/* 换个发动机网页版：一屏放下、不滚动。配色照 Theme.swift：拖拉机机罩绿、东方红、奶白表盘，浅色深色各一套。 */
:root {
  --bg: #E7EBE2; --surface: #F5F6F1; --ink: #1B2117; --muted: #5B6754; --line: #C7CFBF;
  --accent: #C0371E; --hood: #2D5A36; --amber: #B97B0C; --dial: #FBFAF4; --dark-red: #8A2716;
  --blue: #2D6CB0; --sky: #E4ECEF; --field: #DCE5D2; --glow: rgba(255, 255, 255, .85);
  --radius: 16px;
  --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans", "Apple SD Gothic Neo", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111510; --surface: #1A1F18; --ink: #E3E7DC; --muted: #94A08C; --line: #2D352A;
    --accent: #E4583A; --hood: #79B184; --amber: #E2AA3C; --dial: #0C0F0B; --dark-red: #9E3624;
    --blue: #5EA2E8; --sky: #141A20; --field: #0F150E; --glow: rgba(42, 52, 39, .85);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 24%, var(--glow), transparent 320px),
    linear-gradient(var(--sky), var(--bg) 50%, var(--field));
  background-color: var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
.ic { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

#smokeCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

.app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 16px);
  gap: 8px;
  opacity: 0;
  transition: opacity .25s;
}
body.ready .app { opacity: 1; }

/* 顶部：名字 + 语言 + 设置 */
.top { display: flex; align-items: center; gap: 8px; position: relative; z-index: 10; }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 24px; font-weight: 900; letter-spacing: .5px; color: var(--hood); line-height: 1.15; }
.brand .sub { margin: 1px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; border-radius: 12px; font-size: 24px; }
.icon-btn:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }

.lang-menu { position: relative; }
.lang-menu summary {
  list-style: none; display: flex; align-items: center; gap: 5px; height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface);
  font-size: 14px; font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap;
}
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu summary .ic { font-size: 16px; color: var(--muted); }
.lang-menu summary .chev { font-size: 13px; transition: transform .2s; }
.lang-menu[open] summary .chev { transform: rotate(180deg); }
.lang-menu .panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 168px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.lang-menu .panel button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 10px; border: 0; background: none;
  border-radius: 9px; font-size: 15px; text-align: left;
}
.lang-menu .panel button:hover, .lang-menu .panel button:focus-visible { background: color-mix(in srgb, var(--hood) 12%, transparent); outline: none; }
.lang-menu .panel .check { color: var(--accent); font-size: 16px; }
.pill {
  display: inline-flex; align-items: center; height: 36px; padding: 0 12px; border-radius: 18px;
  background: var(--hood); color: #fff; font-size: 14px; font-weight: 700; text-decoration: none; border: 0; white-space: nowrap;
}
.pill.small { height: 30px; font-size: 13px; padding: 0 10px; }

/* 舞台：发动机、码表；宽屏横放时左右分开 */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.left { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.right { display: flex; flex-direction: column; gap: 8px; }
.engine { flex: 1; min-height: 120px; position: relative; cursor: pointer; outline: none; border-radius: var(--radius); }
.engine:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--hood) 50%, transparent); }
.engine canvas { position: absolute; inset: 0; }

