/* VinoQuest — stylesheet (MIT)
 *
 * ── 配色の方針 ───────────────────────────────────────────────
 * ベースは 4 色のみ。それ以外の色はすべて、この 4 色の不透明度違いで作る。
 *
 *   1. ground … 背景（面）
 *   2. ink    … 文字（＋境界線・面の階調をアルファで派生）
 *   3. wine   … ブランドカラー。主要操作・強調
 *   4. gold   … アクセント。見出し・達成・リンク
 *
 * 例外はアイコンのみ（絵文字、品種キャラのSVG、正誤バッジの ✓ / ✕）。
 *
 * ── 可読性の基準 ─────────────────────────────────────────────
 * ・本文と副次テキストは背景に対して 7:1 以上（WCAG AAA 相当）
 * ・最小の文字でも 4.5:1 以上、かつ 12px 未満を作らない
 * ・文字の下に模様を敷かない（背景は単色）
 * ------------------------------------------------------------- */

:root {
  /* ---- ベースの4色（ダーク） ---- */
  --ground: #1d151c;
  --ink-rgb: 240 233 236;
  --wine-rgb: 176 60 98;
  --gold-rgb: 226 180 88;

  /* 面：ground と同系の明度違い */
  --surface: #261c24;
  --surface-2: #322632;

  /* ---- 4色からの派生（新しい色は足さない） ---- */
  --ink: rgb(var(--ink-rgb));
  --ink-2: rgb(var(--ink-rgb) / .80);   /* 副次テキスト */
  --ink-3: rgb(var(--ink-rgb) / .62);   /* 補助テキスト */
  --line: rgb(var(--ink-rgb) / .16);
  --line-2: rgb(var(--ink-rgb) / .30);

  --wine: rgb(var(--wine-rgb));
  --wine-soft: rgb(var(--wine-rgb) / .18);
  --wine-line: rgb(var(--wine-rgb) / .55);
  --on-wine: #fff;

  --gold: rgb(var(--gold-rgb));
  --gold-soft: rgb(var(--gold-rgb) / .16);
  --gold-line: rgb(var(--gold-rgb) / .55);
  --on-gold: #241019;

  /* ---- 寸法 ---- */
  --r-s: 10px;
  --r-m: 14px;
  --r-l: 20px;
  --shadow: 0 2px 10px rgb(0 0 0 / .28);
  --maxw: 900px;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic",
          Meiryo, "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ライトでは地が明るいため、wine を薄めると白文字が読みにくくなる。ベタで使う */
html[data-theme="light"] .hero { background: rgb(var(--wine-rgb)); }

html[data-theme="light"] {
  --ground: #f7f2f4;
  --ink-rgb: 32 16 24;
  --wine-rgb: 141 39 74;
  --gold-rgb: 129 92 24;

  --surface: #ffffff;
  --surface-2: #f0e7ea;

  --ink-2: rgb(var(--ink-rgb) / .82);
  --ink-3: rgb(var(--ink-rgb) / .66);
  --line: rgb(var(--ink-rgb) / .16);
  --line-2: rgb(var(--ink-rgb) / .32);
  --on-wine: #fff;
  --on-gold: #fff;
  --shadow: 0 2px 10px rgb(32 16 24 / .10);
}

/* ============================================================
   基本
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.85;
  letter-spacing: .015em;
  min-height: 100dvh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }

h1, h2, h3, h4 { line-height: 1.5; margin: 0 0 .5em; }
h1 { font-size: 1.42rem; letter-spacing: .01em; }
h2 { font-size: 1.14rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ============================================================
   起動画面
   ============================================================ */
.boot {
  position: fixed; inset: 0; z-index: 99;
  display: grid; place-content: center; gap: 18px; justify-items: center;
  background: var(--ground); transition: opacity .3s;
}
.boot.hide { opacity: 0; pointer-events: none; }
.boot p { color: var(--ink-3); font-size: .9rem; margin: 0; }
.boot-glass {
  width: 54px; height: 70px; position: relative; overflow: hidden;
  border: 2px solid var(--wine); border-top: none; border-radius: 0 0 26px 26px;
}
.boot-glass::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 0;
  background: var(--wine);
  animation: fill 1.4s ease-in-out infinite alternate;
}
@keyframes fill { from { height: 8%; } to { height: 78%; } }

