/* ==================== 四択王 - style.css ==================== */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e5ea;
  --primary: #2563EB;
  --primary-dark: #1d4ed8;
  --danger: #DC2626;
  --ok: #16A34A;
  --warn: #D97706;
  --choice-bg: #ffffff;
  --choice-border: #d7dbe2;
  --overlay-bg: rgba(15, 18, 26, 0.55);
  --question-bg: #FEF9C3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --panel: #1d212b;
    --text: #eef0f4;
    --muted: #9aa2b1;
    --border: #2c313d;
    --primary: #5b8bf0;
    --primary-dark: #7ea2f4;
    --choice-bg: #242834;
    --choice-border: #383e4d;
    --overlay-bg: rgba(0, 0, 0, 0.65);
    --question-bg: #3d3620;
  }
  .genre-card, .q-header__genre { filter: brightness(1.18) saturate(1.05); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
}

#app { min-height: 100dvh; }

button { font-family: inherit; }
/* タップ/クリック後に輪郭が残らないようにし、キーボード操作時だけフォーカスリングを出す */
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-large { padding: 14px 40px; font-size: 1.15rem; }
.link-button {
  background: none; border: none; color: var(--muted); text-decoration: underline;
  cursor: pointer; font-size: .85rem; padding: 4px;
}

.sound-toggle {
  background: none; border: none; font-size: 1.4rem; cursor: pointer;
  line-height: 1; padding: 6px;
}

.simple-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}

/* ---------------- タイトル画面 ---------------- */