.gauges { display: flex; gap: 8px; height: clamp(118px, 19dvh, 176px); }
.g-col {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 8px 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.g-box { flex: 1; min-height: 0; width: 100%; position: relative; }
/* 表盘画布绝对定位，不参与排版：尺寸变化时不会把格子撑住或压成 0 */
.g-box canvas { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.g-label { font-size: 13px; font-weight: 800; }
.g-label.rpm { color: var(--accent); }
.g-label.hood { color: var(--hood); }
.g-label.blue { color: var(--blue); }
.gear-col { flex: none; width: 82px; }
.gear-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.gear-box {
  width: 58px; height: clamp(44px, 7dvh, 62px); display: grid; place-items: center; border-radius: 12px;
  background: var(--hood); color: #fff; font-size: clamp(28px, 5dvh, 40px); font-weight: 800; font-variant-numeric: tabular-nums;
}
.trans { display: flex; border: 1.5px solid var(--hood); border-radius: 14px; overflow: hidden; }
.trans button { border: 0; background: var(--surface); color: var(--hood); font-weight: 800; font-size: 14px; width: 30px; height: 24px; padding: 0; }
.trans button.on { background: var(--hood); color: #fff; }
.shift { display: flex; gap: 4px; }
.shift button {
  width: 30px; height: 26px; border-radius: 8px; border: 1.5px solid var(--hood); background: var(--surface); color: var(--hood);
  display: grid; place-items: center; font-size: 14px; padding: 0;
}

/* 状态行 */
.status { display: flex; align-items: center; gap: 10px; }
.chip {
  flex: none; padding: 6px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
  font-size: 15px; font-weight: 800; min-width: 64px; text-align: center;
}
.chip[data-tone="warm"] { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 50%, var(--line)); }
.chip[data-tone="hot"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.chip[data-tone="cool"] { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 50%, var(--line)); }
.load { flex: 1; min-width: 0; }
.load-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; margin-top: 4px; border-radius: 3px; background: color-mix(in srgb, var(--line) 70%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .1s linear; }

/* 操作卡片 */
.controls {
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); border-radius: 20px;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.ignition { position: relative; height: 62px; }
.crank, .kill {
  position: absolute; inset: 0; border: 0; border-radius: 14px; overflow: hidden; color: #fff;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.crank { background: var(--hood); transition: transform .1s; }
.crank:active { transform: scale(.98); }
.crank-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--amber); transition: width .1s linear; }
.crank-text { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.crank-text b { font-size: 20px; letter-spacing: 1px; }
.crank-text small { font-size: 12px; opacity: .92; }
.kill { background: var(--dark-red); }
.kill-fill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0, 0, 0, .22); border-radius: 14px; }
.kill-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding-left: 30px; font-size: 20px; letter-spacing: 1px; pointer-events: none; }
.kill-label .ic { font-size: 18px; }
.kill-knob {
  position: absolute; left: 5px; top: 5px; width: 52px; height: 52px; border-radius: 50%; border: 0; background: #fff;
  color: var(--dark-red); display: grid; place-items: center; font-size: 22px; box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  touch-action: none; padding: 0;
}
.kill-knob .ic { stroke-width: 2.8; }
.err { margin: 0; font-size: 13px; color: var(--accent); }

