@font-face {
  font-family: "Fusion Pixel";
  src: url("./assets/fonts/fusion-pixel-zh-hans.woff2") format("woff2");
  font-display: swap;
  font-weight: 400 900;
}

:root {
  color-scheme: dark;
  font-family: "Fusion Pixel", "Microsoft YaHei", "PingFang SC", monospace;
  --ink: #08080b;
  --panel: #111117;
  --cyan: #48d8e8;
  --pink: #ff4f9a;
  --yellow: #ffdf59;
  --green: #69df85;
  --muted: #90909d;
  --toy-viewport-height: 100dvh;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; margin: 0; overflow: hidden; background: #000; overscroll-behavior: none; }
body { height: var(--toy-viewport-height); display: grid; place-items: center; touch-action: none; }
button, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }

#app {
  position: relative;
  width: min(100%, calc(var(--toy-viewport-height) * 0.5625));
  height: auto;
  max-height: var(--toy-viewport-height);
  min-width: 280px;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: var(--ink);
  border-inline: 1px solid #202028;
  isolation: isolate;
}

#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.is-hidden { display: none !important; }

.hud {
  position: absolute;
  z-index: 5;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  height: 58px;
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr 38px;
  gap: 6px;
  pointer-events: none;
}

.hud-metric {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #3a3a46;
  border-bottom-color: var(--cyan);
  background: rgba(8, 8, 11, 0.9);
  text-align: center;
}
.hud-metric span { display: block; color: var(--muted); font-size: 10px; line-height: 1; }
.hud-metric strong { display: block; margin-top: 3px; overflow: hidden; color: #fff; font-size: 17px; line-height: 1; text-overflow: ellipsis; }
.hud-time { border-color: var(--pink); box-shadow: 0 0 10px rgba(255, 79, 154, 0.28); }
.hud-time strong { color: var(--yellow); font-size: 21px; }
.hud-time.is-danger { background: #30121f; box-shadow: 0 0 18px rgba(255, 79, 154, 0.58); }

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--cyan);
  border-radius: 4px;
  background: #111117;
  color: #fff;
  font-size: 21px;
  cursor: pointer;
}
.hud .icon-button { align-self: start; pointer-events: auto; }

