/* ===== 色 ===== */
:root {
  /* SVG のキャラ（2D版）用 */
  --line: #3a2630;
  --eye: #ffffff;
  --hair: #6b3a2a;
  --bf-hair: #2e2a36;
  --dress: #ff7fa8;
  --shirt: #5aa9e6;
  --blush: #ff9db5;
  --heart: #ff4d7d;
  --sweat: #8fd3ff;
  --shock: #5b5bd6;
  --puff: #ffffff;
  --skin-0: #ffe0c8;
  --skin-1: #ffe0c8;
  --skin-2: #dfe8b0;
  --skin-3: #bfe08f;
  --skin-4: #9bd16f;
  --skin-5: #82c45c;
  --skin-6: #6fb94e;
  --frog-belly: #eaf7c9;
  --frog-dark: #3f7f2c;

  /* 画面 */
  --ink: #2b1b24;
  --paper: #ffffff;
  --panel-top: #fff6fa;
  --panel-bottom: #ffe3ee;
  --accent: #ff4d7d;
  --tag-a: #ff6f91;
  --tag-b: #4aa8ff;
  --ok: #2fb866;
  --ok-bg: #eafff1;
  --ng: #8d8a99;
  --ng-bg: #eeeef2;
  --ng-text: #77737f;
  --timer: #ffc93d;
  --timer-low: #ff4d4d;
  --x: #111111;
  --panel-max: 1100px; /* パネルの中身の最大幅 */
  --font: "M PLUS Rounded 1c", system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  background: #1d1420;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* 素早いタップで画面が拡大されないように */
  overflow: hidden;
}

.app {
  position: relative;
  /* 3Dの街は画面いっぱい。パネルの中身だけ読みやすい幅にする（.screen の max-width） */
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 52fr 48fr;
}

