:root { color-scheme: dark; font-family: system-ui, sans-serif; background: #111827; color: #f3f4f6; }
* { box-sizing: border-box; }
body { margin: 0; padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); }
main { max-width: 460px; margin: auto; text-align: center; }
header p { margin: 6px 0 12px; color: #cbd5e1; font-size: 13px; }
header .eyebrow { color: #8ee4bd; font-size: 10px; letter-spacing: .22em; }
h1 { margin: 0; font-size: 25px; letter-spacing: -.04em; }
.game { overflow: hidden; position: relative; border-radius: 16px; border: 1px solid #334155; background: #2b335f; touch-action: none; }
canvas { max-width: 100%; height: auto; image-rendering: pixelated; }
/* Pyxel injects full-screen defaults. Keep the real screen inside our card. */
.game div#pyxel-screen { position: relative; left: auto; top: auto; width: 100%; height: auto; aspect-ratio: 256 / 244; }
.game pyxel-run { display: none; }
.game canvas#canvas { width: 100%; height: 100%; max-width: none; }
.controls { display: flex; justify-content: center; align-items: center; gap: 24px; }
button { min-width: 48px; min-height: 44px; border: 1px solid #475569; border-radius: 10px; background: #26344a; color: #f8fafc; font: inherit; font-size: 14px; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button:active { background: #475569; transform: translateY(1px); }
button:focus-visible { outline: 3px solid #fbbf24; outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 44px); gap: 5px; }
.up { grid-column: 2; }.left { grid-column: 1; grid-row: 2; }.down { grid-column: 2; grid-row: 2; }.right { grid-column: 3; grid-row: 2; }
.actions { display: grid; gap: 5px; }
.actions button { padding: 0 14px; }
.dpad button[data-kind="undo"] { border-color: #f6d373; color: #f6d373; }
.dpad button[data-kind="undo"]::after { content: '戻る'; display: block; font-size: 9px; line-height: 10px; }
.share { width: 100%; margin-top: 14px; background: #97e8bd; color: #11271c; border: none; font-weight: 700; }
#shareStatus { font-size: 12px; min-height: 16px; color: #cbd5e1; margin: 8px 0; }
#shareStatus:empty { display: none; }
details { text-align: left; font-size: 12px; line-height: 1.8; color: #cbd5e1; }
summary { min-height: 44px; display: list-item; align-content: center; cursor: pointer; }
.scoreboard { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; background: #1c293d; border: 1px solid #334155; border-radius: 12px; padding: 10px 6px; }
.scoreboard span { display: block; font-size: 9px; color: #b4c6df; letter-spacing: .08em; }
.scoreboard strong { display: block; font-size: 26px; line-height: 1.3; font-variant-numeric: tabular-nums; color: #f6d373; }
.scoreboard #scoreDelta { color: #97e8bd; font-size: 22px; padding-top: 3px; }
.scoreboard #maximumButton { min-width: 44px; min-height: 44px; width: 100%; padding: 2px; border: 0; border-radius: 4px; font-size: 10px; background: #31445e; color: #e3edf9; }
.scoreboard #maximumButton:disabled { background: transparent; opacity: 1; color: #b4c6df; }
#milestoneMessage { min-height: 22px; margin: 6px 0 0; font-size: 14px; font-weight: 700; color: #97e8bd; }
#milestoneMessage[data-tier="200"] { color: #f6d373; }
#result { min-height: 20px; margin: 4px 0 10px; color: #fbbf24; font-size: 13px; }

@media (max-width: 600px) {
  body { padding: calc(8px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  header { margin-bottom: 6px; }
  header p { display: none; }
  h1 { font-size: 21px; line-height: 28px; }
  .game { width: min(100%, calc((100svh - 280px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 256 / 244)); margin: auto; }
  .scoreboard { margin-top: 6px; padding: 6px; min-height: 58px; align-items: center; }
  .scoreboard strong { font-size: 24px; }
  .scoreboard #scoreDelta { font-size: 21px; }
  #maximumButton:not(:disabled) + #maximumValue { display: none; }
  .scoreboard #maximumButton:disabled { min-height: 16px; }
  .feedback { min-height: 44px; padding: 2px 0; }
  #milestoneMessage { min-height: 20px; margin: 0; font-size: 12px; line-height: 20px; }
  #result { min-height: 20px; margin: 0; font-size: 12px; line-height: 20px; }
  .controls { --key-size: clamp(52px, 14vw, 56px); gap: 12px; }
  .dpad { grid-template-columns: repeat(3, var(--key-size)); grid-template-rows: repeat(2, var(--key-size)); gap: 8px; }
  .dpad button { font-size: 19px; }
  .actions { grid-template-columns: repeat(2, var(--key-size)); grid-template-rows: repeat(2, var(--key-size)); gap: 8px; }
  .actions #undoButton { grid-column: 1 / -1; font-size: 15px; }
  .actions button { min-width: 0; padding: 0 2px; font-size: 11px; }
  .share { margin-top: 10px; }
}

@media (min-width: 600px) and (max-height: 500px) {
  body { padding: calc(6px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  main { display: grid; grid-template-columns: 1fr 1fr; max-width: 900px; gap: 6px 14px; }
  header { grid-column: 1 / -1; }
  header p { display: none; }
  h1 { font-size: 20px; line-height: 24px; }
  .game { grid-column: 1; grid-row: 2 / 6; width: min(100%, calc((100svh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 256 / 244)); justify-self: center; align-self: start; }
  .scoreboard, .feedback, .controls, .share { grid-column: 2; margin: 0; }
  .scoreboard { padding: 4px; align-items: center; }
  .scoreboard strong { font-size: 22px; }
  #maximumButton:not(:disabled) + #maximumValue { display: none; }
  .scoreboard #maximumButton:disabled { min-height: 16px; }
  #milestoneMessage { min-height: 18px; margin: 0; font-size: 12px; }
  #result { margin: 0; font-size: 12px; }
  .controls { gap: 10px; }
  .dpad { grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); gap: 6px; }
  .actions { grid-template-columns: repeat(2, 52px); grid-template-rows: repeat(2, 52px); gap: 6px; }
  .actions #undoButton { grid-column: 1 / -1; }
  .actions button { min-width: 0; padding: 0 2px; font-size: 11px; }
  #shareStatus, details { grid-column: 1 / -1; }
}
