@font-face {
  font-family: 'ZLabs Pixel CN';
  src: url('../assets/ZLabsPixel-12px-CN.woff2') format('woff2');
  font-display: swap;
}

:root {
  --cabinet: #0d1020;
  --panel: #1b2343;
  --panel-deep: #11162d;
  --text: #fff4d6;
  --cyan: #55e6ff;
  --magenta: #ff4f9a;
  --yellow: #ffe36e;
  --green: #7cff6b;
  --orange: #ff9b42;
  --danger: #ff4545;
  --muted: #8290b8;
  --ink: #070914;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body { height: 100%; }

body {
  overflow: hidden;
  background: var(--cabinet);
  color: var(--text);
  font-family: 'ZLabs Pixel CN', 'Microsoft YaHei', monospace;
  font-size: 12px;
  image-rendering: pixelated;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }
.hidden { display: none !important; }

#app {
  width: min(100%, 480px);
  height: 100dvh;
  margin: 0 auto;
  background: var(--cabinet);
  border-right: 2px solid #26315c;
  border-left: 2px solid #26315c;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 8px;
}

.pixel-panel {
  border: 2px solid var(--cyan);
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 2px #28345f;
}

.btn {
  min-height: 44px;
  margin-top: 8px;
  padding: 8px 12px;
  border: 2px solid var(--text);
  border-radius: 2px;
  background: var(--panel);
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  text-align: center;
}

.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { border-color: var(--yellow); background: #653959; color: var(--yellow); }
.btn.ghost { border-color: #6875a0; background: var(--panel-deep); color: var(--text); }
.btn.small { width: auto; min-height: 34px; margin: 0; padding: 6px 10px; font-size: 12px; }
.btn.disabled,
.btn:disabled { opacity: .38; pointer-events: none; }
.site-home-link { display: block; text-decoration: none; }

.menu-inner {
  width: min(308px, calc(100% - 20px));
  margin: auto;
  padding: 30px 20px 22px;
  text-align: center;
}

.logo { color: var(--yellow); font-size: 24px; letter-spacing: 2px; text-shadow: 3px 3px 0 #642e5e; }
.sub { margin: 10px 0 22px; color: var(--cyan); }
.logo-sprite { position: relative; width: 58px; height: 48px; margin: 0 auto 14px; }
.logo-sprite::before,
.logo-sprite::after,
.logo-sprite i {
  position: absolute;
  display: block;
  content: '';
  background: var(--magenta);
}
.logo-sprite::before { inset: 4px 9px 4px; border: 4px solid var(--text); box-shadow: 4px 4px 0 #070914; }
.logo-sprite::after { left: 2px; top: 0; width: 10px; height: 48px; box-shadow: 44px 0 0 var(--magenta); }
.logo-sprite i:nth-child(1) { left: 15px; top: 14px; width: 28px; height: 4px; background: var(--text); }
.logo-sprite i:nth-child(2) { left: 15px; top: 24px; width: 28px; height: 4px; background: var(--text); }
.logo-sprite i:nth-child(3) { left: 15px; top: 34px; width: 28px; height: 4px; background: var(--text); }

.screen-title { margin: 8px 0 12px; color: var(--yellow); font-size: 24px; text-align: center; }
#level-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 3px;
  scrollbar-color: var(--cyan) var(--panel-deep);
}
.level-card {
  min-height: 82px;
  border: 2px solid #6875a0;
  border-radius: 2px;
  background: var(--panel);
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--text);
  cursor: pointer;
}
.level-card:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.level-card .lv-num { display: block; color: var(--yellow); font-size: 24px; }
.level-card .lv-name { display: block; margin-top: 5px; color: var(--cyan); font-size: 12px; }
.level-card.locked { opacity: .42; }

.hud {
  display: grid;
  grid-template-columns: 36px 1fr 1fr 1.25fr 36px;
  gap: 4px;
  height: 42px;
}
.hud-block {
  min-width: 0;
  border: 2px solid #394875;
  background: var(--panel);
  padding: 3px 4px;
  text-align: center;
}
.hud-block small { display: block; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 12px; white-space: nowrap; }
.hud-block b { color: var(--text); font-size: 12px; line-height: 16px; white-space: nowrap; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: 2px solid #6875a0;
  border-radius: 2px;
  background: var(--panel-deep);
  box-shadow: 2px 2px 0 var(--ink);
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
}
.icon-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.icon-settings span { position: relative; display: block; width: 14px; height: 14px; margin: auto; border: 3px solid var(--cyan); }
.icon-settings span::before,
.icon-settings span::after { position: absolute; content: ''; background: var(--cyan); }
.icon-settings span::before { left: 3px; top: -7px; width: 2px; height: 22px; }
.icon-settings span::after { left: -7px; top: 3px; width: 22px; height: 2px; }

.danger-readout {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  height: 28px;
  color: var(--yellow);
  font-size: 12px;
}
#danger-bar { height: 10px; border: 2px solid #6b5533; background: #241a21; }
#danger-fill { display: block; width: 0; height: 100%; background: var(--yellow); transition: width .2s steps(8); }
#danger-fill.critical { background: var(--danger); animation: led-alarm .55s steps(2) infinite; }
@keyframes led-alarm { 50% { opacity: .35; } }

#canvas-wrap {
  position: relative;
  height: clamp(104px, 22dvh, 160px);
  min-height: 104px;
  max-height: 160px;
  flex: 0 1 clamp(104px, 22dvh, 160px);
  overflow: hidden;
  border: 2px solid #394875;
  background: #131a35;
  box-shadow: inset 0 0 0 2px #080b18;
}
#canvas-wrap::after {
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(85, 230, 255, .12);
  content: '';
  pointer-events: none;
}
#canvas-wrap::before {
  position: absolute;
  z-index: 2;
  top: 5px;
  left: 7px;
  padding: 1px 3px;
  background: #080b18;
  color: #8290b8;
  content: '局部追踪';
  font-size: 8px;
  pointer-events: none;
}
#cv { position: absolute; inset: 0; }