.tool-rail {
  position: absolute;
  z-index: 6;
  top: 80px;
  right: 8px;
  width: 84px;
  display: grid;
  gap: 8px;
}
.next-box { height: 104px; border: 1px solid #41414c; background: rgba(8, 8, 11, 0.92); text-align: center; }
.next-box span { color: var(--cyan); font-size: 10px; }
.next-box canvas { width: 74px; height: 74px; display: block; margin: 1px auto; }
.tool-button {
  position: relative;
  width: 84px;
  min-height: 70px;
  padding: 7px 4px 5px;
  border: 1px solid var(--cyan);
  border-radius: 4px;
  background: rgba(17, 17, 23, 0.96);
  box-shadow: 0 0 9px rgba(72, 216, 232, 0.22);
  cursor: pointer;
}
.tool-button b { display: block; color: var(--yellow); font-size: 24px; line-height: 1; }
.tool-button span { display: block; margin-top: 5px; color: #fff; font-size: 11px; }
.tool-button em { position: absolute; top: 3px; right: 4px; color: var(--green); font-size: 10px; font-style: normal; }
.tool-button.danger { border-color: var(--pink); box-shadow: 0 0 9px rgba(255, 79, 154, 0.22); }
.tool-button.is-selected { background: #273239; box-shadow: 0 0 18px rgba(72, 216, 232, 0.65); }
.tool-button:disabled { border-color: #55515c; color: #74717b; box-shadow: 0 0 10px rgba(255, 79, 154, 0.24); cursor: not-allowed; }
.tool-button:disabled b, .tool-button:disabled span { color: #77737d; }

.screen, .overlay-panel, .hard-modal {
  position: absolute;
  z-index: 20;
  inset: 0;
  background: rgba(5, 5, 7, 0.96);
}
.start-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; }
.cabinet-label { margin: 0 0 22px; color: var(--cyan); font-size: 12px; }
.recording-badge { margin: 0 0 12px; padding: 5px 10px; border: 1px solid var(--yellow); color: var(--yellow); font-size: 10px; }
.start-screen h1 { margin: 0; color: #fff; font-size: 42px; line-height: 1.1; text-shadow: 3px 0 var(--pink), -3px 0 var(--cyan); }
.start-screen h1 small { display: block; margin-top: 13px; color: var(--yellow); font-size: 20px; text-shadow: none; }
.mode-control { width: min(360px, 100%); margin: 52px 0 24px; padding: 14px 0; border-block: 1px solid #34343d; display: grid; grid-template-columns: 1fr auto; align-items: center; text-align: left; }
.mode-control span { color: #fff; font-weight: 700; }
.mode-control strong { grid-column: 1 / -1; margin-top: 8px; color: var(--muted); font-size: 11px; font-weight: 400; }
.switch { position: relative; width: 48px; height: 26px; }
.switch input { position: absolute; opacity: 0; }
.switch i { position: absolute; inset: 0; border: 1px solid #5a5a65; border-radius: 4px; background: #1b1b22; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #777783; transition: transform 120ms ease; }
.switch input:checked + i { border-color: var(--pink); box-shadow: 0 0 12px rgba(255,79,154,.5); }
.switch input:checked + i::after { transform: translateX(21px); background: var(--pink); }

.primary-button, .secondary-button, .icon-command, .next-reward {
  min-height: 44px;
  border-radius: 4px;
  cursor: pointer;
}
.primary-button { min-width: 210px; padding: 10px 20px; border: 1px solid var(--pink); background: var(--pink); color: #08080b; font-weight: 900; box-shadow: 0 0 15px rgba(255,79,154,.4); }
.secondary-button { min-width: 210px; margin-top: 10px; padding: 10px 20px; border: 1px solid var(--cyan); background: transparent; color: var(--cyan); }
.primary-button:disabled, .secondary-button:disabled { border-color: #555; background: #29292f; color: #777; box-shadow: none; cursor: not-allowed; }
.insert-button { animation: insert-blink 900ms steps(2, end) infinite; }
@keyframes insert-blink { 50% { opacity: .46; } }
.start-best { margin-top: 28px; color: var(--muted); font-size: 12px; }
.start-best strong { color: var(--yellow); }

.continue-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.continue-screen > span { color: var(--pink); font-size: 18px; }
.continue-screen > strong { margin: 18px 0 2px; color: #fff; font-size: 120px; line-height: 1; text-shadow: 4px 0 var(--cyan); }
.continue-screen h2 { margin: 0 0 44px; color: var(--yellow); font-size: 28px; }

.result-screen { display: grid; grid-template-rows: auto 1fr auto; padding-top: max(8px, env(safe-area-inset-top)); }
.result-head { padding: 8px 16px 12px; border-bottom: 1px solid #34343d; text-align: center; }
.result-head span { color: var(--pink); font-size: 11px; }
.result-head h2 { margin: 0; color: #fff; font-size: 48px; line-height: 1; }
.result-head p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.result-head p strong { color: var(--yellow); }
.result-scroll { overflow-y: auto; padding: 12px 16px 20px; overscroll-behavior: contain; }
#scoreCard { display: block; width: min(82%, 300px); height: auto; aspect-ratio: 3 / 4; margin: 0 auto; border: 1px solid #33333d; background: #09090d; }
.card-actions { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.icon-command { width: 108px; min-height: 40px; border: 1px solid var(--cyan); background: #101016; display: flex; align-items: center; justify-content: center; gap: 8px; }
.icon-command b { color: var(--cyan); font-size: 20px; }
.icon-command span { font-size: 12px; }
.collection-summary, .rank-module { margin-top: 18px; padding-block: 14px; border-top: 1px solid #35353e; }
.collection-summary > div:first-child, .collection-grid-wrap > div:first-child { display: flex; justify-content: space-between; align-items: center; }
.collection-summary span, .collection-grid-wrap span { color: var(--muted); font-size: 12px; }
.collection-summary strong, .collection-grid-wrap strong { color: var(--yellow); }
.progress-track { height: 8px; margin: 9px 0; background: #292930; overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); transition: width 180ms ease; }
.next-reward { width: 100%; padding: 9px; border: 1px solid #56515c; background: #15151b; color: #aaa4ad; text-align: left; box-shadow: 0 0 9px rgba(255,79,154,.22); }
.segments { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.segments.periods { grid-template-columns: repeat(3, 1fr); margin-top: 5px; }
.segments button { min-height: 34px; border: 1px solid #3b3b45; background: #111117; color: var(--muted); cursor: pointer; }
.segments button.is-active { border-color: var(--cyan); color: var(--cyan); }
.rank-module > p { margin: 10px 0; color: var(--yellow); font-size: 11px; }
.rank-module ol { margin: 0; padding: 0; list-style: none; }
.rank-module li { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; min-height: 30px; align-items: center; border-bottom: 1px solid #24242b; font-size: 11px; }
.rank-module li span:first-child { color: var(--pink); }
.rank-module li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-module li strong { color: var(--yellow); }
.result-actions { display: grid; grid-template-columns: 1.25fr .9fr; gap: 8px; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid #34343d; background: #08080b; }
.result-actions .primary-button, .result-actions .secondary-button { min-width: 0; width: 100%; margin: 0; }

.overlay-panel { z-index: 30; overflow-y: auto; background: #08080b; padding: max(16px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom)); }
.overlay-panel > header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid #34343d; }
.overlay-panel h2 { margin: 0; font-size: 22px; }
#unlockStatus { min-height: 30px; margin: 0; color: var(--muted); font-size: 12px; }
.unlock-status-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; min-height: 42px; border-bottom: 1px solid #292930; }
.refresh-button { min-height: 36px; padding: 6px 10px; border: 1px solid #56515c; border-radius: 18px; background: #15151b; color: var(--cyan); cursor: pointer; white-space: nowrap; }
.task-list { border-top: 1px solid #292930; }
.task-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; min-height: 66px; align-items: center; border-bottom: 1px solid #292930; }
.task-row > b { color: var(--cyan); font-size: 22px; text-align: center; }
.task-row strong { display: block; color: #fff; font-size: 13px; }
.task-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.task-row em { color: #77737e; font-size: 11px; font-style: normal; }
.task-row.is-earned em { color: var(--green); }
.task-row.is-unknown em { color: var(--yellow); }
.unlock-actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 16px; }
.unlock-actions .primary-button, .unlock-actions .secondary-button { min-width: 0; width: 100%; margin: 0; padding-inline: 8px; }
.collection-grid-wrap { margin-top: 22px; padding-top: 14px; border-top: 1px solid #35353e; }
.collection-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.collection-cell { position: relative; aspect-ratio: 1; border: 1px solid #383842; display: grid; place-items: center; overflow: hidden; background: #111117; color: #5f5f69; font-size: 10px; text-align: center; }
.collection-cell.is-owned { border-color: var(--cyan); color: #fff; box-shadow: 0 0 7px rgba(72,216,232,.25); }
.collection-cell.is-shape { grid-template-rows: 1fr auto; gap: 1px; padding: 4px 2px 3px; }
.collection-cell.is-shape img { width: min(82%, 48px); aspect-ratio: 1; border: 1px solid #55515c; border-radius: 50%; object-fit: cover; filter: grayscale(1) brightness(.3); opacity: .72; }
.collection-cell.is-shape small { color: #696973; font-size: 8px; line-height: 1; }
.collection-cell.is-shape.is-owned img { border-color: #fff; filter: none; opacity: 1; }
.collection-cell.is-shape.is-owned small { color: var(--yellow); }
.collection-lock { position: absolute; inset: 4px 2px 13px; display: grid; place-items: center; color: #d8d8df; font-size: 12px; text-shadow: 0 1px 3px #000; }

.hard-modal { z-index: 40; inset: 20% 8% auto; min-height: 330px; padding: 28px 22px; border: 2px solid var(--pink); box-shadow: 0 0 30px rgba(255,79,154,.42); text-align: center; }
.hard-modal > span { color: var(--cyan); font-size: 11px; }
.hard-modal h2 { margin: 18px 0 10px; color: var(--yellow); font-size: 26px; }
.hard-modal p { min-height: 64px; color: #d8d8df; font-size: 13px; line-height: 1.7; }
.hard-modal .primary-button, .hard-modal .secondary-button { width: 100%; min-width: 0; }
.toast { position: absolute; z-index: 60; left: 50%; bottom: 90px; width: max-content; max-width: 84%; margin: 0; padding: 9px 13px; transform: translateX(-50%); border: 1px solid var(--cyan); background: rgba(8,8,11,.96); color: #fff; font-size: 12px; text-align: center; opacity: 0; pointer-events: none; transition: opacity 140ms ease; }
.toast.is-visible { opacity: 1; }

@media (pointer: fine) and (hover: hover) {
  button:not(:disabled):hover { filter: brightness(1.08); }
  #gameCanvas { cursor: crosshair; }
}

@media (pointer: coarse) {
  button { min-height: 44px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .tool-rail { top: 68px; gap: 5px; }
  .tool-button { min-height: 62px; }
}

@media (max-width: 360px) {
  .start-screen h1 { font-size: 34px; }
  .hud { left: 7px; right: 7px; gap: 3px; }
  .hud-metric { padding-inline: 4px; }
  .tool-rail { right: 5px; width: 70px; }
  .tool-button { width: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
