:root {
  --bg: #070a14;
  --panel: #111827;
  --line: #1f2937;
  --text: #e5e7eb;
  --muted: #8b96ab;
  --accent: #22d3ee;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 800px at 20% -10%, #16233f 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.game {
  display: flex;
  align-items: flex-start;
  gap: 22px;
}

.board-wrap {
  position: relative;
  line-height: 0;
}

#board {
  height: min(84vh, 660px);
  width: auto;
  max-width: 46vw;
  background: #0b1020;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px #0e1526 inset;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  background: rgba(7, 10, 20, .82);
  text-align: center;
  font-size: 22px;
  letter-spacing: .04em;
  color: var(--accent);
}

.overlay.hidden { display: none; }

.overlay .hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.panel {
  width: 232px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  margin: 0;
  font-size: 20px;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.brand span {
  display: block;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: .42em;
}

.stats {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
}

.stat .label { color: var(--muted); }

.stat .value {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.next {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.next h2 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--muted);
}

#next {
  width: 120px;
  height: 240px;
  display: block;
}

.keys {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.keys li { padding: 2px 0; }

kbd {
  background: #1b2437;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
}

@media (max-width: 720px) {
  .game { flex-direction: column; align-items: center; }
  #board { max-width: 92vw; height: min(66vh, 560px); }
  .panel { width: min(92vw, 380px); }
}

/* Touch devices only: the pointer: fine (desktop) layout above is untouched.
   `pointer: coarse` covers phones/tablets; the hover fallback catches devices
   that report a fine pointer but have no hovering input. A desktop with a
   mouse always reports hover: hover, so it never matches. */
.pad { display: none; }

@media (pointer: coarse), (hover: none) and (max-width: 900px) {
  body {
    display: block;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    align-items: stretch;
  }

  .game {
    display: grid;
    grid-template-areas: 'board' 'panel' 'pad';
    align-content: space-between;
    justify-items: center;
    gap: 10px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: calc(100dvh - 16px);
  }

  .board-wrap { grid-area: board; }

  #board {
    height: 52vh;
    width: auto;
    max-width: 86vw;
    touch-action: none;
  }

  .panel {
    grid-area: panel;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  .brand { display: none; }
  .keys { display: none; }

  .stats { flex: 1 1 150px; padding: 6px 10px; }
  .stat { padding: 1px 0; }
  .stat .value { font-size: 15px; }

  .next { padding: 6px 10px; }
  .next h2 { margin: 0 0 2px; font-size: 9px; }
  #next { width: 60px; height: 120px; }

  .overlay .hint { display: none; }

  .pad {
    grid-area: pad;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .pad button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    padding: 10px 0;
    font: inherit;
    font-size: 22px;
    line-height: 1;
    color: var(--text);
    background: #182236;
    border: 1px solid var(--line);
    border-radius: 12px;
    touch-action: none;
  }

  .pad button svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .pad button:active {
    background: #22304d;
    transform: translateY(1px);
  }
}

@media (pointer: coarse) and (orientation: landscape), (hover: none) and (max-width: 900px) and (orientation: landscape) {
  .game {
    grid-template-areas: 'board panel' 'board pad';
    grid-template-columns: auto minmax(170px, 1fr);
    align-content: center;
    gap: 12px;
    max-width: none;
  }

  #board { height: 82vh; }

  .pad { grid-template-columns: repeat(3, 1fr); }
  .pad button { min-height: 48px; font-size: 18px; }
}
