* {
  box-sizing: border-box;
}

:root {
  --bg-top: #1a0e00;
  --bg-bottom: #020617;
  --panel: rgba(20, 10, 0, 0.78);
  --panel-border: rgba(245, 158, 11, 0.28);
  --text-main: #fef9f0;
  --text-dim: #c4a46b;
  --accent: #f59e0b;
  --accent-rgb: 245, 158, 11;
  --tone-warn: #fb7185;
  --button-bg: linear-gradient(180deg, var(--accent), #d97706);
  --shadow: 0 18px 40px rgba(8, 3, 0, 0.34);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(var(--accent-rgb), 0.12), transparent 34%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text-main);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.game-shell {
  width: 100vw;
  min-height: 100vh;
  margin: 0 auto;
  padding: 8px 8px 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
}

.topbar {
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}

.topbar-copy {
  display: grid;
  gap: 2px;
}

.eyebrow {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title {
  font-size: 22px;
  line-height: 1;
}

#restart {
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--button-bg);
  color: #fff7ed;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 10px 14px;
  white-space: nowrap;
}

#restart:hover,
#restart:focus-visible {
  filter: brightness(1.08);
}

/* ── Game area: board + side rail ─────────────────────────────── */

.game-area {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: flex-start;
  justify-content: center;
  padding: 0 2px 0 6px;
  min-height: 0;
}

.board-wrap {
  flex: none;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

#game {
  display: block;
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  border-radius: 8px;
  background: var(--bg-bottom);
  box-shadow:
    inset 0 0 0 1px rgba(var(--accent-rgb), 0.06),
    0 0 18px rgba(var(--accent-rgb), 0.1);
}

/* ── Side rail ────────────────────────────────────────────────── */

.side-rail {
  flex: 1;
  max-width: 78px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 0;
}

.preview-box {
  border: 1.5px solid var(--panel-border);
  border-radius: 4px;
  padding: 3px 2px 2px;
  text-align: center;
  background: rgba(20, 10, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.preview-box canvas {
  display: block;
}

.hold-preview {
  border-style: dashed;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.hold-preview:hover {
  filter: brightness(1.15);
}

.hold-preview:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hold-preview.hold-empty {
  opacity: 0.55;
}

.hold-preview.hold-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview-label,
.stat-label {
  display: block;
  font: 700 7px/1 monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stat-block {
  text-align: center;
  padding: 3px 2px;
}

.stat-block strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
  color: var(--text-main);
}

.status-wrap {
  text-align: center;
  padding: 2px 1px;
  min-height: 18px;
}

#status {
  display: block;
  font: 700 7px/1.3 monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  word-break: break-word;
}

.status-wrap[data-tone="milestone"] #status {
  color: var(--accent);
}

.status-wrap[data-tone="warning"] #status {
  color: var(--tone-warn);
}

/* ── Control deck ─────────────────────────────────────────────── */

.control-deck {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 12px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-radius: 0 0 18px 18px;
  border: 1px solid var(--panel-border);
  border-top-style: dashed;
  gap: 8px;
}

/* ── D-pad cluster ────────────────────────────────────────────── */

.dpad-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dpad {
  position: relative;
  width: 120px;
  height: 120px;
  touch-action: none;
}

.dpad-v-bar {
  position: absolute;
  left: 40px;
  top: 0;
  width: 40px;
  height: 120px;
  background: rgba(15, 8, 0, 0.9);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
}

.dpad-h-bar {
  position: absolute;
  left: 0;
  top: 40px;
  width: 120px;
  height: 40px;
  background: rgba(15, 8, 0, 0.9);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
}

.dpad-btn {
  position: absolute;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  z-index: 2;
  color: var(--text-main);
  font: 700 16px/1 monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  padding: 0;
}

.dpad-btn:active {
  filter: brightness(1.3);
}

.dpad-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.dpad-up {
  top: 0;
  left: 40px;
  background: var(--accent);
  color: var(--bg-bottom);
  border: 2px solid rgba(0, 0, 0, 0.4);
  border-radius: 6px 6px 0 0;
  z-index: 3;
}

.dpad-left {
  top: 40px;
  left: 0;
}

.dpad-right {
  top: 40px;
  left: 80px;
}

.dpad-down {
  top: 80px;
  left: 40px;
}

/* ── Rotation cluster ─────────────────────────────────────────── */

.rotate-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rotate-cluster {
  position: relative;
  width: 130px;
  height: 120px;
}

.rotate-btn {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font: 700 24px/1 monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  padding: 0;
}

.rotate-btn:hover {
  filter: brightness(1.14);
}

.rotate-btn:focus-visible {
  filter: brightness(1.14);
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.rotate-btn:active {
  filter: brightness(1.3);
  transform: scale(0.96);
}

.rotate-btn.ccw {
  background: #2a4d7a;
  left: 8px;
  top: 50px;
  box-shadow:
    inset -3px -3px 0 rgba(0, 0, 0, 0.25),
    2px 2px 0 rgba(0, 0, 0, 0.4);
}

.rotate-btn.cw {
  background: #7a1f3d;
  left: 70px;
  top: 10px;
  box-shadow:
    inset -3px -3px 0 rgba(0, 0, 0, 0.25),
    2px 2px 0 rgba(0, 0, 0, 0.4);
}

/* ── Cluster labels ───────────────────────────────────────────── */

.cluster-label {
  font: 700 8px/1.4 monospace;
  color: var(--text-dim);
  text-align: center;
  margin: 0;
  max-width: 130px;
}

.accent-text {
  color: var(--accent);
}

/* ── Mobile ───────────────────────────────────────────────────── */

@media (max-width: 520px) {
  body {
    min-height: 100svh;
    overflow: hidden;
  }

  .game-shell {
    height: 100svh;
    min-height: 0;
    padding: 6px 6px 0;
    gap: 4px;
    overflow: hidden;
  }

  .topbar {
    border-radius: 16px;
    padding: 6px 10px;
  }

  .title {
    font-size: 19px;
  }

  #restart {
    padding: 8px 12px;
    font-size: 13px;
  }

  .control-deck {
    padding: 8px 10px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-radius: 0 0 16px 16px;
  }

  .dpad {
    width: 110px;
    height: 110px;
  }

  .dpad-v-bar {
    left: 37px;
    width: 37px;
    height: 110px;
  }

  .dpad-h-bar {
    top: 37px;
    width: 110px;
    height: 37px;
  }

  .dpad-btn {
    width: 37px;
    height: 37px;
    font-size: 14px;
  }

  .dpad-up {
    left: 37px;
  }

  .dpad-left {
    top: 37px;
  }

  .dpad-right {
    top: 37px;
    left: 73px;
  }

  .dpad-down {
    top: 73px;
    left: 37px;
  }

  .rotate-cluster {
    width: 120px;
    height: 110px;
  }

  .rotate-btn {
    width: 50px;
    height: 50px;
    font-size: 22px;
  }

  .rotate-btn.ccw {
    left: 6px;
    top: 46px;
  }

  .rotate-btn.cw {
    left: 64px;
    top: 8px;
  }
}