.item-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding-top: 6px;
}
.item {
  display: grid;
  min-width: 0;
  min-height: 54px;
  place-items: center;
  border: 2px solid #53618c;
  border-radius: 2px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.item b { font-size: 12px; line-height: 12px; }
.item small { color: var(--yellow); font-size: 10px; line-height: 10px; }
.item.disabled { opacity: .35; pointer-events: none; }
.pixel-icon { position: relative; display: inline-block; width: 20px; height: 16px; color: var(--cyan); }
.icon-wind::before { position: absolute; top: 3px; left: 1px; width: 14px; height: 2px; background: currentColor; box-shadow: 4px 5px 0 currentColor, -1px 10px 0 currentColor; content: ''; }
.icon-wind::after { position: absolute; top: 1px; right: 1px; width: 4px; height: 4px; border-top: 2px solid currentColor; border-right: 2px solid currentColor; content: ''; }
.icon-slot::before { position: absolute; left: 8px; top: 1px; width: 4px; height: 14px; background: currentColor; box-shadow: -5px 5px 0 -1px currentColor, 5px 5px 0 -1px currentColor; content: ''; }
.icon-dice { border: 2px solid currentColor; }
.icon-dice::before { position: absolute; left: 3px; top: 3px; width: 3px; height: 3px; background: currentColor; box-shadow: 8px 0 0 currentColor, 4px 4px 0 currentColor, 0 8px 0 currentColor, 8px 8px 0 currentColor; content: ''; }
.icon-sort::before { position: absolute; left: 1px; top: 3px; width: 16px; height: 2px; background: currentColor; box-shadow: 0 8px 0 currentColor; content: ''; }
.icon-sort::after { position: absolute; right: 0; top: 0; width: 6px; height: 6px; border-top: 2px solid currentColor; border-right: 2px solid currentColor; box-shadow: -13px 8px 0 -2px var(--panel), -15px 10px 0 -2px currentColor; content: ''; transform: rotate(45deg); }
.icon-garage::before { position: absolute; left: 1px; top: 4px; width: 18px; height: 12px; border: 2px solid currentColor; background: var(--panel-deep); content: ''; }
.icon-garage::after { position: absolute; left: 5px; top: 8px; width: 10px; height: 2px; background: currentColor; box-shadow: 0 4px 0 currentColor; content: ''; }

.slots {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 58px;
  padding: 5px 0;
}
.slot {
  position: relative;
  display: flex;
  flex: 1;
  max-width: 70px;
  min-width: 0;
  align-items: center;
  justify-content: center;
  border: 2px dashed #526087;
  border-radius: 2px;
  background: #12182f;
}
.slot::before { color: #394875; content: 'SLOT'; font-size: 8px; }
.slot.filled { border-style: solid; border-color: var(--cyan); background: var(--panel); cursor: pointer; }
.slot.filled::before { display: none; }
.slot.idle { border-color: var(--orange); }
.slot.idle::after { position: absolute; top: -5px; right: -3px; padding: 2px 3px; background: var(--orange); color: var(--ink); content: attr(data-idle-label); font-size: 8px; animation: led-alarm .8s steps(2) infinite; }

.spool {
  position: relative;
  display: flex;
  width: calc(100% - 8px);
  height: 44px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--text);
  background: var(--c, #888);
  box-shadow: inset 5px 0 0 rgba(0, 0, 0, .24), inset -5px 0 0 rgba(0, 0, 0, .24), 2px 2px 0 var(--ink);
  color: #fff;
}
.spool::after { position: absolute; right: 2px; bottom: 1px; color: var(--text); content: attr(data-code); font-size: 9px; }
.spool .len { font-size: 16px; text-shadow: 2px 2px 0 #101020; }
.spool .pips { display: flex; gap: 2px; }
.spool .pip { width: 3px; height: 3px; background: var(--text); }
.spool.rainbow { background: #7b4fa3; }

.game-foot { display: flex; min-height: 38px; align-items: center; justify-content: space-between; gap: 5px; padding-top: 4px; }
.hud-hint { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.garage-inline {
  flex: 0 0 auto;
  margin-top: 2px;
  padding: 3px;
  overflow: hidden;
}
.garage-inline-head { display: flex; height: 18px; align-items: center; justify-content: space-between; padding: 0 2px; color: var(--muted); font-size: 9px; }
.garage-inline-head b { color: var(--green); font-size: 10px; }
.garage-inline-board { display: flex; align-items: center; justify-content: center; overflow: hidden; background: #11162d; }
.garage-inline-board.rerolling { box-shadow: inset 0 0 0 2px var(--orange); }
.tetris-board {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(var(--tetris-cols), minmax(30px, 1fr));
  grid-auto-rows: clamp(32px, 6dvh, 44px);
  gap: 2px;
}
.tetris-vehicle {
  position: relative;
  display: flex;
  min-width: 30px;
  min-height: 32px;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 1px 2px;
  border: 2px solid var(--zone, #65709a);
  background: var(--c, #777);
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, .22), inset -4px 0 0 rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
  text-shadow: 1px 1px 0 #000;
}
.tetris-vehicle.zone-start::after { position: absolute; top: 1px; right: 2px; color: var(--zone); content: attr(data-zone-label); font-size: 7px; text-shadow: 1px 1px 0 #000; }
.tetris-vehicle.zone-0 { --zone: #55e6ff; }
.tetris-vehicle.zone-1 { --zone: #ff4f9a; }
.tetris-vehicle.zone-2 { --zone: #ffe36e; }
.tetris-vehicle.zone-3 { --zone: #7cff6b; }
.tetris-vehicle.zone-4 { --zone: #ff9b42; }
.tetris-vehicle.zone-5 { --zone: #b779ff; }
.tetris-vehicle.ready { border-color: var(--green); animation: ready-pulse .8s steps(2) infinite; }
/* 被阻挡的车仍保持完整色相；锁标记和边框传达不可操作，不能靠灰化干扰颜色判断。 */
.tetris-vehicle.blocked { filter: none; }
.tetris-vehicle.selected { z-index: 2; border-color: var(--yellow); box-shadow: 0 0 0 2px var(--orange); }
.tetris-vehicle.blocker-target { z-index: 1; border-color: var(--magenta); box-shadow: inset 0 0 0 2px #7f245d; filter: none; }
.tetris-vehicle .vehicle-arrow { flex: 0 0 13px; color: var(--yellow); font-family: 'ZLabs Pixel CN', monospace; font-size: 16px; line-height: 18px; text-align: center; text-shadow: 1px 1px 0 #0d1020; }
.tetris-vehicle .vehicle-core { display: flex; min-width: 0; flex: 1; flex-direction: column; align-items: center; justify-content: center; }
.tetris-vehicle .code { font-size: 8px; line-height: 8px; }
.tetris-vehicle .yarn-stick { position: relative; display: block; width: var(--power, 0%); height: var(--stick-h, 3px); min-width: 4px; margin: 1px 0; border: 1px solid var(--text); background: var(--c); box-shadow: 1px 1px 0 #0d1020; }
.tetris-vehicle .yarn-stick::before,
.tetris-vehicle .yarn-stick::after { position: absolute; top: -2px; width: 2px; height: calc(100% + 4px); background: var(--text); content: ''; }
.tetris-vehicle .yarn-stick::before { left: -2px; }
.tetris-vehicle .yarn-stick::after { right: -2px; }
.tetris-vehicle .yarn-stick i { display: block; width: 100%; height: 1px; margin-top: 1px; background: rgba(255, 255, 255, .62); }
.tetris-vehicle .length { font-size: 7px; line-height: 7px; }
.tetris-vehicle .lock { position: absolute; right: 1px; bottom: 1px; padding: 1px 2px; background: var(--magenta); font-size: 7px; }
.tetris-vehicle.away,
.tetris-vehicle.depleted { border-color: #303855; background: #0b0e1d; color: #546084; }
@keyframes ready-pulse { 50% { border-color: var(--cyan); } }

/* 性能优先模式避免大量可点击车位与空转标记同时触发合成动画。 */
.low-power .tetris-vehicle.ready,
.low-power .slot.idle::after { animation: none; }

.overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 15, .84);
  padding: 18px;
}
.card { width: min(340px, 100%); max-height: 86dvh; overflow-y: auto; padding: 18px; text-align: center; }
.card h3 { margin-bottom: 10px; color: var(--yellow); font-size: 20px; }
.card .ov-sub { margin-bottom: 10px; color: var(--muted); line-height: 1.6; }
.card .ov-score { margin-bottom: 8px; color: var(--text); }
.card .ov-score b { color: var(--yellow); font-size: 20px; }
.ov-list { margin: 8px 0 4px 16px; color: var(--text); line-height: 1.65; text-align: left; }
.sort-row { display: flex; justify-content: center; gap: 8px; margin: 12px 0; }
.sort-chip { width: 54px; height: 54px; border: 3px solid #6875a0; border-radius: 2px; background: var(--c, #777); color: #fff; font-size: 16px; }
.sort-chip.picked { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--orange); }
.setting-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; border-bottom: 2px solid #303b64; }
.toggle { min-width: 76px; min-height: 32px; border: 2px solid #6875a0; background: #301d38; color: var(--muted); }
.toggle.on { border-color: var(--green); background: #173d36; color: var(--green); }

.toast {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: 18px;
  max-width: 88vw;
  padding: 8px 12px;
  border: 2px solid var(--yellow);
  background: var(--panel-deep);
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--yellow);
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

.vehicle-flight { position: fixed; z-index: 110; pointer-events: none; transition: transform .16s steps(4), opacity .16s steps(4); }

@media (max-height: 680px) {
  .hud { height: 38px; }
  .danger-readout { height: 24px; }
  .item { min-height: 48px; }
  .slots { min-height: 52px; }
  .spool { height: 40px; }
  .game-foot { min-height: 34px; }
}

@media (max-width: 340px) {
  .screen { padding: 6px; }
  .hud { grid-template-columns: 34px 1fr 1fr 1.2fr 34px; gap: 2px; }
  .hud-block { padding-right: 1px; padding-left: 1px; }
  .item b { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
