:root {
  color-scheme: dark;
  --bg: #102b30;
  --panel: #173b40;
  --ink: #f8eed3;
  --muted: #a3bcb6;
  --mint: #a9efd4;
  --coral: #ff866e;
  --yellow: #f6cd73;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  background: radial-gradient(ellipse at top, #21474a, var(--bg) 70%);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    "Noto Sans TC",
    sans-serif;
  overscroll-behavior: none;
}
main {
  height: 100vh;
  height: 100dvh;
  max-width: 440px;
  margin: auto;
  padding: calc(14px + env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 700;
  margin: 0 0 5px;
  color: var(--mint);
}
.eyebrow span {
  margin-left: 10px;
  letter-spacing: 1px;
  color: var(--muted);
}
h1 {
  font-size: 26px;
  letter-spacing: 2px;
  margin: 0;
  line-height: 1.25;
  font-weight: 900;
}
.badge {
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
  padding: 4px 5px;
  border: 1px solid #718984;
  vertical-align: middle;
  color: var(--yellow);
  border-radius: 3px;
  letter-spacing: 1px;
}
button {
  font: inherit;
  font-weight: 700;
  border: 1px solid #52736e;
  background: #20494c;
  color: var(--ink);
  border-radius: 12px;
  min-height: 44px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active {
  transform: translateY(1px);
  background: #31585a;
}
button:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
.round-button {
  width: 44px;
  border-radius: 50%;
  font-size: 20px;
}
.hud {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr 0.8fr;
  border: 1px solid #456761;
  border-radius: 13px;
  background: #102c30;
  padding: 10px 0;
  flex-shrink: 0;
}
.hud div {
  padding: 0 12px;
  border-right: 1px solid #345652;
}
.hud div:last-child {
  border: 0;
}
.hud span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}
.hud strong {
  font:
    800 23px/1.25 ui-monospace,
    monospace;
  font-variant-numeric: tabular-nums;
}
.hud div:first-child strong {
  color: var(--yellow);
}
.cabinet {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #37625f;
  border: 1px solid #6b8a79;
  border-radius: 20px;
  padding: 0 9px;
  box-shadow:
    0 5px 0 #081f24,
    inset 0 0 0 3px #254d4d;
  overflow: hidden;
}
.screws {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  color: #cee0c5;
  font-size: 10px;
  letter-spacing: 2px;
  flex-shrink: 0;
}
.screws i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid #93a99a;
  background: linear-gradient(
    135deg,
    #203e41 45%,
    #93a99a 46%,
    #93a99a 54%,
    #203e41 55%
  );
}
.playfield {
  min-height: 0;
  flex: 1;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0b2429;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px #091e23;
}
canvas {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 10px;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: #0b2429ec;
  text-align: center;
}
#overlay[hidden] {
  display: none;
}
#overlay-label {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--yellow);
}
#overlay h2 {
  font-size: 22px;
  margin: 6px 0;
}
#overlay-detail {
  color: var(--muted);
  font-size: 13px;
}
#overlay-action,
dialog button {
  background: var(--mint);
  color: #123637;
  border: 0;
  padding: 0 24px;
  margin-top: 14px;
}
.cabinet-foot {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  font:
    9px ui-monospace,
    monospace;
  letter-spacing: 3px;
  color: #b3cec0;
}
footer {
  flex-shrink: 0;
}
#status {
  text-align: center;
  font-size: 12px;
  margin: 0 0 10px;
  color: var(--mint);
  min-height: 17px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1.25fr;
  gap: 8px;
}
.controls button {
  font-size: 12px;
}
#recall {
  border-color: #b69554;
  color: var(--yellow);
}
.legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 10px;
  color: var(--muted);
  margin: 10px 0 0;
  white-space: nowrap;
}
.legend b {
  font-size: 14px;
  margin-right: 3px;
}
.extra {
  color: var(--mint);
}
.split {
  color: var(--yellow);
}
.bomb {
  color: var(--coral);
}
dialog {
  max-width: 365px;
  width: calc(100% - 32px);
  max-height: calc(100dvh - 40px);
  background: #173b40;
  color: var(--ink);
  border: 1px solid #718984;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 24px 80px #0007;
}
dialog::backdrop {
  background: #04171dd9;
}
dialog h2 {
  font-size: 20px;
}
dialog ol {
  padding-left: 20px;
}
dialog li,
dialog > p:not(.eyebrow) {
  font-size: 13px;
  line-height: 1.8;
  color: #cee0d9;
}
dialog li {
  margin-bottom: 9px;
}
dialog button {
  width: 100%;
}
.keyboard-note {
  font-size: 11px !important;
  color: var(--muted) !important;
}
@media (max-height: 700px) {
  main {
    padding-top: 8px;
    padding-bottom: 8px;
    gap: 8px;
  }
  h1 {
    font-size: 23px;
  }
  .hud {
    padding: 7px 0;
  }
  .hud strong {
    font-size: 21px;
  }
  .screws {
    height: 23px;
  }
  .cabinet-foot {
    height: 19px;
  }
  #status {
    margin-bottom: 6px;
  }
  .legend {
    margin-top: 6px;
  }
  .cabinet {
    border-radius: 16px;
  }
}
.items { flex-shrink: 0; background: #102c30; border: 1px solid #456761; border-radius: 13px; padding: 8px; }
.modes { display:flex; gap:4px; }
.modes button { min-height:44px; padding:0 10px; font-size:11px; border-radius:8px; }
.modes button[aria-pressed="true"] { background:#4d5139; border-color:var(--yellow); color:var(--yellow); }
.items-heading { align-items:center; display:flex; justify-content:space-between; gap:4px; color:var(--muted); font-size:10px; margin-bottom:7px; }
.items-heading > span:first-child { color:var(--yellow); font-weight:800; white-space:nowrap; }
.item-buttons { display:grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap:6px; }
.item-buttons button { font-size:10px; padding:4px 3px; border-radius:9px; white-space:nowrap; }
.item-buttons b { color:var(--yellow); font-size:14px; }
.item-buttons button > span { display:inline-block; min-width:15px; margin-left:2px; color:var(--mint); font:800 12px ui-monospace,monospace; }
.item-buttons button[aria-pressed="true"] { border-color:var(--yellow); background:#4d5139; box-shadow: inset 0 0 0 1px var(--yellow); }
#item-blast b { color:var(--coral); }
#item-precision b { color:var(--mint); }
#item-shotgun b { color:#d9a7ff; }
#item-shotgun[aria-pressed="true"] { border-color:#d9a7ff; background:#433659; box-shadow:inset 0 0 0 1px #d9a7ff; }
@media (max-height:700px) {
  .items { padding:4px; }
  .screws { height:16px; }
  .cabinet-foot { height:12px; }
  .items-heading { margin-bottom:4px; }
  main { gap:6px; }
  .legend { gap:6px; font-size:9px; }
}
@media (prefers-reduced-motion: reduce) {
  button:active {
    transform: none;
  }
}

/* Arena-first layout: controls stay usable without shrinking the board. */
main { max-width:560px; padding:calc(6px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); gap:5px; }
header { min-height:44px; gap:6px; }
header .eyebrow, .badge { display:none; }
h1 { font-size:17px; letter-spacing:0; white-space:nowrap; }
.hud { padding:4px 0; border-radius:8px; }
.hud div { padding:0 8px; display:flex; align-items:baseline; gap:5px; }
.hud span { font-size:10px; }
.hud strong { font-size:18px; }
.items { padding:3px; border-radius:9px; }
.items-heading { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
.item-buttons button { min-height:44px; }
.cabinet { padding:0; border-radius:10px; box-shadow:none; }
.screws, .cabinet-foot, .legend { display:none; }
.playfield { border-radius:8px; }
#status { margin:0 0 3px; font-size:11px; min-height:16px; }
.controls { gap:5px; }
@media (max-width:380px) { .hud div { padding:0 5px; gap:3px; } .hud strong { font-size:16px; } h1 { font-size:16px; } }

/* Edge-to-edge arena with a single compact score/mode row. */
main { padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); gap:3px; max-width:640px; }
header { padding:0 3px; gap:3px; }
header .hud { flex:1; min-width:0; padding:0; border:0; background:none; }
header .hud div { display:block; padding:0 4px; }
header .hud span { font-size:8px; }
header .hud strong { font-size:15px; }
header .modes { gap:2px; }
header .modes button { padding:0 8px; min-width:44px; }
header .round-button { flex-shrink:0; }
.items { border:0; padding:0 3px; }
.cabinet, .playfield, canvas { border-radius:0; }
.cabinet { border:0; }
footer { padding:0 3px 3px; }
#status { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