/* ============================================================
   アプリバー
   ============================================================ */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--ground);
  border-bottom: 1px solid var(--line);
}
.appbar-back {
  background: none; border: none; cursor: pointer;
  font-size: 1.7rem; line-height: 1; padding: 0 8px; color: var(--ink-2);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .03em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; display: inline-block;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--wine);
  box-shadow: 0 0 0 2px var(--gold-line) inset;
}
.brand-text b { color: var(--gold); font-weight: 700; }

.appbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.streak {
  font-size: .88rem; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
  padding: 4px 11px; border-radius: 999px;
}
.streak b { color: var(--gold); }
.icon-btn {
  width: 36px; height: 36px; cursor: pointer; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}
.icon-btn:hover { border-color: var(--line-2); color: var(--ink); }

/* ============================================================
   レイアウト
   ============================================================ */
.app { max-width: var(--maxw); margin: 0 auto; padding: 18px 16px 34px; }
.sidenav { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; display: flex;
  background: var(--ground);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px; font-size: .75rem; font-weight: 600;
  color: var(--ink-3); text-decoration: none;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a i { font-style: normal; font-size: 1.24rem; line-height: 1.1; }
.tabbar a.on { color: var(--gold); }

@media (min-width: 900px) {
  body { padding-bottom: 34px; }
  .tabbar { display: none; }
  .sidenav {
    display: flex; flex-direction: column; gap: 3px;
    position: fixed; top: 68px; left: max(12px, calc(50vw - 610px));
    width: 186px; padding: 10px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  }
  .sidenav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--r-s);
    color: var(--ink-2); font-size: .93rem; text-decoration: none;
  }
  .sidenav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
  .sidenav a.on { background: var(--wine); color: var(--on-wine); font-weight: 700; }
  .sidenav a i { font-style: normal; font-size: 1.08rem; }
  .app { margin-left: max(218px, calc(50vw - 404px)); max-width: 820px; }
}

/* ============================================================
   基本パーツ
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-m); padding: 17px;
}
.card + .card { margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); }
.gstat { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.center { text-align: center; }
.sep { height: 1px; background: var(--line); margin: 15px 0; border: 0; }

/* 補助テキスト：小さくしすぎない・薄くしすぎない */
.muted { color: var(--ink-3); }
.small { font-size: .875rem; line-height: 1.75; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--ink);
  padding: 11px 18px; border-radius: 999px; cursor: pointer;
  font-size: .95rem; font-weight: 700;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: var(--line-2); background: var(--surface); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--wine); border-color: var(--wine); color: var(--on-wine); }
