:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  --cell: 24px;
  --side: 76px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
}
body {
  padding: 8px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 3px solid #b8a6ff;
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- shell & HUD ---------- */
.bd-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 10px 12px 12px;
  border-radius: 24px;
  background:
    radial-gradient(
      120% 70% at 50% 0%,
      rgba(104, 66, 255, 0.24),
      transparent 60%
    ),
    linear-gradient(180deg, #1a1b2e, #131425);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 60px rgba(0, 0, 0, 0.45);
}
.bd-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.bd-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bd-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff, #cbbcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.bd-logo {
  display: grid;
  grid-template-columns: repeat(3, 10px);
  grid-template-rows: repeat(2, 10px);
  gap: 2px;
  flex: none;
}
.bd-logo i {
  border-radius: 3px;
  background: linear-gradient(180deg, #d9a6ff, #a855f7 55%, #7a2fd0);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.bd-logo i:nth-child(1) {
  grid-column: 2;
}
.bd-logo i:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}
.bd-logo i:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
}
.bd-logo i:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}
.bd-chips {
  display: flex;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
}
.bd-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  line-height: 1.05;
}
.bd-chip span {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.bd-chip strong {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.bd-chip-score {
  min-width: 84px;
  background: linear-gradient(180deg, #7b5cff, #5a36f0);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 14px rgba(104, 66, 255, 0.4);
}
.bd-chip-score span {
  color: #e3dbff;
}
.bd-chip strong.bump {
  animation: bd-bump 0.28s ease-out;
}
@keyframes bd-bump {
  40% {
    transform: scale(1.25);
    color: #ffe45c;
  }
}
.bd-icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 3px 0 #17182a;
  cursor: pointer;
}
.bd-icon-btn svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}
.bd-icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.bd-icon-btn:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* ---------- stage ---------- */
.bd-stage {
  display: grid;
  grid-template-columns: var(--side) auto var(--side);
  grid-template-areas: "hold board next";
  justify-content: center;
  align-items: start;
  gap: 10px;
}
.bd-hold {
  grid-area: hold;
}
.bd-next {
  grid-area: next;
}
.bd-board-wrap {
  grid-area: board;
}
.bd-panel {
  padding: 8px 6px 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 6px 18px rgba(0, 0, 0, 0.3);
  text-align: center;
  margin-top: calc(var(--cell) * 2);
}
.bd-panel h2 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.bd-panel canvas {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}
.bd-hold.used canvas {
  opacity: 0.35;
  filter: grayscale(0.8);
}

.bd-board-wrap {
  position: relative;
  border-radius: 14px;
}
#bd-board {
  display: block;
  width: calc(var(--cell) * 10);
  height: calc(var(--cell) * 22);
  touch-action: none;
  border-radius: 12px;
  cursor: pointer;
}
#bd-board:focus-visible {
  outline: none;
}
.bd-board-wrap::after {
  content: "";
  position: absolute;
  inset: calc(var(--cell) * 2) 0 0 0;
  border-radius: 12px;
  pointer-events: none;
}
.bd-board-wrap:has(#bd-board:focus-visible)::after {
  outline: 3px solid #b8a6ff;
  outline-offset: 3px;
}
.bd-board-wrap.shake {
  animation: bd-shake 0.16s ease-out;
}
.bd-board-wrap.thud {
  animation: bd-thud 0.14s ease-out;
}
@keyframes bd-shake {
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}
@keyframes bd-thud {
  40% {
    transform: translateY(4px);
  }
}

