:root {
  --bg1: #1b1440;
  --bg2: #6b2f7a;
  --panel: rgba(255, 255, 255, 0.12);
  --text: #fbf6ff;
  --muted: #e2d4ff;
  --accent: #ffb938;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: linear-gradient(170deg, var(--bg1), var(--bg2));
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  /* ダブルタップ拡大・テキスト選択・長押しメニューを無効化 */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ---- ボタン ---- */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font: inherit;
  font-size: 16px;
  font-weight: bold;
  color: var(--text);
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.btn.primary {
  background: var(--accent);
  color: #3a2500;
}

.btn.big {
  font-size: 22px;
  padding: 14px 56px;
}

.btn.icon {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 18px;
  flex: none;
}

/* ---- タイトル ---- */
.title-screen {
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  text-align: center;
  overflow-y: auto;
}

.title-chara {
  display: block;
  width: 150px;
  height: 170px;
  margin: 0 auto;
}

.title-screen h1 {
  margin: 6px 0 6px;
  font-size: clamp(32px, 10vw, 46px);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.title-screen .sub {
  margin: 0;
  color: var(--muted);
}

.scores {
  width: 100%;
  max-width: 340px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel);
}

.scores h2 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--accent);
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

.score-list li {
  display: grid;
  grid-template-columns: 2.6em 1fr 4em 6.6em;
  align-items: baseline;
  gap: 6px;
  padding: 4px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.score-list li:first-child {
  border-top: none;
}

.score-list li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
}

.score-list .pts {
  font-weight: bold;
  text-align: right;
}

.score-list .dist {
  text-align: right;
}

.score-list .date,
.score-list .rank {
  color: var(--muted);
  font-size: 12px;
}

.score-list .date {
  text-align: right;
}

.back-link {
  color: var(--muted);
  font-size: 14px;
}

/* ---- ゲーム画面 ---- */
.stage {
  position: relative;
  flex: 1;
  touch-action: none;
  cursor: pointer;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 0;
  pointer-events: none;
}

.hud .btn {
  pointer-events: auto;
}

.stat {
  flex: 1.4;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 6px;
  border-radius: 12px;
  background: var(--panel);
}

.stat.small {
  flex: 1;
}

.stat .value {
  font-size: 20px;
  font-weight: bold;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.label {
  font-size: 10px;
  color: var(--muted);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(30, 15, 60, 0.6);
  font-size: 15px;
  line-height: 1.7;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.hint b {
  color: var(--accent);
}

/* ---- 重ねて表示する画面 ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 10, 40, 0.6);
  animation: fadein 0.2s ease-out;
}

.overlay.clear {
  background: rgba(20, 10, 40, 0.25);
  pointer-events: none;
}

.countdown {
  font-size: 120px;
  font-weight: bold;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
}

.card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px;
  border-radius: 20px;
  background: #4a2f86;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
  animation: popin 0.3s cubic-bezier(0.3, 1.4, 0.6, 1);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 26px;
}

.rank-msg {
  color: var(--accent);
  font-weight: bold;
  font-size: 20px;
}

.result {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 6px 16px;
  margin: 12px 0 20px;
  text-align: left;
}

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

.result dd {
  margin: 0;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.card-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- アニメーション ---- */
@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popin {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
