:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #182026;
  --muted: #63707a;
  --line: #d8e0e5;
  --line-strong: #aebbc4;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --soft: #eaf2ff;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  min-height: 56px;
  padding: 0 clamp(16px, 4vw, 64px);
  border-bottom: 1px solid var(--line-strong);
  background: var(--panel);
}
.brand, .back-link, .title-block { display: flex; align-items: center; }
.brand { justify-self: start; gap: 10px; font-weight: 700; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 2px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 13px;
}
.title-block { align-self: stretch; gap: 14px; padding: 0 20px; border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
.title-block span, .back-link { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.title-block strong { font-size: 14px; }
.back-link { justify-self: end; color: var(--accent-dark); }
.back-link:hover, .back-link:focus-visible { text-decoration: underline; outline: 0; }

.game-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
  border: 1px solid var(--line-strong);
  background: var(--panel);
}
.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  min-height: 84px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-strong);
}
.panel-heading p { margin: 0 0 4px; color: var(--accent-dark); font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; }
h1 { margin: 0; font-size: 26px; line-height: 1.1; letter-spacing: -0.025em; }
.run-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.run-state i { width: 8px; height: 8px; background: var(--line-strong); }
.run-state i.active { background: var(--accent); }
.run-state i.danger { background: #dc2626; }

.game-workspace { display: grid; grid-template-columns: minmax(380px, 1fr) 330px; }
.playfield-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 656px;
  padding: 28px;
  border-right: 1px solid var(--line-strong);
  background: #eef2f5;
}
#game {
  display: block;
  width: 300px;
  height: 600px;
  border: 1px solid var(--line-strong);
  background: #f9fbfc;
  image-rendering: pixelated;
}
.overlay {
  position: absolute;
  inset: 50% auto auto 50%;
  display: flex;
  width: 252px;
  min-height: 96px;
  padding: 18px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  transform: translate(-50%, -50%);
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.overlay[hidden] { display: none; }
.overlay strong { margin-bottom: 5px; font-size: 18px; }
.overlay span { color: var(--muted); font-size: 12px; }

.instrument-panel { min-width: 0; background: var(--panel); }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; border-bottom: 1px solid var(--line-strong); }
.metrics div { padding: 18px 14px; border-right: 1px solid var(--line); }
.metrics div:last-child { border-right: 0; }
dt { color: var(--muted); font-family: var(--mono); font-size: 10px; text-transform: uppercase; }
dd { margin: 5px 0 0; }
.metrics dd { color: var(--accent-dark); font-family: var(--mono); font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.next-block, .key-map { border-bottom: 1px solid var(--line-strong); }
.subhead { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.subhead b { color: var(--muted); font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; }
#next { display: block; width: 128px; height: 128px; margin: 16px auto; background: #f9fbfc; }
.game-actions { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line-strong); }
.game-actions button, .touch-panel button {
  min-height: 46px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.game-actions button:last-child { border-right: 0; }
.game-actions button:hover, .game-actions button:focus-visible, .touch-panel button:active { background: var(--soft); color: var(--accent-dark); outline: 0; }
.game-actions .primary, .touch-panel .touch-primary { background: var(--accent); color: #fff; }
.game-actions .primary:hover, .game-actions .primary:focus-visible, .touch-panel .touch-primary:active { background: var(--accent-dark); color: #fff; }
.key-map dl { margin: 0; }
.key-map dl div { display: grid; grid-template-columns: 88px 1fr; padding: 7px 14px; border-bottom: 1px solid var(--line); }
.key-map dl div:last-child { border-bottom: 0; }
.key-map dd { margin: 0; color: var(--muted); font-size: 11px; }

.touch-panel { display: none; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line-strong); }
.touch-panel button:last-child { border-right: 0; }
footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(16px, 4vw, 64px) 24px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

@media (max-width: 760px) {
  .game-header { grid-template-columns: 1fr auto; }
  .title-block { display: none; }
  .game-shell { width: calc(100% - 20px); margin: 10px auto 18px; }
  .panel-heading { min-height: 72px; padding: 14px 16px; }
  h1 { font-size: 22px; }
  .game-workspace { grid-template-columns: 1fr; }
  .playfield-wrap { min-height: 0; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line-strong); }
  #game { width: min(300px, calc(100vw - 46px)); height: auto; aspect-ratio: 1 / 2; }
  .instrument-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .metrics { grid-column: 1 / 3; }
  .next-block { border-right: 1px solid var(--line-strong); }
  #next { width: 112px; height: 112px; margin: 8px auto; }
  .game-actions { align-content: start; grid-template-columns: 1fr; }
  .game-actions button { border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .game-actions button:last-child { border-bottom: 0; }
  .key-map { display: none; }
  .touch-panel { display: grid; position: sticky; bottom: 0; background: var(--panel); }
  .touch-panel button { min-height: 54px; font-size: 18px; }
  .touch-panel .touch-primary { font-size: 12px; }
  footer { flex-direction: column; gap: 4px; padding-bottom: 18px; }
}

@media (max-height: 760px) and (min-width: 761px) {
  .game-shell { margin-top: 14px; margin-bottom: 14px; }
  .panel-heading { min-height: 66px; }
  .playfield-wrap { min-height: 584px; padding: 14px; }
  #game { width: 270px; height: 540px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
