/* ===== RESET & BASE ===== */
* {
  box-sizing: border-box;
  max-width: 100%;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  background: #f5f7fb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #111;
  padding: 14px;
}

/* ===== CARD ===== */
.card {
  max-width: 100%;
  overflow: hidden;
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.section-title {
  margin: 0 0 12px 0;
  font-size: 18px;
}

/* ===== TABLES ===== */
.table-wrap {
  overflow-x: auto;
  scrollbar-width: auto;
  scrollbar-color: #9ca3af #e5e7eb;
}

.table-wrap::-webkit-scrollbar {
  height: 22px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #e5e7eb;
  border-radius: 10px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 10px;
  border: 3px solid #e5e7eb;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Main table */
.tg {
  border-collapse: collapse;
  font-size: 13px;
  width: max-content;
  min-width: 100%;
}

.tg th,
.tg td {
  border: 1px solid #777;
  padding: 6px;
  text-align: center;
  white-space: nowrap;
}

.tg thead th {
  background: #efefef;
  font-weight: 600;
}

.tg td:first-child,
.tg th:first-child {
  background: #d6d6d6;
  font-weight: 600;
}

.tg tr.engine-row td {
  background: #fff !important;
}

.tg td.value-cell {
  background: var(--cell-bg) !important;
}

.tg thead th.clickable-gear {
  cursor: pointer;
  user-select: none;
}

.tg thead th.clickable-gear:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Gear grid */
.gear-grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  font-weight: 400;
  table-layout: fixed;
}

.gear-grid th,
.gear-grid td {
  border: 1px solid #bbb;
  padding: 4px 2px;
  text-align: center;
}

.gear-grid th:first-child {
  width: 50px;
  font-size: 11px;
  font-weight: 700;
}

.gear-grid th:not(:first-child) {
  font-size: 11px;
  font-weight: 600;
}

.gear-grid td:first-child {
  font-size: 11px;
  font-weight: 700;
}

.gear-grid .form-control {
  width: 100%;
  min-width: 0;
  padding: 6px 4px;
  font-size: 13px;
  text-align: center;
  border: 1px solid #bbb;
  border-radius: 4px;
}

.corner {
  background: #e0e0e0;
}

/* ===== TRANSMISSION ACCORDION (MOBILE) ===== */
.trans-accordion {
  display: none;
}

.trans-search {
  margin-bottom: 16px;
}

.trans-search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 14px;
}