.btn.primary:hover { background: var(--wine); filter: brightness(1.12); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
.btn.gold:hover { background: var(--gold); filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn.sm { padding: 10px 15px; font-size: .875rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.chip {
  display: inline-block; padding: 4px 11px; border-radius: 999px;
  font-size: .8rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.chip.on { background: var(--wine); border-color: var(--wine); color: var(--on-wine); }
.chip.gold,
.chip.ok { background: var(--gold-soft); border-color: var(--gold-line); color: var(--gold); }
.chip.bad { background: var(--wine-soft); border-color: var(--wine-line); color: var(--ink); }

.bar { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 99px;
  background: var(--gold); transition: width .5s ease;
}

.hero {
  border-radius: var(--r-l); padding: 22px;
  background: rgb(var(--wine-rgb) / .78); color: var(--on-wine);
}
.hero h1 { margin: 0 0 6px; color: var(--on-wine); }
.hero p { margin: 0; font-size: .95rem; color: rgb(255 255 255 / .92); }
.hero b { color: #fff; }

/* ============================================================
   タイル
   ============================================================ */
.tile {
  display: block; padding: 16px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  transition: border-color .14s, background .14s;
}
.tile:hover { border-color: var(--gold-line); background: var(--surface-2); text-decoration: none; }
.tile .ico { font-size: 1.65rem; line-height: 1; }
.tile h3 { margin: 9px 0 4px; font-size: 1rem; }
.tile p { margin: 0; font-size: .86rem; line-height: 1.7; color: var(--ink-3); }

/* ============================================================
   フラッシュカード
   ============================================================ */
.fc-wrap { perspective: 1400px; margin: 8px 0 14px; }
.fc {
  position: relative; min-height: min(56vh, 400px); cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .7, .3, 1);
}
.fc.flip { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; overflow-y: auto;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--r-l); padding: 24px 22px;
  display: flex; flex-direction: column; justify-content: center; text-align: center;
}
.fc-front { background: var(--surface); border: 1px solid var(--line-2); }
.fc-back {
  background: var(--surface-2); border: 1px solid var(--gold-line);
  transform: rotateY(180deg);
}
.fc-q { font-size: 1.1rem; font-weight: 700; line-height: 1.85; }
.fc-a { font-size: 1.25rem; font-weight: 800; color: var(--gold); margin-bottom: 12px; }
.fc-exp { font-size: .92rem; line-height: 1.9; color: var(--ink-2); text-align: left; }
.fc-hint { margin-top: 16px; font-size: .82rem; color: var(--ink-3); }
.fc-cat { position: absolute; top: 12px; left: 16px; font-size: .78rem; color: var(--ink-3); }
.fc-count { position: absolute; top: 12px; right: 16px; font-size: .78rem; color: var(--ink-3); }
.fc-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* 3段階の評価は「濃さ」で区別する（色数を増やさない） */
.grade { line-height: 1.35; padding: 12px 6px; font-size: .9rem; white-space: nowrap; }
.grade span { display: block; font-size: .78rem; font-weight: 600; color: var(--ink-3); }
.g-no { background: transparent; border-color: var(--line); }
.g-mid { background: var(--surface-2); border-color: var(--line-2); }
.g-yes { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
.g-yes span { color: rgb(36 16 25 / .7); }

/* ============================================================
   クイズ
   ============================================================ */
.choices { display: flex; flex-direction: column; gap: 10px; margin: 15px 0; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 14px 15px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: .97rem; line-height: 1.7; color: var(--ink);
  transition: border-color .14s, background .14s;
}
.choice:hover { border-color: var(--line-2); }
.choice .k {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-content: center; font-size: .8rem; font-weight: 700;
  background: var(--wine); color: var(--on-wine);
}
.choice.locked { cursor: default; }
/* 正誤は「枠 + バッジ記号 + 文言」で示す。色だけに頼らない */
.choice.correct { border-color: var(--gold); border-width: 2px; background: var(--gold-soft); }
.choice.correct .k { background: #2f8f5b; color: #fff; }   /* アイコン色 */
.choice.wrong { border-color: var(--line-2); opacity: .72; }
.choice.wrong .k { background: #c0413f; color: #fff; }     /* アイコン色 */

.qmeta {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: .82rem; color: var(--ink-3); margin-bottom: 8px;
}
.qtext { font-size: 1.06rem; font-weight: 700; line-height: 1.9; margin: 6px 0 4px; }
.exp {
  margin-top: 14px; padding: 14px 16px;
  background: var(--surface-2); border-left: 4px solid var(--gold);
  border-radius: 0 var(--r-s) var(--r-s) 0;
  font-size: .93rem; line-height: 1.9; color: var(--ink-2);
}
.exp b { color: var(--ink); }
.verdict { font-weight: 800; }
.verdict.ok { color: var(--gold); }
.verdict.ng { color: var(--ink); }

/* ============================================================
   品種図鑑
   ============================================================ */
.chr-card {
  display: block; padding: 12px 10px 14px; text-align: center;
  text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  transition: border-color .14s, background .14s;
}
.chr-card:hover { border-color: var(--gold-line); background: var(--surface-2); text-decoration: none; }
.chr-card svg { width: 100%; height: auto; max-width: 122px; }
.chr-card .nm { font-size: .87rem; font-weight: 700; margin-top: 7px; line-height: 1.45; }
.chr-card .jp { font-size: .76rem; color: var(--ink-3); margin-top: 2px; }
.chr-hero { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.chr-hero svg { width: 132px; height: auto; flex: none; }
.radar { width: 100%; max-width: 300px; height: auto; }
.kv { display: grid; grid-template-columns: 6em 1fr; gap: 8px 14px; font-size: .93rem; line-height: 1.8; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

/* ============================================================
   テキスト（教本）
   ============================================================ */
.tb { font-size: 1rem; }
/* 1行が長くなりすぎると読みにくいので、和文で40字前後に収める */
.tb p, .tb li { max-width: 40em; }
.tb h2 {
  margin: 32px 0 12px; padding-bottom: 8px;
  border-bottom: 2px solid var(--gold-line); color: var(--gold);
  font-size: 1.18rem;
}
.tb h3 { margin: 24px 0 9px; color: var(--ink); font-size: 1.04rem; }
.tb h3::before { content: "\258D"; color: var(--wine); margin-right: 7px; }
.tb ul, .tb ol { margin: 0 0 1.1em; padding-left: 1.4em; }
.tb li { margin: .4em 0; line-height: 1.95; }
.tb strong, .tb b { color: var(--ink); font-weight: 700; }

.tb table {
  width: 100%; margin: 12px 0 20px; border-collapse: collapse;
  font-size: .92rem; line-height: 1.7;
  display: block; overflow-x: auto;
}
.tb th, .tb td {
  border: 1px solid var(--line); padding: 9px 12px;
  text-align: left; vertical-align: top; min-width: 6em;
}
.tb th { background: var(--surface-2); color: var(--gold); font-weight: 700; white-space: nowrap; }
.tb td { color: var(--ink-2); }
.tb td b { color: var(--ink); }

.tb .note, .tb .tip {
  margin: 16px 0; padding: 14px 16px; font-size: .93rem; line-height: 1.9;
  border-radius: 0 var(--r-s) var(--r-s) 0; color: var(--ink-2);
  max-width: 44em;
}
.tb .note { background: var(--surface-2); border-left: 4px solid var(--wine); }
.tb .tip { background: var(--gold-soft); border-left: 4px solid var(--gold); }
.tb .note b, .tb .tip b { color: var(--ink); }
.tb code {
  background: var(--surface-2); padding: 2px 7px; border-radius: 5px;
  font-size: .92em; color: var(--gold);
}

.toc a {
  display: block; padding: 13px 15px; font-size: .97rem;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.toc a:last-child { border-bottom: none; }
.toc a:hover { background: var(--surface-2); text-decoration: none; }
.toc .n { color: var(--gold); font-weight: 700; margin-right: 10px; font-size: .88rem; }

/* ============================================================
   その他
   ============================================================ */
.stat {
  padding: 13px 6px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-m);
}
.stat .v { font-size: 1.4rem; font-weight: 800; color: var(--gold); line-height: 1.25; }
.stat .l { font-size: .8rem; color: var(--ink-3); margin-top: 3px; }

.ring { display: block; margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); z-index: 60;
  padding: 12px 20px; max-width: 90vw; text-align: center;
  background: var(--gold); color: var(--on-gold); font-size: .9rem; font-weight: 700;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--ink); font-size: 1.05rem; }
.timer.danger { color: var(--gold); }

.searchbox {
  width: 100%; padding: 13px 18px; font-size: .97rem;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 999px; color: var(--ink);
}
.searchbox::placeholder { color: var(--ink-3); }

select, input[type=number], textarea {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-s);
  padding: 10px 12px; color: var(--ink); font-size: .93rem; font-family: inherit;
}
label.sw {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; font-size: .97rem;
}

details > summary { cursor: pointer; color: var(--ink-2); }
details > summary:hover { color: var(--ink); }

.footer {
  margin: 38px 0 12px; text-align: center;
  font-size: .84rem; line-height: 2; color: var(--ink-3);
}
.footer a { color: var(--ink-2); text-decoration: underline; }
.footer a:hover { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
