:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #172033;
  --text: #e2e8f0;
  --muted: #64748b;
  --line: #334155;
  --accent: #2dd4bf;
  --focus-ring: rgba(45, 212, 191, 0.55);
  --radius: 16px;
  --beat: 620ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

body {
  display: flex;
  justify-content: center;
  background: radial-gradient(120% 90% at 50% -10%, #16233f 0%, var(--bg) 55%);
}

.app {
  width: 100%;
  max-width: 720px;
  padding: clamp(0.75rem, 3vw, 1.75rem);
  padding-top: max(clamp(0.75rem, 3vw, 1.75rem), env(safe-area-inset-top));
  padding-bottom: max(clamp(0.75rem, 3vw, 1.75rem), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(0.75rem, 2.5vw, 1.25rem);
  min-height: 100dvh;
}

/* ---- header ---- */
.topbar {
  text-align: center;
  position: relative;
}
.title {
  margin: 0;
  font-size: clamp(1.4rem, 6vw, 2rem);
  letter-spacing: 0.04em;
  font-weight: 800;
  background: linear-gradient(90deg, #2dd4bf, #a3e635);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: clamp(0.8rem, 3.4vw, 0.95rem);
}
.kind-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  color: #cbd5e1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* ---- board / stage ---- */
.board {
  flex: 1 1 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 4vw, 2rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 4vw, 2rem);
  min-height: min(46dvh, 340px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(0.3rem, 1.6vw, 0.6rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-height: 1.2em;
}

.token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 12vw, 4rem);
  font-weight: 800;
  padding: 0.12em 0.24em;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid transparent;
  will-change: transform, opacity;
}
.token--bare {
  background: transparent;
  padding: 0.12em 0.08em;
  font-weight: 600;
}
.token--focus {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 16%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 22%, transparent);
}

.caption {
  margin: 0;
  text-align: center;
  color: #cbd5e1;
  font-size: clamp(0.95rem, 4vw, 1.2rem);
  font-weight: 600;
  min-height: 1.4em;
  letter-spacing: 0.02em;
}

/* ---- hud ---- */
.hud {
  display: flex;
  justify-content: center;
  gap: clamp(0.75rem, 4vw, 2rem);
}
.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}
.hud-label {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.hud-value {
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}
.ctrl {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  min-height: 44px; /* タッチターゲット */
}
.ctrl:hover {
  background: #24324a;
}
.ctrl:active {
  transform: translateY(1px);
}
.ctrl:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.ctrl[aria-pressed="true"] {
  border-color: var(--accent);
  color: #ccfbf1;
}

/* ---- footer ---- */
.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}
.foot kbd {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0.05rem 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}

/* ---- a11y helpers ---- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* reduced-motion: 動きを抑える (拍は維持、視覚のみ穏やかに)。 */
@media (prefers-reduced-motion: reduce) {
  .ctrl {
    transition: none;
  }
  .token {
    will-change: opacity;
  }
}

/* 横長・大画面では数字をより大きく */
@media (min-width: 560px) {
  .board {
    min-height: 360px;
  }
}