.seg { display: flex; padding: 3px; border-radius: 12px; background: color-mix(in srgb, var(--line) 55%, transparent); }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-size: 15px; color: var(--ink); }
.seg button.on, .seg button[aria-checked="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); font-weight: 600; }
.seg.small button { padding: 6px 12px; font-size: 14px; }

.panels { min-height: 92px; }
.panel-mode { display: flex; flex-direction: column; gap: 8px; }
.note { margin: 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.note.warn { color: var(--accent); }
.gps-row { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.gps-row b { flex: 1; font-size: 15px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.dot[data-tone="ok"] { background: var(--hood); }
.dot[data-tone="wait"] { background: var(--amber); }
.acc { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.demo-top { display: flex; justify-content: space-between; align-items: baseline; }
.demo-top b { font-size: 17px; }
.count { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars { display: flex; gap: 3px; }
.bars i { --fill: 0; height: 6px; border-radius: 3px; flex-basis: 0; background: linear-gradient(90deg, var(--accent) calc(var(--fill) * 100%), color-mix(in srgb, var(--line) 60%, transparent) 0); }

.pedals { display: flex; gap: 10px; }
.pedal {
  flex: 1; height: 54px; border-radius: 14px; border: 2px solid var(--ink); background: var(--surface);
  display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 17px; font-weight: 800;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pedal .ic { font-size: 20px; }
.pedal.hot { border-color: var(--accent); }
.pedal.on { background: var(--ink); color: var(--surface); }
.pedal.hot.on { background: var(--accent); color: #fff; }
.cruise-row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.presets { display: flex; gap: 6px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chip-btn.blue { border-color: var(--blue); color: var(--blue); background: var(--surface); }
.chip-btn.blue.on { background: var(--blue); color: #fff; }

/* 设置：从底部弹出 */
.sheet-root { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.sheet-root.open { pointer-events: auto; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .25s; }
.sheet-root.open .backdrop { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; max-height: 86dvh;
  display: flex; flex-direction: column; background: var(--bg); border-radius: 20px 20px 0 0;
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2, .9, .3, 1); outline: none;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .2);
}
.sheet-root.open .sheet { transform: none; }
.sheet-head { position: relative; display: flex; align-items: center; justify-content: center; padding: 18px 16px 10px; }
.grab { position: absolute; top: 7px; left: 50%; width: 38px; height: 5px; margin-left: -19px; border-radius: 3px; background: var(--line); }
.sheet-head h2 { margin: 0; font-size: 17px; }
.done { position: absolute; right: 12px; top: 12px; border: 0; background: none; color: var(--accent); font-size: 16px; font-weight: 700; padding: 8px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 20px); -webkit-overflow-scrolling: touch; }
.group { margin: 0 0 18px; }
.group h3 { margin: 0 0 8px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.card { background: var(--surface); border-radius: 14px; overflow: hidden; }
.group.card { padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; font-size: 16px; }
.card .row + .row { border-top: 1px solid var(--line); }
.row input[type="range"] { flex: 1; accent-color: var(--accent); }
.row .val { width: 32px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.row.toggle { justify-content: space-between; }
.row .t { display: flex; flex-direction: column; gap: 2px; }
.row .t small { font-size: 13px; color: var(--muted); font-weight: 400; }
.row .t b { font-weight: 400; }
.row.link { color: var(--ink); text-decoration: none; justify-content: space-between; }
.row.link .ic { color: var(--muted); }
.row .seg { margin-left: auto; }
input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 51px; height: 31px; border-radius: 16px; margin: 0;
  background: var(--line); position: relative; cursor: pointer; transition: background .2s;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--hood); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(20px); }
.foot { margin: 6px 4px 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.foot.center { text-align: center; }

.variants { display: flex; gap: 4px; background: var(--surface); border-radius: 14px; padding: 10px 6px; }
.variant { flex: 1; min-width: 0; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; }
.variant img {
  width: 52px; height: 52px; padding: 3px; border-radius: 50%; background: color-mix(in srgb, var(--ink) 85%, transparent);
  border: 3px solid transparent; object-fit: contain;
}
.variant span { font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; max-width: 100%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.variant.on img { border-color: var(--accent); }
.variant.on span { color: var(--accent); font-weight: 700; }

.list .app-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: var(--ink); text-decoration: none; }
.list .app-row + .app-row { border-top: 1px solid var(--line); }
.app-icon { width: 46px; height: 46px; border-radius: 10.5px; flex: none; background: var(--line); object-fit: cover; }
.app-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.app-text b { font-size: 15px; }
.app-text small { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.get { flex: none; padding: 5px 14px; border-radius: 14px; background: color-mix(in srgb, var(--hood) 14%, transparent); color: var(--hood); font-weight: 800; font-size: 14px; }

/* 矮屏（小手机、横着的手机）：码表和操作区压紧一点 */
@media (max-height: 700px) {
  .brand h1 { font-size: 20px; }
  .ignition { height: 54px; }
  .kill-knob { width: 44px; height: 44px; }
  .crank-text b, .kill-label { font-size: 18px; }
  .pedal { height: 46px; }
  .panels { min-height: 80px; }
  .controls { padding: 10px; gap: 8px; }
  .note { font-size: 11px; }
}

/* 平板、电脑横放：左边发动机和码表，右边操作 */
@media (min-width: 900px) and (orientation: landscape) {
  .app { max-width: 1100px; }
  .stage { flex-direction: row; gap: 20px; }
  .left { flex: 1; }
  .right { width: 400px; flex: none; }
  .gauges { height: 190px; }
}
