:root {
  color-scheme: dark;
  --bg: #03050f;
  --card: rgba(14, 19, 44, 0.86);
  --line: rgba(140, 170, 255, 0.22);
  --text: #f2f4ff;
  --muted: #a4acd8;
  --accent: #5ee6c2;
  --you: #4da3ff;
  --ans: #ff5b7f;
  --gold: #ffd95e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#globe { position: fixed; inset: 0; touch-action: none; }
#globe canvas { display: block; }

.hidden { display: none !important; }

button {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  color: #04121a;
  background: var(--accent);
  transition: transform 0.1s, opacity 0.2s;
}
button:active { transform: scale(0.97); }
button { touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }
button.ghost { background: rgba(255, 255, 255, 0.1); color: var(--text); box-shadow: 0 0 0 1px var(--line) inset; }

/* --- HUD --- */
.hud {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px #000;
}
.timer {
  position: relative;
  min-width: 84px;
  padding: 2px 10px 6px;
  text-align: center;
  font-weight: 700;
}
.timer i {
  position: absolute;
  left: 10px;
  bottom: 0;
  height: 3px;
  width: calc(100% - 20px);
  border-radius: 2px;
  background: var(--accent);
  transform-origin: left;
}
.timer.warn { color: var(--ans); }
.timer.warn i { background: var(--ans); }
.hud { padding-right: 48px; }
.sound-btn {
  position: fixed;
  top: calc(6px + env(safe-area-inset-top, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  z-index: 5;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  background: rgba(14, 19, 44, 0.7);
  box-shadow: 0 0 0 1px var(--line) inset;
}
.hud .total strong { color: var(--gold); font-size: 20px; }

.card {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 18px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.question { top: calc(44px + env(safe-area-inset-top, 0px)); }
.question { text-align: center; }
.question h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.question .q-hint { margin: 6px 0 0; color: var(--gold); font-size: 14px; }

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(94, 230, 194, 0.18);
  color: var(--accent);
}
.tag.game { background: rgba(255, 217, 94, 0.18); color: var(--gold); }

.result { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
.result-head { display: flex; align-items: baseline; gap: 4px; }
.result .points { font-size: 34px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.result .unit { font-weight: 700; }
.result .distance { margin-left: auto; color: var(--muted); }
.result .r-answer { margin: 4px 0; font-weight: 700; }
.result .r-note { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.r-photo { margin: 8px 0 6px; }
.r-photo img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: clamp(90px, 18vh, 170px);
  object-fit: cover;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}
.r-photo figcaption { margin-top: 3px; font-size: 10px; line-height: 1.4; color: var(--muted); }
.r-photo figcaption a { color: inherit; text-decoration: none; }
.r-photo figcaption a:hover { text-decoration: underline; }

.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.you { background: var(--you); }
.dot.ans { background: var(--ans); margin-left: 10px; }

.actions {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: center;
  gap: 10px;
}
.actions button { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4); }

/* --- スタート・結果画面 --- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at center, rgba(3, 5, 15, 0.2), rgba(3, 5, 15, 0.75));
}

.panel {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 34px;
  background: linear-gradient(90deg, var(--accent), var(--you), var(--ans));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lead { margin: 0 0 18px; color: var(--muted); line-height: 1.6; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: 14px;
  padding: 14px 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--line) inset;
}
.mode b { font-size: 17px; }
.mode small { color: var(--muted); font-weight: 500; }
.mode:hover { background: rgba(94, 230, 194, 0.16); }

.settings { margin: 16px 0 0; display: flex; flex-direction: column; gap: 10px; }
.setting { display: flex; align-items: center; gap: 10px; }
.setting-label { width: 64px; flex-shrink: 0; text-align: left; font-size: 13px; color: var(--muted); }
.seg { flex: 1; display: flex; padding: 3px; gap: 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); box-shadow: 0 0 0 1px var(--line) inset; }
.seg button { flex: 1; padding: 7px 2px; font-size: 13px; white-space: nowrap; background: transparent; color: var(--muted); }
.seg button.on { background: var(--accent); color: #04121a; }

/* 今週のチャレンジ・オンライン対戦 */
.online-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.online-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-radius: 14px;
  padding: 12px 8px;
  background: linear-gradient(135deg, rgba(255, 217, 94, 0.18), rgba(255, 91, 127, 0.14));
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(255, 217, 94, 0.35) inset;
}
.online-btn b { font-size: 15px; }
.online-btn small { color: var(--muted); font-weight: 500; font-size: 11px; }

.records-btn { width: 100%; margin-top: 10px; padding: 10px; font-size: 14px; }
.records-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 6px; }
.records-summary .stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); }
.records-summary strong { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }
.records-summary span { font-size: 11px; color: var(--muted); }
.end-actions { flex-wrap: wrap; }
#records-best .t, #records-list .t { white-space: normal; line-height: 1.4; }
#records .end-actions { margin-top: 16px; }

.panel h2.sub { margin: 18px 0 6px; font-size: 15px; text-align: left; color: var(--gold); }
.weekly-status { margin: 8px 0 12px; font-size: 14px; color: var(--text); }
.end-note { margin: 6px 0 0; font-size: 14px; font-weight: 700; color: var(--accent); }
.end-extra { margin: 0 0 12px; }
.online-error { margin: 10px 0 0; color: var(--ans); font-size: 14px; }

