:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  color: #f2efe7;
  background: #111318;
  --surface: #191c23;
  --inset: #14171d;
  --edge: #30343e;
  --muted: #a4a9b5;
  --accent: #ffc582;
  --mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% 0%, #2a2530 0%, transparent 58%),
    #111318;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, .playfield:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
canvas { display: block; }
h1, h2, h3, p, dl, dd, ol { margin: 0; }

.app { max-width: 982px; margin-inline: auto; padding: 32px 28px 28px; }
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--edge);
  padding-bottom: 22px;
}
.identity { display: flex; align-items: center; gap: 14px; }
.identity h1 { font-size: 35px; line-height: 1; letter-spacing: -.065em; font-weight: 800; }
.identity p { color: var(--muted); font-size: 12px; margin-top: 6px; }
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  grid-template-rows: repeat(3, 8px);
  place-content: center;
  gap: 2px;
  width: 47px;
  height: 47px;
  flex: none;
  border: 1px solid #574536;
  border-radius: 10px;
  background: #30251f;
}
.brand-mark i { background: var(--accent); border-radius: 1px; }
.brand-mark i:nth-child(1) { grid-area: 1 / 3; }
.brand-mark i:nth-child(2) { grid-area: 2 / 2; }
.brand-mark i:nth-child(3) { grid-area: 2 / 3; }
.brand-mark i:nth-child(4) { grid-area: 3 / 1; }

