/* 《最后180秒》— 电影感写实悬疑：枪灰金属 + 警报红 + 成功绿 + 提示琥珀 */
:root {
  --bg: #0b0c0e;
  --steel: #2a2f36;
  --steel-2: #1b1f24;
  --steel-hi: #8a939c;
  --alarm: #ff2b2b;
  --alarm-dim: #5a0d0d;
  --ok: #3ee27f;
  --hint: #ffb020;
  --ink: #ece7dd;
  --ink-dim: #a9a49a;
  --paper: #e9e2d0;
  --paper-ink: #1e1c18;
  --font-ui: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "Noto Sans SC", sans-serif;
  --font-timer: "Courier New", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-sym: "Segoe UI Symbol", "Noto Sans Symbols", "Noto Sans Symbols 2", "DejaVu Sans", "Arial Unicode MS", serif;
  --radius: 4px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .6);
  --motion: 160ms;
  --alarm-period: 1.6s;
  --s: min(1vw, 1.78vh);
  --fs: clamp(13px, calc(var(--s) * 1.25), 18px);
  --bg-img: none;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: var(--fs);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#app.shake { animation: shake .34s linear; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-7px, 3px); } 40% { transform: translate(6px, -4px); }
  60% { transform: translate(-4px, -2px); } 80% { transform: translate(3px, 3px); }
}

#bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 35% 10%, rgba(150, 175, 190, .16), transparent 55%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, .9), transparent 60%),
    linear-gradient(180deg, #15181c 0%, #0c0d10 60%, #070809 100%);
}
#bg.has-img { background: linear-gradient(rgba(5, 6, 8, .35), rgba(5, 6, 8, .55)), var(--bg-img) center / cover no-repeat, #0b0c0e; }
#vignette {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  box-shadow: inset 0 0 18vmin rgba(0, 0, 0, .85);
}
#vignette.alarm { animation: alarmPulse var(--alarm-period) ease-in-out infinite; }
@keyframes alarmPulse {
  0%, 100% { box-shadow: inset 0 0 18vmin rgba(0, 0, 0, .85); }
  50% { box-shadow: inset 0 0 22vmin rgba(255, 30, 30, .55); }
}