/* popup text */
.bd-popup {
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}
.bd-popup .pop {
  display: block;
  font-weight: 900;
  line-height: 1.05;
  animation: bd-pop 1.1s ease-out forwards;
  text-shadow:
    0 3px 0 rgba(0, 0, 0, 0.35),
    0 0 18px rgba(104, 66, 255, 0.9);
}
.bd-popup .pop-main {
  font-size: calc(var(--cell) * 1.05);
  background: linear-gradient(180deg, #fff 20%, #ffe45c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.45))
    drop-shadow(0 0 10px rgba(255, 170, 60, 0.6));
  text-shadow: none;
}
.bd-popup .pop-sub {
  font-size: calc(var(--cell) * 0.7);
  color: #c9b8ff;
}
.bd-popup .pop-points {
  font-size: calc(var(--cell) * 0.8);
  color: #7ef7ff;
}
.bd-popup .pop-level {
  font-size: calc(var(--cell) * 1.2);
  color: #7dff9b;
}
@keyframes bd-pop {
  0% {
    opacity: 0;
    transform: scale(0.4);
  }
  15% {
    opacity: 1;
    transform: scale(1.18);
  }
  28% {
    transform: scale(1);
  }
  75% {
    opacity: 1;
    transform: translateY(-8px);
  }
  100% {
    opacity: 0;
    transform: translateY(-24px);
  }
}

/* ---------- overlay ---------- */
.bd-overlay {
  position: absolute;
  inset: calc(var(--cell) * 2) 0 0 0;
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 12px;
  background: rgba(12, 12, 28, 0.66);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 3;
}
.bd-overlay[hidden] {
  display: none;
}
.bd-card {
  width: 100%;
  max-width: 280px;
  padding: 18px 14px 16px;
  border-radius: 20px;
  text-align: center;
  background: linear-gradient(180deg, #26274a, #1b1c2e);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 18px 40px rgba(0, 0, 0, 0.5),
    0 0 0 2px rgba(104, 66, 255, 0.45);
  animation: bd-card-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes bd-card-in {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }
}
.bd-card-logo {
  font-size: clamp(26px, calc(var(--cell) * 1.45), 42px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.01em;
  margin-bottom: 8px;
}
.bd-card-logo span {
  display: inline-block;
  color: var(--c);
  text-shadow:
    0 3px 0 color-mix(in srgb, var(--c) 45%, #000),
    0 6px 12px rgba(0, 0, 0, 0.45),
    0 0 16px color-mix(in srgb, var(--c) 60%, transparent);
  animation: bd-letter 2.4s ease-in-out infinite;
}
.bd-card-logo span:nth-child(odd) {
  animation-delay: -1.2s;
}
@keyframes bd-letter {
  50% {
    transform: translateY(-3px);
  }
}
.c1 {
  --c: #4ee8ff;
}
.c2 {
  --c: #ffd84a;
}
.c3 {
  --c: #c77dff;
}
.c4 {
  --c: #5dff8a;
}
.c5 {
  --c: #ff5a6e;
}
.c6 {
  --c: #5c8dff;
}
.c7 {
  --c: #ff9f43;
}
.bd-overlay-title {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 900;
}
.bd-overlay[data-mode="start"] .bd-overlay-title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.bd-overlay:not([data-mode="start"]) .bd-card-logo {
  display: none;
}
.bd-overlay-copy {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}
.bd-results {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 10px;
}
.bd-results[hidden] {
  display: none;
}
.bd-results div {
  flex: 1;
  padding: 6px 4px;
  border-radius: 12px;
  background: var(--secondary);
}
.bd-results dt {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.bd-results dd {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.bd-newbest {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 900;
  color: #ffe45c;
  text-shadow: 0 0 14px rgba(255, 200, 60, 0.7);
  animation: bd-letter 1s ease-in-out infinite;
}
.bd-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s;
}
.bd-btn + .bd-btn {
  margin-top: 8px;
}
.bd-btn[hidden] {
  display: none;
}
.bd-btn-primary {
  background: linear-gradient(180deg, #8467ff, #6842ff 55%, #5230e6);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 5px 0 #3b1fb3,
    0 10px 22px rgba(104, 66, 255, 0.45);
}
.bd-btn-secondary {
  min-height: 44px;
  font-size: 16px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #17182a;
}
.bd-btn:active {
  transform: translateY(3px);
}

/* ---------- touch pad ---------- */
.bd-pad {
  display: none;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
  margin: 12px auto 0;
  max-width: 480px;
}
.bd-key {
  grid-column: span 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #33344c, var(--secondary));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 0 #17182a;
  cursor: pointer;
  touch-action: none;
}
.bd-key-wide {
  grid-column: span 4;
  min-height: 56px;
}
.bd-key svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bd-key span {
  font-size: 11px;
  color: var(--muted);
}
.bd-key-drop {
  background: linear-gradient(180deg, #8467ff, #6842ff 55%, #5230e6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 #3b1fb3;
}
.bd-key-drop span {
  color: #e3dbff;
}
.bd-key.down {
  transform: translateY(3px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  filter: brightness(1.2);
}
.bd-help {
  margin: 10px 0 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.8;
}
kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 1px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #17182a;
  font: inherit;
  font-size: 11px;
  color: #fff;
  text-align: center;
}

@media (pointer: coarse), (max-width: 600px) {
  .bd-pad {
    display: grid;
  }
  .bd-help {
    display: none;
  }
}
@media (max-width: 600px) {
  body {
    padding: 4px;
  }
  .bd-shell {
    padding: 8px;
    border-radius: 18px;
  }
  .bd-brand h1 {
    display: none;
  }
  .bd-hud {
    gap: 6px;
  }
  .bd-chips {
    flex: 1;
    gap: 4px;
  }
  .bd-chip {
    flex: 1;
    min-width: 0;
    padding: 4px 4px;
  }
  .bd-chip-score {
    flex: 1.35;
    min-width: 0;
  }
  .bd-chip strong {
    font-size: 15px;
  }
  .bd-chip span {
    font-size: 9px;
  }
  .bd-stage {
    grid-template-columns: auto var(--side);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "board hold"
      "board next";
    gap: 8px;
  }
  .bd-next {
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
  .bd-popup .pop {
    animation: none;
    opacity: 1;
  }
}