.rank-list { margin: 0; padding: 0; list-style: none; text-align: left; font-size: 14px; }
.rank-list li { display: flex; gap: 10px; align-items: baseline; padding: 7px 6px; border-bottom: 1px solid var(--line); }
.rank-list li.me { background: rgba(94, 230, 194, 0.12); border-radius: 8px; }
.rank-list .n { width: 26px; text-align: center; font-variant-numeric: tabular-nums; }
.rank-list .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .d { color: var(--muted); white-space: nowrap; }
.rank-list .p { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.cpu-box { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; padding: 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); box-shadow: 0 0 0 1px var(--line) inset; }
.cpu-box .setting-label { width: 76px; }

.random-box { margin-top: 12px; padding: 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); box-shadow: 0 0 0 1px var(--line) inset; }

.join-row { display: flex; gap: 8px; margin-top: 14px; }
.join-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.join-row input::placeholder { letter-spacing: normal; font-size: 14px; }
.room-code { margin: 4px 0; font-size: 16px; }
.room-code strong { font-size: 34px; letter-spacing: 0.15em; color: var(--gold); margin-left: 6px; font-variant-numeric: tabular-nums; }

.live-board {
  position: fixed;
  top: calc(118px + env(safe-area-inset-top, 0px));
  left: max(12px, env(safe-area-inset-left, 0px));
  z-index: 2;
  min-width: 150px;
  max-width: 46vw;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(14, 19, 44, 0.78);
  border: 1px solid var(--line);
  font-size: 12px;
  pointer-events: none;
}
.live-row { display: flex; gap: 8px; justify-content: space-between; padding: 2px 0; }
.live-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-row .p { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.live-row.me .t { color: var(--accent); font-weight: 700; }

.legal-links { margin: 10px 0 0; font-size: 11px; color: var(--muted); }
.legal-links a { color: var(--muted); }

.howto { margin: 18px 0 0; font-size: 13px; color: var(--muted); line-height: 1.8; }

.final { margin: 4px 0; font-size: 18px; }
.final strong { font-size: 48px; color: var(--gold); font-variant-numeric: tabular-nums; }
.rank { margin: 0 0 4px; font-weight: 700; font-size: 18px; }
.best { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

.final-list {
  text-align: left;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  font-size: 14px;
}
.final-list li {
  display: flex;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
}
.final-list .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.final-list .d { color: var(--muted); white-space: nowrap; }
.final-list .p { width: 52px; text-align: right; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }

.end-actions { display: flex; gap: 10px; justify-content: center; }

.music-hint {
  margin: -8px 0 16px;
  font-size: 13px;
  color: var(--gold);
  animation: hint-blink 1.6s ease-in-out infinite;
}
@keyframes hint-blink { 50% { opacity: 0.45; } }

/* クラッカーの紙吹雪 */
.fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }

/* ダメなときの ✕ マーク */
.batsu {
  position: fixed;
  left: 50%;
  top: 34%;
  z-index: 3;
  width: min(62vw, 300px);
  aspect-ratio: 1;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
}
.batsu::before,
.batsu::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 118%;
  height: 17%;
  border-radius: 999px;
  background: var(--ans);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.92), 0 10px 30px rgba(0, 0, 0, 0.45);
}
.batsu::before { transform: translate(-50%, -50%) rotate(45deg); }
.batsu::after { transform: translate(-50%, -50%) rotate(-45deg); }
.batsu.show { animation: batsu-stamp 1.7s ease-out forwards; }
@keyframes batsu-stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(0.92); }
  18% { transform: translate(-50%, -50%) scale(1.04) rotate(-3deg); }
  24% { transform: translate(-50%, -50%) scale(1) rotate(3deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  80% { opacity: 0.95; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* 答え合わせのほめ言葉 */
.callout {
  position: fixed;
  left: 50%;
  top: 34%;
  z-index: 4;
  pointer-events: none;
  font-family: "Lilita One", "Arial Black", system-ui, sans-serif;
  font-size: clamp(42px, 13vw, 76px);
  font-weight: 400;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--gold);
  -webkit-text-stroke: 2px #1a1030;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #1a1030, 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
}
.callout.best { color: var(--gold); }
.callout.good { color: var(--accent); }
.callout.ok { color: var(--you); }
.callout.bad { color: var(--ans); }
.callout.show { animation: callout-pop 1.6s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
@keyframes callout-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-8deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(3deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  80% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(0.95); }
}
@keyframes callout-fade {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%); }
  15%, 80% { opacity: 1; transform: translate(-50%, -50%); }
}
@media (prefers-reduced-motion: reduce) {
  .callout.show { animation-name: callout-fade; animation-timing-function: ease; }
  .batsu.show { animation-name: callout-fade; }
  .music-hint { animation: none; }
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  z-index: 10;
}

/* 横長の画面（スマホの横向き・パソコン）：答え合わせのカードは右側に出し、左側で地球を見せる */
@media (orientation: landscape) and (min-width: 700px) {
  .result {
    left: auto;
    right: max(16px, env(safe-area-inset-right, 0px));
    transform: none;
    width: min(400px, 44vw);
    top: calc(48px + env(safe-area-inset-top, 0px));
    bottom: auto;
    max-height: calc(100% - 48px - 76px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
  }
  .r-photo img { height: clamp(70px, 26vh, 210px); }
}

@media (max-width: 480px) {
  .question h2 { font-size: 18px; }
  .actions button { padding: 12px 16px; font-size: 14px; }
  .result .points { font-size: 28px; }
}