.screen {
  position: absolute; inset: 0; z-index: 2; display: none;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.screen.on { display: flex; }

/* ---------- 共享组件：按钮 ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; min-width: 132px; padding: 0 26px;
  font-size: clamp(15px, calc(var(--s) * 1.5), 22px); font-weight: 700; letter-spacing: .08em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(180deg, #454c55 0%, #2b3037 48%, #1d2126 100%);
  border: 2px solid #59616b; border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 4px 0 #0c0e10, 0 8px 16px rgba(0, 0, 0, .5);
  cursor: pointer; transition: transform var(--motion), filter var(--motion);
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.15); }
.btn:active, .btn.pressed { transform: translateY(2px) scale(.98); filter: brightness(.92); }
.btn:focus-visible { outline: 2px solid var(--hint); outline-offset: 3px; }
.btn[disabled] { filter: grayscale(.7) brightness(.55); cursor: default; }
.btn.primary { color: #ffd9d4; text-shadow: 0 0 10px rgba(255, 60, 40, .55); }
.btn.hint { color: var(--hint); }
.btn.ok { color: #c9ffdc; }
.btn.small { min-height: 44px; min-width: 0; padding: 0 14px; font-size: clamp(13px, calc(var(--s) * 1.15), 16px); letter-spacing: .04em; }
.btn > .lbl { position: relative; z-index: 1; }

/* ---------- 共享组件：金属模块面板 ---------- */
.plate {
  position: relative;
  background: linear-gradient(160deg, #3a4048 0%, #262a30 40%, #1a1d21 100%);
  border: 2px solid #4d555e; border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), inset 0 -2px 0 rgba(0, 0, 0, .5), var(--shadow);
}

/* ---------- 共享组件：LED ---------- */
.led {
  --c: var(--alarm);
  display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, rgba(255, 255, 255, .85) 0, var(--c) 38%, #000 110%);
  box-shadow: 0 0 10px var(--c), 0 0 2px #000 inset;
}
.led.green { --c: var(--ok); }
.led.blink { animation: ledBlink 1s steps(1) infinite; }
.led.d2 { animation-delay: .33s; } .led.d3 { animation-delay: .66s; }
@keyframes ledBlink { 50% { background: #3a1010; box-shadow: none; } }

/* ---------- 共享组件：LED 计时器 ---------- */
.timer {
  display: inline-flex; align-items: baseline; justify-content: center;
  padding: 6px 22px; min-width: 210px;
  background: linear-gradient(180deg, #0a0606, #160909);
  border: 3px solid #121315; border-radius: 6px;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, .9), 0 0 0 2px #3a3f46, var(--shadow);
  color: var(--alarm); font-family: var(--font-timer); font-weight: 700;
  text-shadow: 0 0 8px rgba(255, 40, 40, .9), 0 0 22px rgba(255, 0, 0, .45);
}
.timer .digits { font-size: clamp(30px, calc(var(--s) * 4.2), 62px); letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.timer .tenths { font-size: clamp(16px, calc(var(--s) * 2), 28px); opacity: .85; width: 1.6em; }
.timer.big .digits { font-size: clamp(48px, calc(var(--s) * 9), 140px); }
.timer.low { animation: timerFlash .5s steps(1) infinite; }
.timer.stopped { color: var(--ok); text-shadow: 0 0 10px rgba(60, 230, 130, .8); }
@keyframes timerFlash { 50% { color: #ff9a9a; } }
.timer.bump { animation: bump .3s ease-out; }
@keyframes bump { 30% { transform: scale(1.08); } }

/* ---------- 标题页 ---------- */
#scr-title { align-items: center; justify-content: space-between; gap: 4vw; padding-left: max(6vw, env(safe-area-inset-left)); padding-right: max(5vw, env(safe-area-inset-right)); }
.title-left { flex: 0 1 46%; min-width: 0; display: flex; flex-direction: column; gap: clamp(8px, calc(var(--s) * 1.6), 22px); }
.title-kicker { color: var(--alarm); letter-spacing: .3em; font-size: clamp(12px, calc(var(--s) * 1.1), 16px); }
.game-title {
  margin: 0; font-size: clamp(40px, calc(var(--s) * 7.5), 110px); line-height: 1; letter-spacing: .06em;
  text-shadow: 0 4px 18px rgba(0, 0, 0, .9);
}
.game-title .t-num { color: var(--alarm); font-family: var(--font-timer); text-shadow: 0 0 16px rgba(255, 30, 30, .8); padding: 0 .06em; }
.title-sub { margin: 0; color: var(--ink-dim); line-height: 1.6; }
.title-actions { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.best { color: var(--ink-dim); font-size: clamp(12px, calc(var(--s) * 1.1), 15px); }
.best b { color: var(--ok); }
.title-right { flex: 0 1 44%; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.title-leds { display: flex; gap: 18px; }

/* ---------- 游戏页 ---------- */
#scr-game { flex-direction: column; gap: clamp(6px, calc(var(--s) * 1), 14px); }
.topbar { flex: none; display: grid; grid-template-columns: 1fr auto auto 1fr; align-items: center; gap: clamp(8px, calc(var(--s) * 1.4), 22px); }
.tb-left { display: flex; gap: 8px; min-width: 0; }
.serial-plate {
  display: flex; flex-direction: column; align-items: center; padding: 4px 14px;
  background: linear-gradient(180deg, #d9d2bf, #bfb7a2); color: var(--paper-ink); border-radius: 3px;
  box-shadow: inset 0 0 0 2px #8d8572, 0 3px 8px rgba(0, 0, 0, .5);
}
.sp-label { font-size: 11px; letter-spacing: .2em; opacity: .7; }
.sp-val { font-family: var(--font-timer); font-weight: 700; font-size: clamp(16px, calc(var(--s) * 1.9), 26px); letter-spacing: .08em; }
#scr-game .timer .digits { font-size: clamp(28px, calc(var(--s) * 4), 56px); }
.stats { display: flex; justify-content: flex-end; gap: clamp(6px, calc(var(--s) * 1.2), 18px); min-width: 0; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 44px; padding: 3px 8px; background: rgba(10, 11, 13, .7); border: 1px solid #3a4048; border-radius: 3px; }
.stat span { font-size: 11px; color: var(--ink-dim); white-space: nowrap; }
.stat b { font-family: var(--font-timer); font-size: clamp(15px, calc(var(--s) * 1.7), 22px); }
.stat b.flash { color: var(--alarm); }

.stage { position: relative; flex: 1; min-height: 0; }
.overview { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(10px, calc(var(--s) * 2), 30px); align-items: stretch; padding: 0 1vw; }
.modcard {
  display: flex; flex-direction: column; align-items: stretch; justify-content: space-between; gap: 8px;
  padding: clamp(12px, calc(var(--s) * 2), 30px); text-align: left; cursor: pointer; min-width: 0; max-height: 100%;
  transition: transform var(--motion), filter var(--motion);
}
.modcard:hover { filter: brightness(1.12); }
.modcard:active { transform: scale(.985); }
.modcard.locked { cursor: default; filter: none; }
.modcard.locked::after {
  content: "已锁定"; position: absolute; right: 14%; top: 42%; transform: rotate(-12deg);
  padding: 4px 14px; border: 3px solid var(--ok); color: var(--ok); font-weight: 800; letter-spacing: .2em;
  font-size: clamp(16px, calc(var(--s) * 2.2), 30px); background: rgba(5, 20, 10, .6); border-radius: 4px;
  text-shadow: 0 0 8px rgba(60, 230, 130, .7);
}
.mc-head { display: flex; justify-content: space-between; align-items: center; color: var(--ink-dim); font-size: 13px; letter-spacing: .15em; }
.mc-name { font-size: clamp(18px, calc(var(--s) * 2.4), 34px); font-weight: 800; letter-spacing: .1em; }
.mc-preview { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; padding: 8px; background: rgba(0, 0, 0, .35); border-radius: 4px; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .7); }
.mc-foot { color: var(--hint); font-size: 13px; letter-spacing: .1em; }
.modcard.locked .mc-foot { color: var(--ok); }
.pv-sym { font-family: var(--font-sym); font-size: clamp(20px, calc(var(--s) * 3), 40px); width: 1.6em; height: 1.6em; display: grid; place-items: center; background: #15181b; border: 1px solid #3a4048; border-radius: 4px; }
.pv-lamp { width: clamp(16px, calc(var(--s) * 2.6), 34px); height: clamp(16px, calc(var(--s) * 2.6), 34px); border-radius: 50%; }
.pv-wire { display: block; width: 86%; height: clamp(5px, calc(var(--s) * .7), 9px); border-radius: 4px; box-shadow: 0 2px 3px rgba(0, 0, 0, .6); }
.mc-preview.wires { flex-direction: column; flex-wrap: nowrap; gap: clamp(5px, calc(var(--s) * 1.1), 14px); }

/* ---------- 模块特写 ---------- */
.focus { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); gap: clamp(10px, calc(var(--s) * 1.6), 24px); }
.op { display: flex; flex-direction: column; min-height: 0; padding: clamp(10px, calc(var(--s) * 1.6), 24px); }
.op-head { flex: none; display: flex; align-items: center; gap: 12px; }
.op-title { flex: 1; min-width: 0; font-size: clamp(17px, calc(var(--s) * 2.1), 28px); font-weight: 800; letter-spacing: .1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-body { flex: 1; min-height: 0; display: flex; position: relative; overflow: auto; }
.op-body > * { margin: auto; }
.op-msg { flex: none; min-height: 1.6em; text-align: center; color: var(--ink-dim); font-size: clamp(13px, calc(var(--s) * 1.2), 17px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-msg.bad { color: #ff7a6e; } .op-msg.good { color: var(--ok); } .op-msg.hintc { color: var(--hint); white-space: normal; }
.op.locked .op-body { filter: saturate(.6) brightness(.8); pointer-events: none; }

.rulecard {
  position: relative; min-height: 0; overflow: hidden;
  background: linear-gradient(180deg, #ece5d3, #ddd5c0); color: var(--paper-ink);
  border: 6px solid #2b3036; border-radius: 4px;
  box-shadow: inset 0 0 30px rgba(120, 100, 60, .25), var(--shadow);
}
.rule-scroll { height: 100%; overflow-y: auto; padding: clamp(10px, calc(var(--s) * 1.6), 24px); line-height: 1.55; font-size: clamp(13px, calc(var(--s) * 1.25), 17px); -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.rule-scroll h3 { margin: 0 0 6px; font-size: 1.15em; letter-spacing: .1em; border-bottom: 2px solid var(--paper-ink); padding-bottom: 4px; }
.rule-scroll p { margin: 6px 0; }
.rule-scroll .note { color: #6b2a10; font-weight: 700; }
.rule-scroll ol { margin: 6px 0; padding-left: 1.5em; }
.rule-scroll li { margin: 3px 0; padding: 2px 4px; border-radius: 3px; }
.rule-scroll li.hl { background: rgba(255, 176, 32, .55); outline: 2px solid #b36b00; }
.rule-scroll .serial-inline { font-family: var(--font-timer); font-weight: 700; background: rgba(0, 0, 0, .08); padding: 0 6px; border-radius: 3px; }
.symtable { border-collapse: collapse; margin: 6px 0; width: 100%; table-layout: fixed; }
.symtable th, .symtable td { border: 1px solid #8d8572; text-align: center; padding: 2px 0; }
.symtable th { font-size: .8em; font-weight: 700; background: rgba(0, 0, 0, .06); }
.symtable td { font-family: var(--font-sym); font-size: 1.25em; }
.symtable td.rowh { font-family: var(--font-ui); font-weight: 800; font-size: 1em; background: rgba(0, 0, 0, .1); }
.symtable tr.hl td { background: rgba(255, 176, 32, .5); }
.colortable { border-collapse: collapse; margin: 6px 0; }
.colortable td { border: 1px solid #8d8572; padding: 2px 10px; text-align: center; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 4px; border: 1px solid #555; }

/* 符号键 / 键盘键（共享 KeyCap） */
.key {
  display: grid; place-items: center; min-width: 44px; min-height: 44px;
  background: radial-gradient(ellipse at 50% 30%, #3b4047, #202328 75%);
  border: 2px solid #5a626c; border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), inset 0 -3px 0 rgba(0, 0, 0, .55), 0 4px 0 #0a0b0d, 0 6px 12px rgba(0, 0, 0, .5);
  font-weight: 800; cursor: pointer; transition: transform 90ms, filter 90ms; touch-action: manipulation;
}
.key:active, .key.pressed { transform: translateY(3px); filter: brightness(.85); }
.key.ok { box-shadow: 0 0 0 3px var(--ok), 0 0 16px rgba(60, 230, 130, .6); color: var(--ok); }
.key.bad { box-shadow: 0 0 0 3px var(--alarm), 0 0 16px rgba(255, 40, 40, .7); color: #ff8a80; }
.key.hinted { box-shadow: 0 0 0 3px var(--hint), 0 0 14px rgba(255, 176, 32, .7); }
.symkeys { display: grid; grid-template-columns: repeat(2, auto); gap: clamp(10px, calc(var(--s) * 2), 28px); }
.symkey { width: clamp(64px, calc(var(--s) * 10), 140px); height: clamp(64px, calc(var(--s) * 10), 140px); font-family: var(--font-sym); font-size: clamp(30px, calc(var(--s) * 5), 66px); position: relative; }
.symkey .kled { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: #222; box-shadow: inset 0 0 2px #000; }
.symkey.ok .kled { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.lightmod { display: grid; grid-template-columns: auto auto; grid-template-rows: auto 1fr; gap: clamp(8px, calc(var(--s) * 1.4), 20px) clamp(12px, calc(var(--s) * 2.4), 34px); align-items: center; justify-items: center; }
.lamps { grid-column: 1 / -1; display: flex; gap: clamp(12px, calc(var(--s) * 2.6), 36px); }
.lampwrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lampno { font-size: 11px; color: var(--ink-dim); }
.lamp {
  --c: #f33; width: clamp(34px, calc(var(--s) * 5.2), 70px); height: clamp(34px, calc(var(--s) * 5.2), 70px); border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, rgba(255, 255, 255, .9) 0, var(--c) 34%, rgba(0, 0, 0, .55) 100%), var(--c);
  box-shadow: 0 0 0 4px #15171a, 0 0 0 6px #4a5058, 0 0 22px var(--c);
}
.lamp.blink { animation: lampBlink 1s steps(1) infinite; }
@keyframes lampBlink { 50% { background: radial-gradient(circle at 36% 30%, rgba(255, 255, 255, .15) 0, #1a1a1a 60%); box-shadow: 0 0 0 4px #15171a, 0 0 0 6px #4a5058; } }
.lampname { font-size: clamp(12px, calc(var(--s) * 1.15), 15px); font-weight: 700; }
.codecol { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.codedisp {
  font-family: var(--font-timer); font-weight: 700; font-size: clamp(24px, calc(var(--s) * 3), 40px); letter-spacing: .3em; text-align: center;
  padding: 6px 4px 6px 14px; min-width: 5.2em; background: #0b130d; color: #7dffa6; border: 3px solid #121315; border-radius: 4px;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, .9), 0 0 0 2px #3a3f46; text-shadow: 0 0 8px rgba(80, 255, 140, .6);
}
.codedisp.bad { color: #ff6b6b; text-shadow: 0 0 8px rgba(255, 60, 60, .7); }
.codecol .btn { min-width: 0; }
.keypad { display: grid; grid-template-columns: repeat(4, clamp(50px, calc(var(--s) * 5.4), 70px)); grid-auto-rows: clamp(44px, calc(var(--s) * 5.4), 70px); gap: clamp(6px, calc(var(--s) * .9), 12px); }
.keypad .key { padding: 0; white-space: nowrap; }
.keypad .key { font-family: var(--font-timer); font-size: clamp(18px, calc(var(--s) * 2.4), 30px); }
.keypad .key.fn { font-family: var(--font-ui); font-size: clamp(13px, calc(var(--s) * 1.4), 18px); }
.keypad .key.go { color: var(--ok); }
.keypad .key.clr { color: var(--hint); }

.wiremod { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.wiresvg { width: 100%; height: 100%; max-height: 100%; touch-action: manipulation; }
.wiresvg .hit { stroke: transparent; stroke-width: 40; fill: none; cursor: pointer; pointer-events: stroke; }
.wiresvg .wire { fill: none; stroke-width: 11; stroke-linecap: round; pointer-events: none; transition: filter .15s; }
.wiresvg .wire-sh { fill: none; stroke: rgba(0, 0, 0, .55); stroke-width: 15; stroke-linecap: round; pointer-events: none; }
.wiresvg g.w:hover .wire { filter: brightness(1.35); }
.wiresvg g.w.bad .wire { animation: wireBad .5s; }
@keyframes wireBad { 0%, 100% { filter: none; } 30% { filter: brightness(2) drop-shadow(0 0 6px #f22); } }
.wiresvg .term { fill: #9aa2ab; stroke: #1b1d21; stroke-width: 2; }
.wiresvg .wno { fill: var(--ink); font-size: 18px; font-weight: 700; font-family: var(--font-timer); }
.wiresvg .cutL { animation: cutL .4s ease-out forwards; }
.wiresvg .cutR { animation: cutR .4s ease-out forwards; }
@keyframes cutL { to { transform: translate(-10px, 14px) rotate(-4deg); } }
@keyframes cutR { to { transform: translate(10px, 14px) rotate(4deg); } }
.wiresvg .spark { fill: #ffe9a6; }

/* ---------- 弹窗 ---------- */
.modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(3, 4, 5, .78); }
.dialog {
  position: relative; width: min(760px, 94vw); max-height: 94%; display: flex; flex-direction: column;
  background: linear-gradient(170deg, #2d3239, #191c20 70%); border: 3px solid #4d555e; border-radius: 6px;
  box-shadow: inset 0 3px 0 #7a1414, inset 0 1px 0 rgba(255, 255, 255, .15), 0 18px 50px rgba(0, 0, 0, .8);
  animation: dlgIn .22s ease-out;
}
@keyframes dlgIn { from { transform: scale(.92); opacity: 0; } }
.dlg-inner { min-height: 0; overflow-y: auto; padding: clamp(16px, calc(var(--s) * 2.4), 36px); display: flex; flex-direction: column; gap: 12px; touch-action: pan-y; }
.x-close {
  position: absolute; top: 6px; right: 6px; z-index: 2; width: 44px; height: 44px; border-radius: 4px;
  background: rgba(0, 0, 0, .4); border: 1px solid #555c66; font-size: 26px; line-height: 1; cursor: pointer;
}
.dlg-title { margin: 0; text-align: center; font-size: clamp(22px, calc(var(--s) * 3.2), 44px); letter-spacing: .14em; }
.dlg-title.win { color: var(--ok); text-shadow: 0 0 16px rgba(60, 230, 130, .6); }
.dlg-title.lose { color: var(--alarm); text-shadow: 0 0 16px rgba(255, 40, 40, .7); }
.dlg-sub { margin: 0; text-align: center; color: var(--ink-dim); }
.dlg-text { line-height: 1.6; }
.dlg-text h4 { margin: 10px 0 4px; color: var(--hint); letter-spacing: .1em; }
.dlg-text ul { margin: 4px 0; padding-left: 1.3em; }
.dlg-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.dlg-stat { text-align: center; padding: 8px 4px; background: rgba(0, 0, 0, .35); border: 1px solid #3a4048; border-radius: 4px; min-width: 0; }
.dlg-stat span { display: block; font-size: 12px; color: var(--ink-dim); }
.dlg-stat b { font-family: var(--font-timer); font-size: clamp(20px, calc(var(--s) * 2.6), 34px); }
.grade { font-size: clamp(44px, calc(var(--s) * 7), 90px); font-family: var(--font-timer); text-align: center; color: var(--ok); line-height: 1; text-shadow: 0 0 20px rgba(60, 230, 130, .6); }
.newrec { text-align: center; color: var(--hint); font-weight: 700; letter-spacing: .1em; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.dlg-actions .btn { flex: 1 1 180px; max-width: 280px; }
.ad-note { text-align: center; font-size: 12px; color: var(--ink-dim); min-height: 1em; }

/* ---------- 排行榜 ---------- */
.lb-box { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: rgba(0, 0, 0, .35); border: 1px solid #3a4048; border-radius: 4px; min-width: 0; }
.lb-head { text-align: center; color: var(--ink-dim); letter-spacing: .08em; }
.lb-head b { color: var(--ink); font-family: var(--font-timer); font-size: 1.15em; }
.lb-form { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: stretch; }
.lb-input { flex: 1 1 140px; min-width: 0; max-width: 220px; min-height: 40px; padding: 0 10px; font: inherit; font-size: 16px; color: var(--ink); background: #111316; border: 1px solid #4a515a; border-radius: 4px; }
.lb-input:focus { outline: 2px solid var(--hint); outline-offset: 1px; }
.lb-form .btn { flex: 0 1 auto; }
.lb-msg { text-align: center; font-size: 13px; min-height: 1.2em; color: var(--ink-dim); }
.lb-msg.good { color: var(--ok); } .lb-msg.bad { color: #ff7a6e; }
.lb-note { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink-dim); }
.lb-state { text-align: center; padding: 10px 4px; color: var(--ink-dim); font-size: 14px; }
.lb-state.bad { color: #ff7a6e; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-table th { color: var(--ink-dim); font-weight: 400; font-size: 12px; padding: 4px; border-bottom: 1px solid #3a4048; }
.lb-table td { padding: 5px 4px; text-align: center; border-bottom: 1px solid rgba(58, 64, 72, .5); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0; }
.lb-table td:nth-child(1) { width: 18%; font-family: var(--font-timer); }
.lb-table td:nth-child(3) { width: 30%; font-family: var(--font-timer); color: var(--ok); }
.lb-table tr.me td { color: var(--hint); }

/* ---------- 反馈层 ---------- */
#fx-layer { position: absolute; inset: 0; z-index: 30; pointer-events: none; overflow: hidden; }
.flash { position: absolute; inset: 0; animation: flash .35s ease-out forwards; }
@keyframes flash { from { opacity: .55; } to { opacity: 0; } }
.float-txt { position: absolute; font-family: var(--font-timer); font-weight: 800; font-size: clamp(20px, calc(var(--s) * 2.6), 36px); transform: translate(-50%, -50%); animation: floatUp 1s ease-out forwards; text-shadow: 0 2px 6px #000; white-space: nowrap; }
@keyframes floatUp { to { transform: translate(-50%, -180%); opacity: 0; } }
.ring { position: absolute; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 4px solid var(--ok); animation: ring .7s ease-out forwards; }
@keyframes ring { to { transform: scale(14); opacity: 0; border-width: 1px; } }
.particle { position: absolute; width: 8px; height: 8px; border-radius: 2px; animation: particle var(--d, 1.4s) ease-out forwards; }
@keyframes particle { to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }

.toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 15; pointer-events: none;
  padding: 8px 18px; background: rgba(10, 11, 13, .92); border: 1px solid #4d555e; border-radius: 4px;
  opacity: 0; transition: opacity .2s; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.on { opacity: 1; }

#rotate-tip { display: none; position: absolute; top: 0; left: 0; right: 0; z-index: 40; text-align: center; padding: 4px; font-size: 12px; background: rgba(90, 13, 13, .85); pointer-events: none; }

/* ---------- 美术外壳（九宫格 border-image；图片全部加载后 body.skinned 才启用，失败保留上方程序化外观） ---------- */
.skinned .btn {
  background: none; box-shadow: none;
  border-style: solid; border-width: 9px 24px; border-radius: 0;
  border-image: url(assets/ui_btn_primary.webp) 60 165 60 165 fill / 9px 24px stretch;
  padding: 0 20px;
}
.skinned .btn.small { border-width: 8px 18px; border-image-width: 8px 18px; padding: 0 12px; }
.title-actions .btn { min-width: clamp(160px, calc(var(--s) * 17), 240px); min-height: clamp(50px, calc(var(--s) * 5.2), 68px); }
.skinned .title-actions .btn { border-width: 11px 28px; border-image-width: 11px 28px; }
.skinned .timer, .skinned .plate, .skinned .dialog, .skinned .rulecard { filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .6)); }
.skinned .modcard:hover { filter: brightness(1.12) drop-shadow(0 8px 14px rgba(0, 0, 0, .6)); }
.skinned .plate {
  --pb: clamp(30px, calc(var(--s) * 3.4), 46px);
  background: none; box-shadow: none;
  border-style: solid; border-width: var(--pb); border-radius: 0;
  border-image: url(assets/ui_panel_module.webp) 230 fill / var(--pb) stretch;
}
.skinned .modcard { padding: clamp(0px, calc(var(--s) * .4), 6px); }
.skinned .op { padding: 2px; }
.skinned .key {
  background: none;
  border-style: solid; border-width: 11px 10px; border-radius: 0;
  border-image: url(assets/ui_keycap.webp) 95 85 95 85 fill / 11px 10px stretch;
  box-shadow: none;
}
.skinned .key.ok { box-shadow: 0 0 0 2px var(--ok), 0 0 16px rgba(60, 230, 130, .6); }
.skinned .key.bad { box-shadow: 0 0 0 2px var(--alarm), 0 0 16px rgba(255, 40, 40, .7); }
.skinned .key.hinted { box-shadow: 0 0 0 2px var(--hint), 0 0 14px rgba(255, 176, 32, .7); }
.skinned .timer {
  background: none; box-shadow: none;
  border-style: solid; border-width: 15px 26px; border-radius: 0;
  border-image: url(assets/ui_timer_frame.webp) 110 185 110 185 fill / 15px 26px stretch;
  padding: 0 10px;
}
.skinned .timer.big { border-width: 26px 46px; border-image-width: 26px 46px; padding: 6px 18px; }
.skinned .dialog {
  background: none; box-shadow: none;
  border-style: solid; border-width: 34px 30px 30px 30px; border-radius: 0;
  border-image: url(assets/ui_panel_dialog.webp) 120 110 110 110 fill / 34px 30px 30px 30px stretch;
}
.skinned .dlg-inner { padding: clamp(8px, calc(var(--s) * 1.4), 20px); }
.skinned .x-close { top: -6px; right: -4px; }
.skinned .rulecard {
  background: none; box-shadow: none;
  border-style: solid; border-width: 15px 19px; border-radius: 0;
  border-image: url(assets/ui_panel_rules.webp) 75 95 75 95 fill / 15px 19px stretch;
}
.skinned .rule-scroll { padding: clamp(6px, calc(var(--s) * 1.2), 18px); }

/* ---------- 窄高度横屏（手机横屏） ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .screen { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .timer { padding: 2px 14px; min-width: 150px; }
  .serial-plate { padding: 2px 10px; }
  .sp-label { font-size: 10px; }
  .stat { padding: 1px 6px; }
  .stat span { font-size: 10px; }
  .mc-foot, .mc-head { font-size: 12px; }
  .btn { min-height: 44px; }
  #scr-game .timer .digits { font-size: 26px; }
  .skinned .timer { border-width: 10px 20px; border-image-width: 10px 20px; }
  .skinned .plate { --pb: 22px; }
  .op-msg { position: absolute; left: 0; right: 0; bottom: 4px; pointer-events: none; }
  .lampno { display: none; }
  .lightmod .codecol .lampno { display: none; }
  .codedisp { font-size: 22px; min-width: 5.6em; padding: 4px 4px 4px 10px; }
}

/* ---------- 竖屏 ---------- */
@media (orientation: portrait) {
  #rotate-tip { display: block; }
  :root { --s: min(1.9vw, 1vh); }
  #scr-title { flex-direction: column; justify-content: center; padding: 40px 18px; }
  .title-left, .title-right { flex: none; width: 100%; }
  .topbar { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "left stats" "serial timer"; row-gap: 8px; padding-top: 18px; }
  .tb-left { grid-area: left; }
  .serial-plate { grid-area: serial; }
  .stats { grid-area: stats; gap: 6px; }
  .stat { min-width: 40px; padding: 1px 4px; }
  .topbar .timer { grid-area: timer; justify-self: end; min-width: 0; }
  .lg { display: none; }
  .skinned .plate { --pb: 24px; }
  .overview { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr); padding: 0; }
  .focus { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1.6fr) minmax(0, 1fr); }
  .lightmod { grid-template-columns: auto; }
  .lamps { grid-column: auto; }
  .lampno { display: none; }
}