/* 背景にうっすら4色のにじみを置き、ゲームの入口らしい雰囲気を出す（文字の読みやすさを損なわない淡さに抑える） */
.title-screen {
  background:
    radial-gradient(circle at 15% 20%, color-mix(in srgb, #2563EB 14%, transparent), transparent 40%),
    radial-gradient(circle at 85% 25%, color-mix(in srgb, #16A34A 12%, transparent), transparent 40%),
    radial-gradient(circle at 20% 85%, color-mix(in srgb, #D97706 12%, transparent), transparent 40%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, #DC2626 12%, transparent), transparent 40%),
    var(--bg);
}
.title-screen__top { display: flex; justify-content: flex-end; padding: 12px 16px; }
.title-screen__body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 20px max(32px, env(safe-area-inset-bottom)); gap: 24px;
}
.title-screen__hero, .title-screen__main { display: flex; flex-direction: column; align-items: center; }
.title-screen__main { gap: 16px; width: 100%; max-width: 420px; }

/* 選択肢の①〜④を4色のタイルにしたロゴ（「四択」を表す） */
.title-logo { display: flex; gap: clamp(6px, 1.5vmin, 12px); margin-bottom: 10px; }
.title-logo__tile {
  display: grid; place-items: center;
  width: clamp(40px, 9vmin, 72px); aspect-ratio: 1;
  border-radius: 22%;
  color: #fff; font-weight: 800; font-size: clamp(1.3rem, 4.5vmin, 2.3rem);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .15);
  transform: rotate(-6deg);
}
.title-logo__tile:nth-child(1) { background: #2563EB; }
.title-logo__tile:nth-child(2) { background: #16A34A; transform: rotate(4deg) translateY(-4px); }
.title-logo__tile:nth-child(3) { background: #D97706; transform: rotate(-3deg) translateY(2px); }
.title-logo__tile:nth-child(4) { background: #DC2626; transform: rotate(6deg); }

.title-screen__title {
  /* 幅と高さの小さいほうに合わせ、スマホでも大画面でも画面に対して同じくらいの存在感にする */
  font-size: clamp(3rem, min(16vw, 13vh), 7.5rem);
  font-weight: 900;
  letter-spacing: .12em;
  line-height: 1.1;
  margin: 0 0 4px .12em;
}
.title-screen__subtitle { margin: 0; color: var(--muted); font-size: clamp(1rem, 2.4vmin, 1.25rem); letter-spacing: .2em; }
.title-screen__lead { margin: 0; color: var(--text); font-size: .95rem; line-height: 1.7; text-wrap: balance; }

/* スマホでは親指で押しやすいよう横幅いっぱい・高めのボタンにする */
.title-screen__start { width: 100%; max-width: 320px; padding: 16px 24px; font-size: 1.3rem; font-weight: 700; border-radius: 12px; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent); }
.title-screen__start:disabled { box-shadow: none; }

.title-screen__warning {
  margin: 0; padding: 10px 14px; border-radius: 8px;
  background: #FEE2E2; color: #991B1B; font-size: .9rem; line-height: 1.6;
}

/* プレイ記録：3つの数値を横に並べ、ひと目で読めるようにする */
.title-record {
  width: 100%; padding: 14px 16px 10px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel);
}
.title-record__badge {
  margin: 0 0 10px; padding: 4px 10px; display: inline-block;
  border-radius: 999px; background: #FEF3C7; color: #92400E; font-weight: 700; font-size: .85rem;
}
.title-record__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.title-record__stats div { display: flex; flex-direction: column-reverse; gap: 2px; }
.title-record__stats dt { font-size: .75rem; color: var(--muted); }
.title-record__stats dd { margin: 0; font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.title-record .link-button { margin-top: 6px; }

/* 高さの低い横長画面（スマホ横向き・小さいウィンドウ）：ロゴと操作部分を左右に並べ、1画面に収める */
@media (max-height: 520px) and (min-width: 640px) {
  .title-screen__top { position: absolute; top: 0; right: 0; }
  .title-screen__body { flex-direction: row; gap: clamp(24px, 6vw, 64px); padding-top: 12px; padding-bottom: 12px; }
  .title-screen__title { font-size: clamp(2.6rem, 17vh, 4.5rem); }
  .title-logo__tile { width: clamp(32px, 9vh, 48px); font-size: clamp(1rem, 5vh, 1.5rem); }
  .title-screen__main { gap: 10px; max-width: 380px; }
  .title-screen__lead { font-size: .85rem; }
  .title-screen__start { padding: 12px 20px; font-size: 1.15rem; }
  .title-record { padding: 10px 12px 6px; }
  .title-record__stats dd { font-size: 1.05rem; }
}

/* ---------------- ジャンル選択画面 ---------------- */

.genre-screen .simple-header { padding-bottom: 0; }
.genre-screen__body { flex: 1; padding: 0 16px 32px; max-width: 1120px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; }
/* タブレット・PCでは、画面に余裕があれば見出し〜カードをまとめて上下中央に置く（下半分が空くのを防ぐ）。
   auto の余白は内容が画面より高いときは0になるので、見出しが画面外に押し出されることはない */
@media (min-width: 640px) {
  .genre-screen__body > :first-child { margin-top: auto; }
  .genre-screen__body > :last-child { margin-bottom: auto; }
}
.genre-screen__body h1 { font-size: 1.15rem; text-align: center; margin: 4px 0 10px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ステージの進み具合（①✓ ②✓ ③選択中 ④ ⑤） */
.stage-progress {
  list-style: none; margin: 0 0 4px; padding: 0;
  display: flex; justify-content: center; gap: 6px;
}
.stage-progress__step {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 3px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: .8rem; white-space: nowrap;
}
.stage-progress__num {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--border); color: var(--text); font-weight: 700; font-size: .75rem;
}
.stage-progress__label { padding-right: 8px; overflow: hidden; text-overflow: ellipsis; }
.stage-progress__step.is-done { color: var(--text); border-color: var(--genre-color); }
.stage-progress__step.is-done .stage-progress__num { background: var(--genre-color); color: #fff; }
.stage-progress__step.is-current { color: var(--primary); border-color: var(--primary); font-weight: 700; }
.stage-progress__step.is-current .stage-progress__num { background: var(--primary); color: #fff; }
/* スマホでは5つのラベルを1行に収めるため、ジャンル名と「選択中」の文字を省き、余白も詰める
   （クリア済みは色と正答数、今のステージは青い番号で見分けられる） */
@media (max-width: 639px) {
  .stage-progress { gap: 4px; }
  .stage-progress__genre, .stage-progress__current-text { display: none; }
  .stage-progress__step { font-size: .78rem; }
  .stage-progress__label { padding-right: 6px; }
  .stage-progress__step.is-current .stage-progress__label { padding-right: 0; }
}
.loading { text-align: center; padding: 60px 0; color: var(--muted); }
.alert-box {
  background: #FEE2E2; color: #991B1B; padding: 12px 16px; border-radius: 8px;
  text-align: center; margin-bottom: 16px; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
}

/* カードの高さは内容に合わせ、同じ行のカードは高さを揃える（固定の縦横比にすると文字が切れるため） */
.genre-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  gap: 8px;
  margin-top: 14px;
}

/* 基本形（スマホ・タブレット）：横長のカードに色・ジャンル名・説明文を1行ずつ並べる */
.genre-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  min-height: 60px;
  padding: 8px 12px 8px 10px;
  text-align: left;
  border-radius: 12px;
  border: 2px solid var(--genre-color, var(--border));
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.genre-card__chip {
  align-self: stretch;
  width: 8px; min-height: 28px;
  border-radius: 4px;
  background: var(--genre-color, var(--muted));
}
.genre-card__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.genre-card__name { font-weight: 700; font-size: .95rem; }
.genre-card__desc {
  font-size: .76rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.genre-card__state { font-size: .76rem; font-weight: 700; white-space: nowrap; }

/* 選択済み・準備中：カード全体ではなく中身だけを薄くし、状態ラベルははっきり見せる */
.genre-card.is-used, .genre-card.is-locked { cursor: default; background: transparent; }
.genre-card.is-used .genre-card__chip, .genre-card.is-used .genre-card__main,
.genre-card.is-locked .genre-card__chip, .genre-card.is-locked .genre-card__main { opacity: .45; }
.genre-card.is-used { border-color: color-mix(in srgb, var(--genre-color) 40%, var(--border)); }
.genre-card.is-used .genre-card__state { color: var(--ok); }
.genre-card.is-locked { border-style: dashed; border-color: var(--choice-border); }
.genre-card.is-locked .genre-card__state { color: var(--muted); }

@media (hover: hover) and (pointer: fine) {
  .genre-card.is-playable:hover { box-shadow: 0 0 0 2px var(--genre-color) inset; }
}

@media (min-width: 640px) {
  .genre-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* PC：5列×2行。縦長のカードに色・名前・説明文（2行まで）・状態を上から並べる */
@media (min-width: 1024px) {
  .genre-grid { grid-template-columns: repeat(5, 1fr); gap: 12px; margin-top: 18px; }
  .genre-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
    min-height: 150px; padding: 14px;
  }
  .genre-card__chip { flex: 0 0 auto; align-self: flex-start; width: 22px; height: 22px; min-height: 0; border-radius: 6px; }
  .genre-card__main { gap: 4px; }
  .genre-card__desc {
    white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .genre-card__state { margin-top: auto; }
}

/* 大きいPC画面（幅1440px以上・高さ800px以上）：カードと文字を一回り大きくして、画面の広さを活かす */
@media (min-width: 1440px) and (min-height: 800px) {
  .genre-screen__body { max-width: 1400px; }
  .genre-screen__body h1 { font-size: 1.5rem; margin-bottom: 14px; }
  .stage-progress__step { font-size: .95rem; padding: 4px; }
  .stage-progress__num { width: 28px; height: 28px; font-size: .9rem; }
  .genre-grid { gap: 16px; margin-top: 24px; }
  .genre-card { min-height: 200px; padding: 20px; gap: 10px; border-radius: 16px; }
  .genre-card__chip { width: 28px; height: 28px; border-radius: 8px; }
  .genre-card__name { font-size: 1.2rem; }
  .genre-card__desc { font-size: .92rem; }
  .genre-card__state { font-size: .9rem; }
}

/* 背の高いタブレット縦（幅640〜1023px・高さ900px以上）：2列のカードを大きくし、説明文も2行まで表示する */
@media (min-width: 640px) and (max-width: 1023px) and (min-height: 900px) {
  .genre-screen__body h1 { font-size: 1.3rem; }
  .genre-grid { gap: 12px; }
  .genre-card { min-height: 92px; padding: 12px 16px 12px 12px; gap: 6px 14px; }
  .genre-card__chip { width: 10px; }
  .genre-card__name { font-size: 1.1rem; }
  .genre-card__desc {
    font-size: .88rem; white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
}

/* 小さいスマホ（幅640px未満・高さ700px以下）：説明文を省いてカードを低くし、10枚をほぼ1画面に収める */
@media (max-width: 639px) and (max-height: 700px) {
  .genre-screen .simple-header { padding-top: 6px; }
  .genre-screen__body h1 { font-size: 1rem; margin: 0 0 6px; }
  .genre-grid { gap: 6px; margin-top: 10px; }
  .genre-card { min-height: 44px; padding: 6px 12px 6px 10px; }
  .genre-card__chip { min-height: 22px; }
  .genre-card__desc { display: none; }
}

/* 高さの低い横長画面（スマホ横向きなど）：説明文を省き、4列にして10枚を少ないスクロールで見せる */
@media (max-height: 520px) and (min-width: 640px) and (max-width: 1023px) {
  .genre-screen__body h1 { font-size: 1rem; margin: 0 0 6px; }
  .genre-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
  .genre-card { min-height: 48px; grid-template-columns: auto minmax(0, 1fr); padding: 6px 10px 6px 8px; }
  .genre-card__desc { display: none; }
  .genre-card__name { font-size: .88rem; }
  .genre-card__state { grid-column: 2; font-size: .7rem; }
}

/* ---------------- ステージ開始表示 ---------------- */

.stage-intro {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; cursor: pointer;
  background: linear-gradient(160deg, color-mix(in srgb, var(--genre-color) 18%, var(--bg)), var(--bg));
}
.stage-intro__stage { font-size: 2.2rem; font-weight: 800; margin: 0; }
.stage-intro__genre {
  font-size: 1.2rem; margin: 0; padding: 6px 20px; border-radius: 999px;
  background: var(--genre-color); color: #fff;
}

/* ---------------- 出題画面 ---------------- */

.q-screen { height: 100dvh; overflow: hidden; }

.q-header {
  flex: 0 0 48px; height: 48px;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.q-header__stage { font-weight: 700; white-space: nowrap; }
.q-header__genre {
  background: var(--genre-color, var(--primary));
  color: #fff;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: .95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  /* STAGE表示・効果音ボタン・余白を除いた残りを使い、狭いスマホでもジャンル名を切らない */
  max-width: calc(100vw - 170px);
}
.q-header .sound-toggle { margin-left: auto; font-size: 1.15rem; }

.q-timebar { flex: 0 0 4px; background: var(--border); overflow: hidden; }
.q-timebar__fill {
  height: 100%;
  background: var(--primary);
  transform-origin: left center;
}
.q-timebar__fill.is-warning { background: var(--danger); }

/* 選択肢エリアは内容の高さを確保し、残りを問題文エリアに回す（画面が低くても④が隠れないようにする）。
   それでも収まらない極端に低い画面では、切れずに全体をスクロールできるようにする */
.q-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }

/* 問題文・解説欄・選択肢エリアは同じ最大幅にそろえて中央に置く（大画面で問題文の枠だけが横に広がらないように） */
.q-question, .q-explanation { width: calc(100% - 40px); max-width: 1120px; margin-inline: auto; }
.q-lower { width: 100%; max-width: 1160px; margin-inline: auto; }

.q-question {
  flex: 1 1 auto; min-height: 96px;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 24px; overflow: auto;
  margin-top: 12px; margin-bottom: 6px;
  background: var(--question-bg);
  border-radius: 18px;
}
.q-question__text {
  line-height: 1.5;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  min-height: 1.5em;
}
/* 文字数に応じた3段階のフォントサイズ（問題文の上限50文字を基準に区切る）。
   幅だけでなく高さ（vh）でも上限を決め、大きい画面では大きく、低い画面では控えめにする */
.q-question__text.size-short { font-size: clamp(1.6rem, min(5.6vw, 6.5vh), 3rem); }   /* 〜17文字 */
.q-question__text.size-medium { font-size: clamp(1.35rem, min(4.6vw, 5vh), 2.4rem); } /* 18〜34文字 */
.q-question__text.size-long { font-size: clamp(1.15rem, min(4vw, 4vh), 1.9rem); }     /* 35〜50文字 */

.q-explanation {
  flex: 0 0 auto;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  margin-top: 4px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.q-explanation[hidden] { display: none; }
.q-explanation { position: relative; overflow: hidden; }
/* 自動で閉じるまでの残り時間を、解説欄の下端の細いバーが縮むことで示す */
.q-explanation__timer {
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: var(--primary); transform-origin: left center;
  animation: explanation-timer linear forwards;
}
@keyframes explanation-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.q-explanation__result { font-weight: 800; white-space: nowrap; }
.q-explanation__result.is-correct { color: var(--ok); }
.q-explanation__result.is-wrong { color: var(--danger); }
.q-explanation__text { flex: 1 1 14em; margin: 0; line-height: 1.6; }
.q-explanation .btn { margin-left: auto; }

.q-lower {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
  padding: 10px 16px max(18px, env(safe-area-inset-bottom));
}

.q-status-row { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; }
.q-side--left { display: flex; gap: 14px; color: var(--muted); }
.q-num__total { font-size: .8em; }
.q-timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.25rem; }
.q-timer.is-warning { color: var(--danger); animation: blink 0.5s steps(1) infinite; }

.q-choices { display: flex; flex-direction: column; gap: 8px; }

.choice {
  display: flex; align-items: center; gap: 10px;
  min-height: 3em;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--choice-border);
  background: var(--choice-bg);
  color: var(--text);
  font-size: 1.1rem;
  text-align: left;
  cursor: pointer;
}
/* タッチ端末では:hoverが「タップ後も枠が残る」ように見えるため、実際にマウスを持つ環境だけに限定する */
@media (hover: hover) and (pointer: fine) {
  .choice:hover:not(.is-locked) { border-color: var(--primary); border-width: 2px; }
}
/* タップ中（指を触れている間）だけ枠を出す。指を離せば即座に消えるためhoverの「貼り付き」は起きない。
   ホバーと同じ色だと区別しづらいため、押下中は少し濃い色にする */
.choice:active:not(.is-locked) { border-color: var(--primary-dark); }
.choice.is-locked { cursor: default; }
.choice__num { font-weight: 700; color: var(--primary); flex: 0 0 auto; }
.choice__text { word-break: break-word; }

.choice.is-correct { background: #DCFCE7; border-color: var(--ok); color: #14532D; }
.choice.is-wrong { background: #FEE2E2; border-color: var(--danger); color: #7F1D1D; }

/* タブレット縦など（幅640〜899px）：スマホと同じ並びのまま、広さに合わせて文字を大きくする */
@media (min-width: 640px) and (max-width: 899px) {
  .q-status-row { font-size: 1rem; }
  .q-timer { font-size: 1.6rem; }
  .choice { font-size: 1.3rem; min-height: 3.2em; }
}

/* 左右に問題数・残り時間の列を置くのは幅900px以上だけ。
   タブレット縦（768px前後）で3列にすると選択肢の欄が狭くなり、どの選択肢も2行に折り返してしまうため */
@media (min-width: 900px) {
  .q-lower {
    display: grid;
    grid-template-columns: minmax(120px, 160px) minmax(0, 760px) minmax(120px, 160px);
    grid-template-areas: "left choices right";
    justify-content: center; align-items: stretch; gap: 0 16px;
  }
  .q-status-row { display: contents; }
  /* 問題文エリアに近い位置に小さめの箱を置き、その箱の中で上下中央に表示する
     （grid全体の高さいっぱいに広げると、問題文エリアとの間の余白が大きくなってしまうため） */
  .q-side--left {
    grid-area: left; align-self: start; min-height: 4.5em;
    flex-direction: column; justify-content: center; align-items: center;
    text-align: center; gap: 10px;
  }
  .q-side--right {
    grid-area: right; align-self: start; min-height: 4.5em;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center;
  }
  /* 選択肢を上詰めにして、問題文エリアとの間の余白を詰める */
  .q-choices { grid-area: choices; justify-content: flex-start; }
  .q-lower { padding-top: 4px; }

  /* 問題数エリア・残り時間エリアの文字を大きく表示する（PC画面） */
  .q-side--left .q-num, .q-side--left .q-correct { font-size: 1.3rem; }
  .q-side--right .q-timer { font-size: 2.2rem; }

  /* 選択肢の文字を大きく表示する（PC画面） */
  .choice { font-size: 1.55rem; }
}

/* 高さの低い画面（ノートPCの小さいウィンドウ、スマホ横向き）：選択肢を2×2に並べて4つとも収める */
@media (max-height: 520px) {
  .q-header { flex-basis: 40px; height: 40px; }
  .q-question { min-height: 64px; margin-top: 6px; margin-bottom: 2px; padding: 6px 16px; border-radius: 12px; }
  .q-question, .q-explanation { width: calc(100% - 24px); }
  .q-question__text.size-short { font-size: 1.6rem; }
  .q-question__text.size-medium { font-size: 1.35rem; }
  .q-question__text.size-long { font-size: 1.15rem; }
  .q-explanation { padding: 8px 12px; }
  .q-lower { padding-top: 6px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .q-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .choice { min-height: 2.6em; padding: 6px 12px; font-size: 1rem; }
  .q-side--left .q-num, .q-side--left .q-correct { font-size: 1rem; }
  .q-side--right .q-timer { font-size: 1.6rem; }
}
@media (max-height: 520px) and (min-width: 900px) {
  .q-lower { grid-template-columns: minmax(80px, 120px) minmax(0, 760px) minmax(80px, 120px); gap: 0 10px; }
  .choice { font-size: 1.15rem; }
  .q-side--left, .q-side--right { min-height: 0; }
}

/* ---------------- 判定オーバーレイ ---------------- */

.judge-overlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px;
  background: var(--overlay-bg);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease;
  z-index: 20;
}
/* [hidden] はデフォルトのUAスタイルだが、上の display:flex が上書きしてしまうため明示的に指定する。
   これが無いと、判定前の透明なオーバーレイが選択肢のクリックを吸ってしまう。 */
.judge-overlay[hidden] { display: none; }
.judge-overlay.is-visible { opacity: 1; pointer-events: auto; }
.judge-mark {
  /* 画面の幅と高さの小さいほうの60%を基準にし、縦長のスマホでも横長のPCでも画面に対して同じくらいの存在感にする */
  font-size: clamp(9rem, min(60vw, 60vh), 28rem);
  font-weight: 800;
  line-height: 1;
  /* ◯✕はフォントに太字グリフが無いことが多く、font-weightだけでは太く見えないため、
     文字の縁取り（text-stroke）を重ねて確実に太く見せる。マークが大きくなっても線が細く見えないよう、太さも比例させる */
  -webkit-text-stroke: max(4px, .02em) currentColor;
  paint-order: stroke fill;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.35));
}
.judge-mark.is-correct { color: #22C55E; }
.judge-mark.is-wrong { color: #EF4444; }

@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: .35; } }

/* ---------------- 結果画面 ---------------- */

/* 結果に応じたテーマ色（クリア＝緑／失敗＝赤／最終結果＝金）を --accent に入れ、見出し・背景・正答数の丸に使う */
.result-screen { --accent: var(--ok); }
.result-screen.is-fail { --accent: var(--danger); }
.result-screen.is-final { --accent: #D97706; }
.result-screen {
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 65%), var(--bg);
}

.result-screen__body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 20px max(32px, env(safe-area-inset-bottom)); gap: 20px; text-align: center;
}
.result-screen__main, .result-screen__side { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 440px; }

.result-hero { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.result-hero__mark {
  margin: 0; line-height: 1; font-weight: 800; color: var(--accent);
  font-size: clamp(3.5rem, 12vmin, 5.5rem);
  -webkit-text-stroke: max(2px, .03em) currentColor; paint-order: stroke fill;
}
.result-hero__title { margin: 0; font-size: clamp(1.6rem, 6vmin, 2.4rem); font-weight: 800; color: var(--accent); }
.result-screen.is-final .result-hero__title { color: var(--text); }
.result-hero__genre {
  margin: 4px 0 0; padding: 4px 14px; border-radius: 999px;
  background: var(--genre-color, var(--primary)); color: #fff; font-weight: 700; font-size: .95rem;
}
.result-hero__logo { margin-bottom: 4px; }
.result-hero__rank {
  margin: 4px 0 0; display: flex; align-items: center; gap: 8px;
  font-size: clamp(1.3rem, 5vmin, 1.8rem); font-weight: 900; color: #B45309;
}
.result-hero__rank-label {
  padding: 2px 10px; border-radius: 999px; background: #FEF3C7; color: #92400E; font-size: .8rem; font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .result-hero__rank { color: #FBBF24; }
}

.result-score { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.result-score__num { margin: 0; line-height: 1; font-variant-numeric: tabular-nums; }
.result-score__num strong { font-size: clamp(3rem, 12vmin, 4.5rem); font-weight: 900; color: var(--accent); }
.result-score__max { font-size: clamp(1.3rem, 4.5vmin, 1.8rem); font-weight: 700; color: var(--muted); }
.result-score__pips { display: flex; gap: 6px; }
.result-score__pip { width: 18px; height: 18px; border-radius: 50%; background: var(--border); }
.result-score__pip.is-hit { background: var(--accent); }
/* クリアライン（5問目）の後ろに縦線を入れ、あと何問だったかを見て分かるようにする */
.result-score__pip.is-line { position: relative; margin-right: 10px; }
.result-score__pip.is-line::after {
  content: ""; position: absolute; right: -9px; top: -4px; bottom: -4px; width: 2px; border-radius: 1px; background: var(--muted);
}
.result-score__note { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.result-score__short { display: block; color: var(--danger); font-size: 1.05rem; }

/* スマホで押しやすいよう、ボタンは横幅いっぱいで縦に並べる */
.result-screen__actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }
.result-screen__actions .btn { width: 100%; font-weight: 700; border-radius: 12px; }

.history-table { border-collapse: collapse; font-size: .9rem; width: 100%; }
.history-table th, .history-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.history-table th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.history-table .history-table__score { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-table__dot {
  display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%;
  background: var(--genre-color); vertical-align: 0;
}
.history-table tr.is-current td { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 700; }
.history-table tfoot td { font-weight: 800; border-top: 2px solid var(--border); border-bottom: none; }

/* 小さいスマホ（幅640px未満・高さ700px以下）：飾りと余白を詰めて、最終結果（5行の成績表つき）も1画面に収める */
@media (max-width: 639px) and (max-height: 700px) {
  .result-screen__body { gap: 12px; padding-top: 12px; }
  .result-screen__main, .result-screen__side { gap: 10px; }
  .result-hero__logo { display: none; }
  .result-hero__mark { font-size: 3rem; }
  .result-hero__title { font-size: 1.5rem; }
  .result-score { gap: 6px; }
  .result-score__num strong { font-size: 2.8rem; }
  .result-screen__actions { flex-direction: row; max-width: none; }
  .result-screen__actions .btn { padding: 12px 10px; font-size: 1rem; }
  .history-table th, .history-table td { padding: 4px 8px; }
}

/* 高さの低い横長画面（スマホ横向き、ノートPCの低いウィンドウなど）：
   結果（左）と操作・成績表（右）を左右に並べ、1画面に収める */
@media (max-height: 520px) and (min-width: 640px), (max-height: 760px) and (min-width: 900px) {
  .result-screen__body { flex-direction: row; align-items: center; gap: clamp(20px, 5vw, 56px); padding-top: 12px; padding-bottom: 12px; }
  .result-screen__main { gap: 10px; }
  .result-screen__side { gap: 10px; max-width: 400px; }
  .result-hero { gap: 2px; }
  .result-hero__mark { font-size: clamp(2.4rem, 12vh, 3.5rem); }
  .result-hero__title { font-size: clamp(1.3rem, 6vh, 1.8rem); }
  .result-hero__logo .title-logo__tile { width: 30px; font-size: 1rem; }
  .result-score { gap: 6px; }
  .result-score__num strong { font-size: clamp(2.2rem, 12vh, 3rem); }
  .result-score__pip { width: 14px; height: 14px; }
  .result-screen__actions { flex-direction: row; max-width: none; }
  .result-screen__actions .btn { padding: 10px 16px; font-size: 1rem; }
  .history-table { font-size: .8rem; }
  .history-table th, .history-table td { padding: 3px 8px; }
}

@media (max-width: 480px) {
  .title-screen__title { letter-spacing: .08em; }
}
