:root {
  --bg: #06101f;
  --panel: rgba(18, 26, 60, 0.82);
  --panel-border: rgba(140, 170, 255, 0.25);
  --text: #f2f5ff;
  --muted: #9fb0dd;
  --accent: #ffd23a;
  --accent-2: #ff5fc1;
  --button: linear-gradient(180deg, #5b7cff, #3048c8);
  --button-2: rgba(255, 255, 255, 0.08);
  --danger: #ff6a3d;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang TC', 'Noto Sans TC', 'Hiragino Sans', 'Microsoft JhengHei', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

/* ---------- HUD：原版那條深藍橫幅 ---------- */

/* 橫幅與下方按鈕列都和盤面同寬（--board-w 由程式依盤面實際寬度設定） */
#hud,
#controls {
  width: min(calc(100% - 24px), var(--board-w, 640px));
  margin: 0 auto;
}

#hud {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, #2b4fb8, #132a78);
  border: 2px solid #8fc0ff;
  box-shadow: 0 6px 18px rgba(20, 50, 120, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 6px 8px 8px;
}

.stat + .stat {
  border-left: 1px solid rgba(160, 200, 255, 0.35);
}

.stat .label {
  font-size: 12px;
  font-weight: 700;
  color: #bcd8ff;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.stat .value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

/* ---------- 舞台 ---------- */

/* 3D 畫面鋪滿整個視窗，分數列與按鈕列浮在上面 */
#stage {
  position: absolute;
  inset: 0;
}

#play-area {
  flex: 1;
  min-height: 0;
  pointer-events: none;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5), 0 0 12px rgba(255, 210, 58, 0.8);
  animation: float-up 1s ease-out forwards;
  white-space: nowrap;
}

.float.big {
  font-size: 30px;
  color: var(--accent);
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.6);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -220%) scale(1);
  }
}

#callout {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  width: min(90vw, 640px);
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 900;
  background: linear-gradient(180deg, #fff6c2, var(--accent) 50%, #ff8a1f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* 淺色背景上要有深藍外框才看得清楚 */
  filter: drop-shadow(0 3px 0 #1d3a9e) drop-shadow(0 0 3px #1d3a9e) drop-shadow(0 0 12px rgba(29, 58, 158, 0.45));
  opacity: 0;
}

#callout small {
  display: block;
  margin-top: 6px;
  font-size: max(14px, 0.36em);
  font-weight: 700;
  -webkit-text-fill-color: #fff;
  white-space: normal;
}

#callout.show {
  animation: callout 1.3s ease-out forwards;
}

@keyframes callout {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.4);
  }
  15% {
    opacity: 1;
    transform: translateX(-50%) scale(1.12);
  }
  25% {
    transform: translateX(-50%) scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
}

/* ---------- 下方按鈕列：左提示、右切換方向 ---------- */

#controls {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 14px;
}

button.round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 24px;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 12px rgba(20, 50, 120, 0.25);
}

button.round:hover {
  background: rgba(255, 255, 255, 0.8);
}

/* 中間的「選單」：原版那種藍色膠囊按鈕 */
button.pill {
  min-width: 132px;
  padding: 12px 28px;
  border-radius: 99px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, #4f86ff, #1f4fc8);
  border: 2px solid #9cc6ff;
  box-shadow: 0 4px 0 #173b95, 0 8px 18px rgba(20, 50, 120, 0.35);
}

button.pill:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #173b95;
}

button.spin {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  font-size: 38px;
  line-height: 1;
  /* 原版的旋轉方向鍵是黃色大箭頭 */
  color: #1d3a9e;
  font-weight: 900;
  background: radial-gradient(circle at 35% 30%, #fff3a8, #ffcf2e 55%, #f0a000);
  border: 2px solid #fff6c8;
  box-shadow: 0 6px 0 #b86f00, 0 10px 24px rgba(20, 50, 120, 0.35);
  touch-action: manipulation;
}

button.spin:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b86f00;
}

/* 滑鼠操作時按鈕不用那麼大 */
@media (pointer: fine) {
  button.spin {
    width: 60px;
    height: 60px;
    font-size: 30px;
  }
  button.round {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

/* ---------- 畫面（選單、說明、設定…） ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 8, 22, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.panel {
  width: min(420px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.panel.scroll {
  overflow-y: auto;
  user-select: text;
}

.panel h2 {
  margin: 0 0 4px;
  text-align: center;
}

.panel > button,
.row > button,
button.mode {
  padding: 13px 16px;
  border-radius: 14px;
  background: var(--button);
  font-weight: 700;
  font-size: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.panel > button:hover,
.row > button:hover,
button.mode:hover {
  filter: brightness(1.12);
}

button.secondary {
  background: var(--button-2);
  box-shadow: none;
}

.row {
  display: flex;
  gap: 10px;
}

.row > button {
  flex: 1;
}

.title-panel {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 10vw, 52px);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff, #ffd23a 45%, #ff5fc1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(60, 20, 90, 0.8));
}

.subtitle {
  margin: 0 0 8px;
  color: var(--muted);
  letter-spacing: 0.3em;
}

button.mode {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

button.mode b {
  font-size: 19px;
}

button.mode small {
  font-weight: 400;
  opacity: 0.85;
}

button.mode.bomb {
  background: linear-gradient(180deg, #ff7a4d, #c8322a);
}

.best-line {
  font-size: 12px;
  font-weight: 600;
  color: #fff3b0;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.setting-note {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.setting select,
button.toggle {
  min-width: 140px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
}

.setting select option {
  background: #18204a;
}

button.toggle[aria-pressed='true'] {
  background: linear-gradient(180deg, #45d16a, #229544);
}

.howto h3 {
  margin: 14px 0 4px;
  font-size: 16px;
  color: var(--accent);
}

.howto p {
  margin: 0 0 6px;
  line-height: 1.6;
  color: #dbe3ff;
}

.reason {
  margin: 0;
  text-align: center;
  color: var(--muted);
}

.big-score {
  text-align: center;
  font-size: 48px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.newbest {
  margin: -6px 0 0;
  text-align: center;
  font-weight: 800;
  color: var(--accent-2);
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    transform: scale(1.1);
  }
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin: 4px 0 8px;
  font-size: 14px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 520px) {
  .stat {
    padding: 5px 4px 6px;
  }
  .stat .label {
    font-size: 11px;
  }
  .stat .value {
    font-size: 18px;
  }
}