.header-actions { display: flex; gap: 8px; }
.utility-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 39px;
  padding: 5px 9px 5px 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--surface);
  color: #eeeaf0;
  font-size: 12px;
  font-weight: 650;
}
.utility-button:hover:not(:disabled), .touch-controls button:hover { background: #262a34; border-color: #515766; }
.utility-button:disabled { color: #8e94a2; }
kbd {
  display: inline-grid;
  min-width: 23px;
  min-height: 23px;
  place-items: center;
  padding: 0 5px;
  border: 1px solid #3c414d;
  border-radius: 4px;
  background: #242832;
  color: #e1e4ec;
  font: 11px var(--mono);
  white-space: nowrap;
}

.console {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(0, 330px) minmax(150px, 190px);
  gap: 18px;
  justify-content: center;
  align-items: start;
  margin-block: 24px 20px;
}
.left-rail { display: grid; gap: 14px; min-width: 0; }
.card, .machine, .controls {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 11px;
}
.card { padding: 13px; }
.stats { padding: 15px 14px 14px; }
.stats dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.score, .best { grid-column: 1 / -1; }
.stat dt, h2, .machine-top span {
  color: var(--muted);
  font: 600 10px / 1.2 var(--mono);
  letter-spacing: .11em;
  text-transform: uppercase;
}
.stat dd { font: 600 22px / 1 var(--mono); letter-spacing: -.07em; margin-top: 6px; }
.stat.score dd { color: var(--accent); font-size: clamp(26px, 4.8vw, 41px); overflow-wrap: anywhere; }
.best { display: flex; justify-content: space-between; align-items: baseline; gap: 7px; margin-top: 12px; }
.best dd { margin-top: 0; color: #d2d5df; font-size: 14px; overflow-wrap: anywhere; }
.progression { margin-top: 14px; border-top: 1px solid var(--edge); padding-top: 12px; }
.progression + .progression { padding-left: 14px; }
.card-heading { display: flex; min-height: 24px; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 9px; }
.hold-tray, .next li { position: relative; border: 1px solid #292e38; border-radius: 6px; background: var(--inset); }
.hold-tray { display: grid; place-items: center; min-height: 62px; }
.hold-tray canvas { width: min(100%, 110px); }
.hold-tray span { position: absolute; color: var(--muted); font: 11px var(--mono); }
.hold.is-used canvas { opacity: .55; }
.next ol { padding: 0; list-style: none; display: grid; gap: 8px; }
.next li { display: grid; min-height: 65px; place-items: center; }
.next li:first-child { border-color: #4b403a; }
.next canvas { width: min(100%, 120px); }

.machine { padding-inline: 12px; box-shadow: 0 12px 44px #0005; min-width: 0; }
.machine-top, .machine-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-inline: 2px; }
.machine-top { min-height: 36px; }
.machine-bottom { min-height: 37px; }
.playfield {
  position: relative;
  overflow: hidden;
  border: 1px solid #404653;
  border-radius: 6px;
  background: #11141b;
}
#board { width: 100%; height: auto; }
.status, .streak { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .09em; }
.status { display: flex; align-items: center; gap: 7px; color: #d4d7df; }
.status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px #ffc58255; }
.status[data-state='playing']::before { background: #8ddeae; box-shadow: 0 0 8px #8ddeae66; }
.status[data-state='over']::before { background: #f095b6; box-shadow: 0 0 8px #f095b666; }
.streak { color: var(--accent); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 14px; background: #11141b8c; }
.overlay-panel {
  width: min(100%, 236px);
  padding: 20px 15px 16px;
  border: 1px solid #46424a;
  border-radius: 10px;
  background: #1e2029;
  text-align: center;
  box-shadow: 0 10px 24px #0006;
}
.overlay h3 { font-size: clamp(17px, 3vw, 23px); line-height: 1.15; letter-spacing: -.045em; }
.overlay p { color: #b5bac5; font-size: 12px; line-height: 1.5; margin-block: 8px 15px; }
.overlay p[hidden] + button { margin-top: 14px; }
.play-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #251b15;
  font-size: 12px;
  font-weight: 800;
}
.play-button:hover { background: #ffd8aa; }
.play-button span { font-size: 15px; line-height: 1; }

.controls { display: flex; align-items: center; gap: 15px 23px; padding: 12px 14px; }
.controls h2 { max-width: 80px; line-height: 1.5; }
.controls dl { display: grid; grid-template-columns: repeat(6, auto); gap: 10px; flex: 1; }
.controls dl > div { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.controls dt { color: #c9cdd7; font-size: 11px; white-space: nowrap; }
.controls dd { display: flex; align-items: center; gap: 3px; color: var(--muted); font: 10px var(--mono); }
.controls abbr { text-decoration: none; }
.touch-controls { display: none; }

@media (min-width: 701px) and (max-height: 800px) {
  .app { padding-block: 24px 20px; }
  .app-header { padding-bottom: 18px; }
  .console { grid-template-columns: minmax(150px, 190px) clamp(244px, 61vh - 151px, 330px) minmax(150px, 190px); margin-block: 18px 12px; }
}

@media (max-width: 700px) {
  .app { padding: 18px 14px 20px; }
  .console { grid-template-columns: minmax(104px, 166px) minmax(0, 330px) minmax(104px, 166px); gap: 10px; margin-block: 16px 12px; }
  .card { padding: 9px; }
  .left-rail { gap: 10px; }
  .controls { align-items: flex-start; flex-direction: column; }
  .controls h2 { max-width: none; }
  .controls dl { width: 100%; }
}

@media (max-width: 530px) {
  .app-header { padding-bottom: 13px; }
  .identity { gap: 8px; }
  .identity h1 { font-size: 26px; }
  .identity p { margin-top: 4px; font-size: 10px; }
  .brand-mark { width: 36px; height: 36px; grid-template-columns: repeat(3, 6px); grid-template-rows: repeat(3, 6px); }
  .header-actions { gap: 4px; }
  .utility-button { min-height: 36px; padding-inline: 7px; font-size: 11px; }
  .utility-button kbd { display: none; }
  .console { grid-template-columns: minmax(0, 320px) minmax(76px, 102px); gap: 8px; }
  .machine { grid-area: 1 / 1 / span 2 / 2; padding-inline: 6px; }
  .left-rail { grid-area: 1 / 2; gap: 8px; }
  .next { grid-area: 2 / 2; }
  .card { padding: 7px; }
  .card-heading { min-height: 20px; margin-bottom: 5px; }
  .progression { margin-top: 8px; padding-top: 7px; }
  .progression + .progression { padding-left: 4px; }
  .stat dd { font-size: 16px; }
  .stat dt, h2, .machine-top span { font-size: 9px; }
  .stat.score dd { font-size: 22px; }
  .best { margin-top: 6px; }
  .best dd { font-size: 11px; }
  .hold-tray, .next li { min-height: 38px; }
  .hold-tray span { font-size: 10px; }
  .next ol { gap: 4px; }
  .machine-top, .machine-bottom { min-height: 27px; }
  .overlay { padding: 8px; }
  .overlay-panel { padding: 13px 8px 11px; }
  .overlay p { font-size: 11px; }
  .controls dl { grid-template-columns: repeat(3, 1fr); }
}

@media (pointer: coarse), (max-width: 530px) {
  .touch-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-bottom: 12px; }
  .touch-controls button { min-height: 44px; border: 1px solid var(--edge); border-radius: 6px; background: var(--surface); color: #eeeaf0; font-size: 13px; touch-action: manipulation; }
  .touch-controls button[aria-label] { font-size: 18px; }
  .touch-controls .touch-drop { grid-column: span 2; color: var(--accent); }
}