.trans-item {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.trans-item.hidden {
  display: none;
}

.trans-header {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.trans-header:active {
  background: #f5f5f5;
}

.trans-title {
  font-weight: 600;
  font-size: 14px;
  color: #111;
}

.trans-subtitle {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}

.trans-chevron {
  font-size: 18px;
  transition: transform 0.2s ease;
  color: #666;
}

.trans-item.expanded .trans-chevron {
  transform: rotate(180deg);
}

.trans-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.trans-item.expanded .trans-body {
  max-height: 500px;
}

.trans-content {
  padding: 0 14px 14px 14px;
  border-top: 1px solid #eee;
}

.trans-info {
  margin: 12px 0;
}

.trans-info-label {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.trans-info-value {
  font-size: 14px;
  font-weight: 600;
  color: #111;
}

.trans-ratios {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.trans-ratio-item {
  background: #f9fafb;
  padding: 8px;
  border-radius: 4px;
  text-align: center;
}

.trans-ratio-label {
  font-size: 11px;
  color: #666;
  margin-bottom: 2px;
}

.trans-ratio-value {
  font-size: 15px;
  font-weight: 600;
  color: #111;
}

.trans-select-btn {
  width: 100%;
  padding: 10px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
}

.trans-select-btn:active {
  background: #333;
}

/* ===== FORMS ===== */
.form-control,
#transmissions {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  box-sizing: border-box;
}

#transmissions {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  padding-right: 32px;
  cursor: pointer;
}

.btnSpeed {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid #333;
  background: #fafafa;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
}

.btnSpeed:hover {
  background: #f0f0f0;
}

/* Tire inputs */
.tire-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tire-inputs .tireField {
  width: 120px;
  padding: 8px;
  border: 1px solid #bbb;
  border-radius: 6px;
}

.tire-inputs small {
  margin-left: 6px;
  white-space: nowrap;
}

.tireOut {
  width: 100%;
  margin-top: 6px;
  color: #555;
  font-size: 13px;
}

/* ===== CALCULATOR LAYOUT ===== */
.calc-layout {
  display: grid;
  grid-template-columns: minmax(560px, 680px) minmax(400px, 420px);
  gap: 44px;
  align-items: start;
}

.calc-right {
  max-width: 420px;
}

.calc-right .gear-grid {
  width: 100%;
}

.calc-right .gear-wrap {
  margin-top: 0;
}

.calc {
  width: 100%;
  border-collapse: collapse;
}

.calc td {
  padding: 8px 4px;
  vertical-align: top;
}

.calc tr {
  margin-bottom: 20px;
}

.label {
  width: 200px;
  font-weight: 400;
  font-size: 14px;
}

small {
  color: #555;
  display: block;
  margin-top: 6px;
}

/* ===== DUAL LAYOUT (RPM/KMH) ===== */
.dual-wrap {
  display: grid;
  grid-template-columns: 360px minmax(360px, 1fr);
  gap: 16px;
  align-items: start;
}

.dual-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dual-title {
  font-weight: 700;
  color: #111;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.dial-box {
  width: 320px;
  max-width: 100%;
}

.dial-box svg {
  width: 320px;
  height: 320px;
  display: block;
}

.tach-controls {
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
}

.control-row {
  display: flex;
  align-items: flex-end;
}

.ctrl {
  width: 100%;
}

.rpm-controls .control-row:first-child,
.kmh-controls .control-row:first-child {
  min-height: 56px;
}

.rpm-controls .control-row:nth-child(2),
.kmh-controls .spacer-row {
  min-height: 56px;
}

.kmh-controls .align-bottom {
  align-items: flex-end;
}

/* Gear pills */
.gear-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.gear-pill {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid #bbb;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.gear-pill.is-active {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* ===== LINKS ===== */
.links a {
  display: block;
  margin-bottom: 6px;
  color: #0055aa;
  text-decoration: none;
}

.links a:hover {
  text-decoration: underline;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .calc-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .dual-wrap {
    grid-template-columns: 1fr;
  }
}

/* Tablets (600px - 900px) */
@media (min-width: 600px) and (max-width: 900px) {
  .calc tr {
    display: grid;
    grid-template-columns: 200px 1fr;
    column-gap: 12px;
    row-gap: 6px;
    align-items: start;
    margin-bottom: 24px;
  }

  .calc td {
    display: block;
    padding: 0;
    min-width: 0;
  }

  .calc td.label {
    margin: 0;
    padding-top: 8px;
  }

  .tire-inputs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
  }

  .tire-inputs .tireField {
    width: 120px;
  }

  .tireOut {
    width: 100%;
    margin-top: 6px;
  }
}

/* Mobile (<= 600px) */
@media (max-width: 600px) {
  body {
    padding: 8px;
  }

  .card {
    padding: 8px;
    margin-bottom: 12px;
  }

  /* Hide desktop table, show accordion */
  .table-wrap {
    display: none;
  }

  .trans-accordion {
    display: block;
  }

  /* Stack calc table */
  .calc,
  .calc tbody,
  .calc tr,
  .calc td {
    display: block;
    width: 100%;
  }

  .calc tr {
    margin-bottom: 20px;
  }

  .calc td {
    padding: 0;
    min-width: 0;
  }

  .calc td.label {
    width: 100%;
    font-size: 13px;
    line-height: 1.2;
    margin: 0 0 8px 0;
  }

  /* Force inputs to fit */
  .form-control,
  #transmissions {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 40px;
    padding: 8px 10px;
    font-size: 14px;
    box-sizing: border-box;
  }

  #transmissions {
    padding-right: 32px !important;
  }

  .calc small {
    display: block;
    margin-top: 8px;
    margin-bottom: 4px;
    font-size: 12px;
    line-height: 1.25;
  }

  /* Tire inputs: 3 columns */
  .tire-inputs {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    align-items: center;
  }

  .tire-inputs .tireField {
    width: 100% !important;
    min-width: 0 !important;
    text-align: center;
    height: 36px;
    padding: 6px 10px;
    font-size: 13px;
    box-sizing: border-box;
  }

  .tire-inputs small,
  .tireOut {
    grid-column: 1 / -1;
  }

  .tireOut {
    margin-top: 6px;
    font-size: 12px;
  }

  .btnSpeed {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    height: 40px;
  }

  /* Gear grid mobile optimization */
  .calc-right {
    max-width: 100%;
    width: 100%;
  }

  .gear-grid {
    width: 100%;
    font-size: 12px;
  }

  .gear-grid th:first-child {
    width: 42px;
    font-size: 10px;
    padding: 3px 1px;
  }

  .gear-grid th:not(:first-child) {
    font-size: 10px;
    padding: 3px 2px;
  }

  .gear-grid td:first-child {
    font-size: 10px;
    padding: 3px 1px;
  }

  .gear-grid td:not(:first-child) {
    padding: 2px 1px;
  }

  .gear-grid .form-control {
    width: 100%;
    min-width: 0;
    padding: 5px 2px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    border: 1px solid #bbb;
    border-radius: 3px;
  }
}