:root {
  color-scheme: dark;
  font-family: system-ui, "Yu Gothic UI", sans-serif;
  background: #16132a;
  color: #fff4fd;
  --muted: #d0c2df;
  --line: #584566;
  --accent: #ff8bb1;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #372244, transparent 65%);
}
main { width: min(780px, calc(100% - 28px)); margin: auto; padding: 22px 0; }
header { margin-bottom: 16px; }
header p { color: var(--muted); margin: 5px 0 0; }
header .series { color: var(--accent); font-size: .82rem; font-weight: 700; letter-spacing: .1em; }
h1 { margin: 2px 0; font-size: clamp(1.55rem, 5vw, 2.6rem); }
.layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(210px, 1fr); gap: 14px; }
.board {
  position: relative;
  align-self: start;
  overflow: hidden;
  border-radius: 16px;
  outline: 1px solid var(--line);
  background: #201a33;
}
@media (prefers-reduced-motion: no-preference) {
  .board { transform: translate(var(--shake-x, 0px), var(--shake-y, 0px)); }
}
canvas { width: 100%; height: auto; display: block; }
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
  background: #171225e8;
}
.overlay h2, .overlay p { margin: 0 0 12px; }
.mode-picker { border: 0; min-width: 0; margin: 0 0 16px; padding: 0; width: 100%; }
.mode-picker legend { margin: 0 auto 8px; padding: 0; color: var(--muted); font-size: .82rem; }
.mode-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.mode-option { position: relative; display: flex; }
.mode-option input { position: absolute; opacity: 0; }
.mode-option span {
  display: grid;
  place-content: center;
  width: 100%;
  min-height: 52px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #382b4c;
  font-size: .8rem;
  cursor: pointer;
}
.mode-option input:checked + span { border-color: var(--accent); background: #532e50; }
.mode-option input:focus-visible + span { outline: 2px solid #fff; outline-offset: 2px; }
aside { display: grid; align-content: start; gap: 12px; }
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scores > div, .panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: #27203c;
}
.scores span, .panel h2 { color: var(--muted); font-size: .78rem; letter-spacing: .08em; }
.scores strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.panel h2 { margin: 0 0 8px; }
.next { min-height: 100px; }
.next canvas { width: min(100%, 152px); margin-inline: auto; }
dl { margin: 0 0 14px; }
dl div { display: flex; justify-content: space-between; gap: 6px; margin: 6px 0; }
dd { margin: 0; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
button {
  border: 1px solid var(--line);
  background: #382b4c;
  color: inherit;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover:enabled { border-color: var(--accent); }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
#primary { background: #ff8bb1; color: #23102a; font-weight: 800; }
.hint { font-size: .8rem; margin: 12px 0 0; color: var(--muted); }
.touch-controls { display: none; }
@media (any-pointer: coarse), (max-width: 620px) {
  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1.5fr 1fr 1fr;
    gap: 5px;
    margin-top: 8px;
  }
  .touch-controls button {
    min-height: 46px;
    padding: 4px 2px;
    font-size: 1.2rem;
    touch-action: manipulation;
    user-select: none;
  }
  .touch-controls [data-move] { touch-action: none; }
  .touch-controls [data-drop] { background: var(--accent); color: #23102a; font-size: .95rem; font-weight: 800; }
  .touch-controls button:active { filter: brightness(1.25); }
}
@media (max-width: 620px) {
  main { width: min(420px, calc(100% - 20px)); padding: 10px 0; }
  header { margin-bottom: 8px; }
  header > p:last-child { display: none; }
  .layout { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  aside { display: contents; }
  .scores { grid-column: 1; grid-row: 1; gap: 4px; }
  .scores > div, .next { padding: 4px 5px; min-height: 0; }
  .scores span, .next h2 { font-size: .65rem; }
  .scores strong { font-size: 1rem; overflow-wrap: anywhere; }
  .next { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 4px; }
  .next h2 { margin: 0; }
  .next canvas { width: min(100%, 94px); min-width: 0; }
  .play-area { grid-column: 1 / -1; grid-row: 2; }
  .board {
    width: min(100%, max(220px, calc((100svh - 290px) * 420 / 570)));
    margin-inline: auto;
  }
  .overlay { padding: 12px; }
  .controls { grid-column: 1 / -1; grid-row: 3; padding: 5px; }
  .controls h2, .controls dl, .controls .hint { display: none; }
  .controls button { min-height: 44px; font-size: .78rem; }
}