/* ===== シーン（上） ===== */
.scene { position: relative; overflow: hidden; min-height: 0; background: #8fd3ff; }
.scene-canvas { display: block; width: 100%; height: 100%; }
.scene-loading {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--paper);
  font-size: 20px;
  text-shadow: 0 2px 0 var(--ink);
}
.hud {
  position: absolute;
  z-index: 3;
  top: max(8px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.q-dots {
  display: flex;
  gap: 2px;
  margin: 0;
  padding: 4px 6px;
  list-style: none;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
}
.q-dots li {
  width: clamp(17px, 5vw, 24px);
  height: clamp(17px, 5vw, 24px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  background: #f1e6ec;
}
.q-dots li.is-current { background: var(--accent); color: var(--paper); transform: scale(1.12); }
.q-dots li.is-correct { background: var(--ok); color: var(--paper); }
.q-dots li.is-wrong { background: var(--ng); color: var(--paper); }
.q-level {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  white-space: nowrap;
}
.mute {
  margin-left: auto;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  font-size: 17px;
  cursor: pointer;
}
.q-level:not([hidden]) + .mute { margin-left: 0; }

/* 音量パネル（右上のボタンで開く） */
.sound-panel {
  position: absolute;
  z-index: 4;
  top: calc(max(8px, env(safe-area-inset-top)) + 46px);
  right: max(10px, env(safe-area-inset-right));
  width: min(280px, calc(100% - 20px));
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
}
.vol-row { display: grid; grid-template-columns: 4em 1fr 3.2em; align-items: center; gap: 8px; font-size: 15px; }
.vol-row input { width: 100%; height: 28px; accent-color: var(--accent); cursor: pointer; }
.vol-row output { text-align: right; font-size: 14px; }
.sound-panel .btn-mute { font-size: 15px; padding: 8px 14px; background: var(--ink); box-shadow: 0 4px 0 #000; }

/* 吹き出し（シーンがキャラの頭の上に置く） */
.scene-bubble {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -100%);
  padding: 7px 12px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  font-size: clamp(13px, 3.6vw, 17px);
  white-space: nowrap;
  pointer-events: none;
}
.scene-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  transform: translateX(-50%);
  border: 9px solid transparent;
  border-top-color: var(--ink);
  border-bottom: 0;
}

/* ===== パネル（下） ===== */
.panel {
  min-height: 0;
  background: linear-gradient(var(--panel-top), var(--panel-bottom));
  border-top: 4px solid var(--ink);
  padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.screen {
  width: 100%;
  max-width: var(--panel-max);
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 10px;
  overflow-y: auto;
  text-align: center;
}
.screen-question { justify-content: stretch; align-items: stretch; overflow: hidden; gap: 8px; }

.btn {
  font: inherit;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  color: var(--paper);
  background: var(--accent);
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .card:focus-visible, .mute:focus-visible { outline: 4px solid var(--timer); outline-offset: 3px; }
.btn-primary { font-size: 22px; min-width: 200px; }
.btn-link { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink); text-decoration: underline; font-size: 15px; padding: 6px 12px; }
.btn-share { background: var(--x); font-size: 18px; min-width: 200px; }

/* タイトル */
.logo { margin: 0; display: flex; flex-direction: column; line-height: 1.2; }
.logo-sub { font-size: clamp(17px, 4.6vw, 30px); }
.logo-main { font-size: clamp(38px, 11vw, 72px); color: var(--accent); text-shadow: 0 4px 0 var(--ink); -webkit-text-stroke: 1px var(--ink); }
.lead { margin: 0; font-size: 17px; }

/* 難易度 */
.heading { margin: 0; font-size: clamp(24px, 6.4vw, 38px); }
.diff-list { display: flex; flex-direction: column; gap: 12px; width: min(100%, 440px); }
.btn-diff { display: flex; flex-direction: column; align-items: center; border-radius: 18px; padding: 10px 16px; }
.diff-name { font-size: 22px; }
.diff-sub { font-size: 14px; }
.btn-diff[data-difficulty="intermediate"] { background: #e8742a; }
.btn-diff[data-difficulty="advanced"] { background: #6a3ad6; }

/* 問題 */
.q-prompt { margin: 0; font-size: 17px; }
.cards { flex: 1; min-height: 0; display: grid; grid-template-rows: 1fr 1fr; gap: 10px; }
.card {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: stretch;
  padding: 8px 14px 8px 54px;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--ink);
  opacity: 0;
  transform: translateY(8px);
}
.card:disabled { cursor: default; }
.card.is-in { opacity: 1; transform: none; transition: opacity 0.2s, transform 0.2s; }
.card-tag {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper);
  font-size: 18px;
  border: 3px solid var(--ink);
}
#card-0 .card-tag { background: var(--tag-a); }
#card-1 .card-tag { background: var(--tag-b); }
.card-text { flex: 1; min-width: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.fit {
  display: block;
  text-align: center;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: normal;
  word-break: auto-phrase; /* 日本語を文節で折り返す（対応ブラウザのみ） */
  text-wrap: balance;
}
.card-verdict {
  position: absolute;
  right: 10px;
  top: -14px;
  padding: 2px 12px;
  border-radius: 999px;
  color: var(--paper);
  border: 3px solid var(--ink);
  font-size: 15px;
  display: none;
}
.card.is-real { background: var(--ok-bg); }
.card.is-real .card-verdict { display: block; background: var(--ok); }
.card.is-fake { background: var(--ng-bg); color: var(--ng-text); }
.card.is-fake .card-verdict { display: block; background: var(--ng); }
.card.is-picked { box-shadow: 0 0 0 4px var(--timer), 0 5px 0 var(--ink); }
.timer { height: 14px; border: 3px solid var(--ink); border-radius: 999px; background: var(--paper); overflow: hidden; flex: 0 0 auto; }
.timer-bar { height: 100%; width: 100%; background: var(--timer); transform-origin: left center; }
.timer-bar.is-low { background: var(--timer-low); }

/* 結果 */
.r-level { margin: 0; font-size: 17px; }
.r-percent { margin: 0; font-size: 18px; }
.r-percent strong { display: block; font-size: clamp(44px, 13vw, 84px); line-height: 1.05; color: var(--accent); text-shadow: 0 4px 0 var(--ink); }
.r-title { margin: 0; font-size: clamp(24px, 7vw, 44px); }
.r-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  .card.is-in { transition: opacity 0.2s; transform: none; }
}

/* ===== 横長の画面 ===== */
@media (min-aspect-ratio: 1/1) {
  .app { grid-template-rows: 64fr 36fr; }
  .cards { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .r-actions { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .diff-list { flex-direction: row; width: min(100%, 820px); }
  .btn-diff { flex: 1; }
  .screen-title { flex-direction: row; flex-wrap: wrap; justify-content: center; column-gap: 28px; }
  .screen-title .logo { align-items: center; }
}
/* 高さが足りない横長の画面（スマホの横向きなど）：パネルの中身を詰める */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .app { grid-template-rows: 54fr 46fr; }
  .screen-question .q-prompt { display: none; } /* 通行人の吹き出しが同じことを言う */
  .panel { padding-top: 6px; }
  .screen { gap: 6px; }
  .logo-sub { font-size: 16px; }
  .logo-main { font-size: clamp(28px, 9dvh, 48px); }
  .lead { font-size: 14px; }
  .heading { font-size: 20px; }
  .btn-diff { padding: 6px 8px; }
  .diff-name { font-size: 17px; }
  .diff-sub { font-size: 12px; }
  .btn-primary, .btn-share { font-size: 16px; min-width: 0; padding: 8px 18px; }
  .q-prompt { font-size: 14px; }
  .r-percent strong { font-size: clamp(30px, 11dvh, 56px); }
  .r-title { font-size: 22px; }
  .r-level, .r-percent { font-size: 14px; }
}

/* ===== SVG のキャラ（2D版） ===== */
.chara { display: block; width: 100%; height: auto; overflow: visible; }
