/* Chengyu Clash — warm glass cards with accessible interaction states. */

/* Bundled Nunito (variable, latin) — keeps the look identical on devices
   whose system/theme fonts would otherwise hijack the whole UI. */
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url("fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #33261C;
  --muted: #6E5F4F;
  --line: rgba(255, 255, 255, .65);
  --glass: rgba(255, 255, 255, .52);
  --glass-strong: rgba(255, 255, 255, .72);
  --red: #D8432F;
  --red-dark: #A93021;
  --gold: #E9A13B;
  --gold-soft: rgba(255, 214, 140, .35);
  --jade: #3FA37C;
  --jade-soft: rgba(111, 205, 167, .22);
  --l1: #5B8DEF;
  --l2: #E9A13B;
  --l3: #D8432F;
  --purple: #9B6BD8;
  --l3-soft: rgba(216, 67, 47, .18);
  --gold-text: #8A5A0B;   /* gold as small-text color, >=4.5:1 on card glass */
  --purple-text: #6E3FA8; /* purple as small-text color, >=4.5:1 on card glass */
  --shadow: 0 8px 32px rgba(120, 80, 40, .12);
  --shadow-lg: 0 16px 48px rgba(120, 80, 40, .18);
  --radius: 22px;
  --focus: #9C2B1D;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans", "Liberation Sans", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  min-height: 100vh;
  display: flex; flex-direction: column;
  background:
    radial-gradient(560px 420px at 8% -6%,   rgba(216, 67, 47, .20), transparent 65%),
    radial-gradient(640px 480px at 96% 4%,  rgba(233, 161, 59, .26), transparent 65%),
    radial-gradient(620px 500px at -6% 78%, rgba(63, 163, 124, .20), transparent 65%),
    radial-gradient(560px 460px at 92% 96%, rgba(155, 107, 216, .16), transparent 65%),
    linear-gradient(160deg, #FBF3E4, #F6EADA 55%, #F2E4D0);
  background-attachment: fixed;
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; padding: 14px 26px;
  background: rgba(255, 255, 255, .38);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 48px; height: 48px; border-radius: 13px;
  background: linear-gradient(145deg, #E8543F, #C22F1D);
  color: #FFF6E8; font-size: 26px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px rgba(200, 60, 40, .35), inset 0 -3px 0 rgba(0,0,0,.18);
  transform: rotate(-5deg);
  transition: transform .25s;
}
.brand:hover .logo { transform: rotate(4deg) scale(1.06); }
h1 { font-size: 23px; font-weight: 900; letter-spacing: .3px; }
.accent { color: var(--red); }
.tagline { font-size: 12px; color: var(--muted); font-weight: 700; }
nav { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.tab-list { display: flex; align-items: center; gap: 9px; }
.tab {
  background: var(--glass); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 9px 20px; cursor: pointer;
  font-size: 14px; font-weight: 800; font-family: inherit;
  backdrop-filter: blur(14px) saturate(150%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  box-shadow: 0 4px 14px rgba(120, 80, 40, .10);
  transition: transform .14s, background .14s, box-shadow .14s;
}
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.1em; height: 1.1em; display: inline-block; flex: 0 0 auto;
  vertical-align: -.18em; fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}
.tab, .mode-card, button.primary, button.ghost, .tts-btn, .translate-btn, .learn-more,
.res-head, #quiz-level-label, .quiz-ask { display: inline-flex; align-items: center; gap: 7px; }
.tab .zh-sub, .mode-card .zh-sub, button.primary .zh-sub, button.ghost .zh-sub,
.learn-more .zh-sub { display: block; }
.mode-card { flex-direction: column; }
.mode-icon {
  width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px; margin-bottom: 7px; color: currentColor;
  background: rgba(255,255,255,.42); border: 1px solid rgba(255,255,255,.72);
}
.mode-icon .icon { width: 25px; height: 25px; stroke-width: 1.8; }
.mode-card.praise .mode-icon { color: var(--jade); }
.mode-card.argue .mode-icon { color: var(--red); }
.mode-card.sarcasm .mode-icon { color: var(--purple); }
.tab .icon { width: 17px; height: 17px; }
.tab.active .icon { color: currentColor; }
.tab:hover { transform: translateY(-2px) rotate(-1deg); box-shadow: var(--shadow); }
.tab.active { background: #A93021; color: #FFF6E8; box-shadow: 0 6px 18px rgba(169, 48, 33, .35); }

main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 26px 22px 52px; }

/* ---------- draw flow ---------- */
.draw-title { text-align: center; margin: 18px 0 6px; font-size: 30px; font-weight: 900; }
.modes {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap;
  margin: 20px auto 0; max-width: 780px;
}
.mode-card {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(170%);
  -webkit-backdrop-filter: blur(16px) saturate(170%);
  border: 1.5px solid var(--line); border-radius: 18px;
  color: var(--ink); padding: 18px 26px; cursor: pointer; text-align: center;
  font-size: 17px; font-weight: 900; font-family: inherit;
  box-shadow: var(--shadow);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.mode-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.mode-card.praise:hover { transform: translateY(-4px) rotate(-1.2deg) scale(1.03); border-color: var(--jade); box-shadow: var(--shadow-lg); }
.mode-card.argue:hover { transform: translateY(-4px) rotate(1.2deg) scale(1.03); border-color: var(--red); box-shadow: var(--shadow-lg); }
.mode-card.sarcasm:hover { transform: translateY(-4px) rotate(-1deg) scale(1.03); border-color: var(--purple); box-shadow: var(--shadow-lg); }
.mode-card:hover .mode-icon { transform: translateY(-2px); }

.draw-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
#mode-label { font-weight: 900; font-size: 16px; flex: 1; }
.free-count {
  color: var(--muted); font-size: 12px; font-weight: 800;
  background: var(--glass); border: 1.5px solid var(--line);
  padding: 6px 14px; border-radius: 999px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.draw-stage { display: flex; flex-direction: column; align-items: center; gap: 22px; }
#card-slot { width: 100%; display: flex; justify-content: center; }
#card-slot .idiom-card { max-width: 580px; width: 100%; }
button.big { font-size: 17px; padding: 15px 38px; }
.upsell { max-width: 560px; text-align: center; }
.upsell p { color: var(--muted); margin: 12px 0 18px; line-height: 1.6; font-weight: 600; }

/* ---------- idiom card (frosted collectible) ---------- */
.idiom-card {
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 0; cursor: default; position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.idiom-card.drawn { animation: drawIn .4s cubic-bezier(.34,1.56,.64,1); }
@keyframes drawIn {
  from { transform: translateY(30px) rotate(-3deg) scale(.94); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* level ribbon */
.card-ribbon {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 18px; color: #FFF6E8;
}
.lv1 .card-ribbon { background: linear-gradient(120deg, #3B66C9, #284B9B); }
.lv2 .card-ribbon { background: linear-gradient(120deg, #E6A137, #CA861B); color: var(--ink); }
.lv3 .card-ribbon { background: linear-gradient(120deg, #B83A28, #8F2115); }
.ribbon-level { font-weight: 900; font-size: 13.5px; letter-spacing: .5px; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.ribbon-tools { display: flex; gap: 7px; }
.ribbon-tools button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 44px; min-height: 44px; }
.ribbon-tools .icon { width: 15px; height: 15px; }
.ribbon-tools .tts-btn, .ribbon-tools .translate-btn {
  background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.55); color: #FFF6E8;
}
.ribbon-tools .tts-btn:hover, .ribbon-tools .translate-btn:hover {
  background: rgba(255,255,255,.38); border-color: #fff;
}
.lv2 .ribbon-tools .tts-btn, .lv2 .ribbon-tools .translate-btn {
  background: rgba(51,38,28,.10); border-color: rgba(51,38,28,.45); color: var(--ink);
}
.lv2 .ribbon-tools .tts-btn:hover, .lv2 .ribbon-tools .translate-btn:hover {
  background: rgba(51,38,28,.18); border-color: var(--ink);
}

/* the four characters as tiles */
.card-body { padding: 20px 22px 22px; }
.hz-tiles { display: flex; gap: 10px; margin: 4px 0 6px; }
.hz-tile {
  flex: 1; text-align: center;
  background: rgba(255,255,255,.62); border: 2px solid var(--line); border-radius: 16px;
  padding: 16px 4px 11px;
  box-shadow: 0 6px 14px rgba(120, 80, 40, .10), inset 0 -4px 0 rgba(120, 80, 40, .05);
  transition: transform .15s;
}
.hz-tile:hover { transform: translateY(-4px) rotate(-1.5deg); }
.hz-tile b { display: block; font-size: 36px; font-weight: 900; line-height: 1.15; }
.hz-tile i { display: block; margin-top: 5px; font-style: normal; font-size: 12px; font-weight: 800; color: var(--red-dark); white-space: nowrap; }
.hz-tile i.name-gloss { color: var(--purple-text); border-bottom: 2px dotted var(--purple-text); cursor: help; }
.pinyin-line { font-style: italic; color: var(--muted); font-weight: 700; font-size: 13.5px; margin: 10px 0 2px; }
.pinyin { color: var(--muted); font-size: 13px; font-weight: 700; font-style: italic; }
.hanzi { font-size: 30px; font-weight: 900; letter-spacing: 3px; }
.idiom-card .en { font-size: 14.5px; line-height: 1.6; margin-top: 4px; }
.char-note { font-size: 12.5px; color: var(--purple-text); margin: 8px 0; line-height: 1.5; font-weight: 600; }

.level-badge {
  display: inline-block; font-size: 11.5px; font-weight: 900; letter-spacing: .6px;
  padding: 4px 12px; border-radius: 999px; margin-top: 12px; color: #fff;
}
.lv1 .level-badge { background: linear-gradient(135deg, #3B66C9, #284B9B); }
.lv2 .level-badge { background: linear-gradient(135deg, #E6A137, #CA861B); color: var(--ink); }
.lv3 .level-badge { background: linear-gradient(135deg, #B83A28, #8F2115); }
.level-badge.txt-zh { margin-top: 6px; }

/* detail */
.detail {
  display: grid; grid-template-rows: 0fr; overflow: hidden;
  transition: grid-template-rows .28s ease; font-size: 13.5px;
}
.idiom-card.open .detail, .detail.open-always { grid-template-rows: 1fr; }
.detail-inner { min-height: 0; overflow: hidden; }
.detail-inner > div { margin-top: 14px; padding-top: 14px; border-top: 1.5px dashed rgba(255,255,255,.8); }
.detail .label {
  font-size: 10.5px; font-weight: 900; letter-spacing: 1.4px; color: var(--muted);
  text-transform: uppercase; margin-bottom: 6px; display: block;
}
.example-hanzi { font-size: 18px; font-weight: 800; }
.detail .warn { color: var(--red-dark); }
.learn-more {
  width: 100%; margin-top: 14px; padding: 10px 14px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1.5px solid rgba(51,38,28,.28); border-radius: 12px;
  background: rgba(255,255,255,.48); color: var(--ink);
  cursor: pointer; font: inherit; font-size: 13px; font-weight: 800;
  transition: background .14s, border-color .14s;
}
.learn-more .icon { width: 16px; height: 16px; }
.learn-more:hover { background: rgba(255,255,255,.78); border-color: rgba(51,38,28,.55); }

/* language toggle */
.idiom-card .txt-zh, .idiom-card .lbl-zh { display: none; }
.idiom-card.zh .txt-en { display: none; }
.idiom-card.zh .txt-zh { display: block; }
.idiom-card.zh .lbl-en { display: none; }
.idiom-card.zh .lbl-zh { display: inline; }
.idiom-card.zh .lit { display: none; }

/* dialogue bubbles */
.dialogue { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.dlg-line {
  background: rgba(255,255,255,.45); border: 1.5px solid var(--line); border-radius: 16px;
  border-bottom-left-radius: 5px; padding: 12px 15px;
  font-size: 15.5px; line-height: 1.55;
}
.dlg-line.reply {
  background: linear-gradient(135deg, rgba(255, 214, 140, .5), rgba(255, 190, 120, .38));
  border-color: rgba(233, 161, 59, .45);
  border-bottom-left-radius: 16px; border-bottom-right-radius: 5px;
  font-weight: 800; font-size: 16.5px;
}
.dlg-badge { margin-right: 7px; }
.lit-words {
  margin-top: 10px; font-size: 14.5px; font-weight: 900; color: var(--red-dark);
  letter-spacing: 1px;
}

/* ---------- arena ---------- */
.card {
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1.5px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.intro h2 { margin-bottom: 12px; font-weight: 900; }
.intro > p { color: var(--muted); line-height: 1.7; margin-bottom: 20px; font-weight: 600; }
.opponent-pick p { margin-bottom: 12px; font-weight: 800; }
.opponents { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.opponent {
  background: rgba(255,255,255,.45); border: 1.5px solid var(--line); border-radius: 16px; color: var(--ink);
  padding: 18px; cursor: pointer; font-size: 15px; font-weight: 800; text-align: left; line-height: 1.45;
  font-family: inherit; transition: transform .14s, border-color .14s, box-shadow .14s;
}
.opponent small { color: var(--muted); font-weight: 600; }
.opponent:hover { border-color: var(--red); transform: translateY(-3px) rotate(-.6deg); box-shadow: var(--shadow); }

.battle-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px; font-size: 14.5px; font-weight: 800;
}
#round-indicator { color: var(--muted); }
.hp-bars { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 340px; }
.hp { flex: 1; height: 12px; border-radius: 999px; background: rgba(255,255,255,.5); overflow: hidden; border: 1px solid var(--line); }
.you-hp i { float: right; }
.hp i { display: block; height: 100%; background: linear-gradient(90deg, #4FC08D, #3FA37C); border-radius: 999px; transition: width .4s; }
.hp i.hurt { background: linear-gradient(90deg, #E8543F, #C22F1D); }
.vs { font-size: 11px; font-weight: 900; color: var(--muted); }

#chat-log {
  display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px;
  max-height: 44vh; overflow-y: auto; padding: 4px;
}
.msg { max-width: 86%; padding: 13px 17px; border-radius: 18px; line-height: 1.55; font-size: 14.5px; border: 1.5px solid var(--line); background: rgba(255,255,255,.5); }
.msg.opp { align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.you { background: var(--jade-soft); border-color: rgba(63,163,124,.35); align-self: flex-end; border-bottom-right-radius: 5px; }
.msg .zh { font-size: 17.5px; font-weight: 800; display: block; }
.msg .en { color: var(--muted); font-size: 13px; display: block; margin-top: 4px; font-weight: 600; }
.msg .verdict { display: block; margin-top: 10px; font-size: 13px; font-weight: 800; }
.verdict.hit { color: var(--jade); }
.verdict.miss { color: var(--red); }
.verdict.over { color: #C77C14; }
.msg .used-idiom { display: inline-block; background: var(--gold-soft); color: var(--red); font-weight: 900; padding: 2px 9px; border-radius: 8px; margin-right: 6px; }

#hand { display: flex; flex-direction: column; gap: 10px; }
.hand-title { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.4px; font-weight: 900; }
.hand-cards { display: flex; flex-wrap: wrap; gap: 9px; }
.play-card {
  background: var(--glass); color: var(--ink); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 11px 15px; cursor: pointer; text-align: left; font-size: 14px; font-family: inherit;
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  box-shadow: 0 4px 12px rgba(120, 80, 40, .10);
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.play-card:hover { transform: translateY(-4px) rotate(-.8deg); border-color: var(--gold); box-shadow: var(--shadow); }
.play-card:active { transform: translateY(1px); }
.play-card b { display: block; font-size: 16.5px; }
.play-card small { color: var(--muted); font-size: 11.5px; font-weight: 700; }
#battle-controls { margin-top: 16px; display: flex; justify-content: flex-end; }

/* ---------- buttons ---------- */
button.primary, button.ghost {
  padding: 13px 28px; border-radius: 999px; cursor: pointer;
  font-size: 15px; font-weight: 900; font-family: inherit;
  transition: transform .09s, box-shadow .09s, filter .12s;
}
button.primary {
  background: linear-gradient(135deg, #B83A28 0%, #9C2B1D 48%, #7F2017 100%);
  border: none; color: #FFF6E8;
  box-shadow: 0 7px 0 var(--red-dark), 0 16px 32px rgba(200, 60, 40, .30);
  text-shadow: 0 1px 0 rgba(0,0,0,.15);
}
button.primary:hover { filter: brightness(1.07) saturate(1.1); transform: translateY(-2px); }
button.primary:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--red-dark); }
button.primary:disabled { filter: grayscale(.6); opacity: .6; cursor: not-allowed; }
button.ghost {
  background: var(--glass); border: 1.5px solid var(--line); color: var(--muted);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
button.ghost:hover { color: var(--ink); border-color: var(--muted); transform: translateY(-2px); }
#btn-reset-test {
  padding: 9px 16px;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- report ---------- */
#report-card { text-align: center; }
#report-card h2 { margin-bottom: 16px; font-weight: 900; }
#report-body { text-align: left; color: var(--ink); line-height: 1.7; margin-bottom: 20px; font-size: 14.5px; }
#report-body .grade { font-size: 52px; font-weight: 900; text-align: center; display: block; margin: 8px 0; }
#report-body ul { margin: 10px 0 0 20px; }
#report-body li { margin-bottom: 6px; }
.report-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.hidden { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important; border: 0 !important;
}
.zh-sub {
  display: block; margin-top: 2px;
  color: var(--muted); font-size: max(.72em, 11px); font-weight: 700;
  line-height: 1.25; letter-spacing: 0; text-transform: none;
}
@media (max-width: 640px) {
  .tabitem .zh-sub { display: none; }
}
.tab.active .zh-sub, button.primary .zh-sub { color: inherit; }

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

/* ---------- Chengyu Token Quiz ---------- */
.wallet {
  background: var(--glass); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 8px 16px; font-weight: 900; font-size: 14px; color: var(--ink);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 14px rgba(120, 80, 40, .10);
  cursor: default; user-select: none;
}
.quiz-sub { text-align: center; color: var(--muted); font-weight: 600; max-width: 560px; margin: 0 auto; line-height: 1.6; }
.quiz-attempts { text-align: center; color: var(--muted); font-weight: 700; font-size: 13.5px; margin-top: 22px; }
.quiz-stage { display: flex; flex-direction: column; gap: 18px; max-width: 640px; margin: 0 auto; }
.quiz-scene .dialogue { margin-top: 10px; }
.quiz-ask { margin-top: 12px; font-weight: 800; font-size: 15.5px; }
.quiz-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.quiz-options .play-card { text-align: center; padding: 16px 12px; }
.quiz-options .play-card b { font-size: 22px; letter-spacing: 2px; }
.quiz-options .play-card small { display: block; margin-top: 6px; font-size: 12px; }
.quiz-options .play-card.right { border-color: var(--jade); background: var(--jade-soft); animation: pop .35s; }
.quiz-options .play-card.wrong { border-color: var(--red); background: var(--l3-soft); }
@keyframes pop { 0%{transform:scale(.92)} 60%{transform:scale(1.06)} 100%{transform:scale(1)} }

#q-hard-box { display: flex; flex-direction: column; gap: 12px; }
#q-input {
  width: 100%; padding: 16px 20px; border-radius: 16px; font-size: 18px;
  font-family: inherit; font-weight: 700; text-align: center; letter-spacing: 1px;
  background: rgba(255,255,255,.6); border: 2px solid var(--line); color: var(--ink);
  transition: border-color .15s;
}
#q-input:focus { border-color: var(--gold); background: #fff; }
#q-input::placeholder { color: var(--muted); font-weight: 600; font-size: 14px; }
.hard-tools { display: flex; gap: 10px; justify-content: center; }

.quiz-result { text-align: center; animation: drawIn .35s cubic-bezier(.34,1.56,.64,1); }
.res-head { font-size: 22px; font-weight: 900; margin-bottom: 10px; justify-content: center; }
.res-head .icon { width: 22px; height: 22px; }
.res-head.ok { color: var(--jade); }
.res-head.no { color: var(--red); }
.res-earn { font-weight: 900; color: var(--gold-text); font-size: 17px; margin: 6px 0; }
.res-earn.dim { color: var(--muted); }
.res-explain { color: var(--ink); font-weight: 600; line-height: 1.6; font-size: 14px; }
.quiz-result .pinyin { display: inline-block; margin-left: 6px; }

footer {
  text-align: center; padding: 18px; color: var(--muted); font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.3);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass: rgba(255,255,255,.88); --glass-strong: rgba(255,255,255,.94); }
  header, .tab, .mode-card, .idiom-card, .card, .wallet, .free-count,
  .play-card, .msg, button.ghost, footer {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  header, footer { background: rgba(255,255,255,.90); }
}

@media (prefers-reduced-transparency: reduce) {
  :root { --glass: rgba(255,255,255,.90); --glass-strong: rgba(255,255,255,.96); }
  header, .tab, .mode-card, .idiom-card, .card, .wallet, .free-count,
  .play-card, .msg, button.ghost, footer {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  header, footer { background: rgba(255,255,255,.94); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 640px) {
  header { align-items: center; padding: calc(12px + max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px))) 16px 12px; gap: 10px; flex-wrap: nowrap; }
  .brand { width: auto; flex: 1; min-width: 0; }
  .tagline { display: none; }
  h1 { font-size: 19px; }
  nav { margin-left: auto; }
  .logo { width: 36px; height: 36px; font-size: 22px; }
  main { padding: 16px 14px calc(84px + max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px))); }
  .msg { max-width: 95%; }
  .hanzi { font-size: 24px; }
  .draw-title { font-size: 25px; }
  .modes { flex-direction: column; }
  .hard-tools { flex-wrap: wrap; }
  .hard-tools button { flex: 1 1 150px; }
}

/* ---------- App shell: bottom tab bar + Me page (mobile-first) ---------- */

html, body { overscroll-behavior: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex;
  background: var(--glass-strong);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border-top: 1.5px solid var(--line);
  padding: 8px 10px calc(10px + max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px)));
}
.tabitem {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 11.5px; font-weight: 800; color: var(--muted);
  padding: 6px 0 4px; border-radius: 14px;
  transition: color .14s, background .14s;
}
.tabitem .icon { width: 22px; height: 22px; }
.tabitem.active { color: var(--red); background: var(--gold-soft); }
.tabitem:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.me-wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.me-card {
  background: var(--glass-strong); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 6px 16px;
  box-shadow: var(--shadow);
}
.me-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 14px 2px;
  background: none; border: none; cursor: default;
  font-family: inherit; font-size: 15px; font-weight: 800; color: var(--ink);
  border-bottom: 1px solid rgba(120, 80, 40, .10);
  text-align: left;
}
.me-card > :last-child { border-bottom: none; }
.me-row .zh-sub { display: inline; margin: 0 0 0 6px; }
.me-row .wallet { padding: 4px 10px; font-size: 13px; }
.me-row.me-link { cursor: pointer; transition: background .14s; border-radius: 10px; }
.me-row.me-link:hover { background: var(--gold-soft); }
.me-row .chev { margin-left: auto; color: var(--muted); font-size: 20px; font-weight: 900; }
.me-row.dim { color: var(--muted); font-weight: 700; font-size: 13.5px; }
.me-note { font-size: 13px; color: var(--muted); font-weight: 700; text-align: center; line-height: 1.5; }
.privacy-text { padding: 18px 18px 10px; font-size: 14px; font-weight: 600; line-height: 1.65; }
.privacy-text p { margin-bottom: 12px; }
.privacy-text b { font-weight: 900; }
#btn-privacy-back { align-self: flex-start; }
.test-reset { color: var(--red); }

/* ---------- Favorites ---------- */

.fav-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.42); border: 1px solid rgba(255,255,255,.72);
  border-radius: 10px; padding: 5px 12px; cursor: pointer; color: var(--ink);
  min-width: 44px; min-height: 44px;
  transition: color .14s, background .14s, transform .14s;
}
.fav-btn .icon { width: 17px; height: 17px; }
.fav-btn:hover { transform: scale(1.08); }
.fav-btn.active { color: var(--red); background: rgba(200,64,46,.10); border-color: rgba(200,64,46,.35); }
.fav-btn.active .icon { fill: var(--red); }

.me-favs h3 { font-size: 16px; font-weight: 900; margin-top: 4px; }
.fav-list { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.fav-empty {
  font-size: 13.5px; color: var(--muted); font-weight: 700;
  padding: 12px 4px; line-height: 1.5;
}

/* ---------- Share button (mirrors fav-btn) ---------- */

.share-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.42); border: 1px solid rgba(255,255,255,.72);
  border-radius: 10px; padding: 5px 12px; cursor: pointer; color: var(--ink);
  min-width: 44px; min-height: 44px;
  transition: color .14s, background .14s, transform .14s;
}
.share-btn .icon { width: 17px; height: 17px; }
.share-btn:hover { transform: scale(1.08); background: var(--gold-soft); }

/* ---------- dark mode (follows system preference) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #F0E6D8;
    --muted: #B3A28D;
    --line: rgba(255, 255, 255, .14);
    --glass: rgba(42, 36, 30, .55);
    --glass-strong: rgba(48, 41, 34, .78);
    --gold-soft: rgba(233, 161, 59, .16);
    --jade-soft: rgba(111, 205, 167, .14);
    --l3-soft: rgba(216, 67, 47, .22);
    --red: #E86A55;
    --red-dark: #F0876F;
    --gold-text: #E9B45C;
    --purple-text: #C9A5F0;
    --shadow: 0 8px 32px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .45);
    --focus: #FF8A70;
  }
  body {
    background:
      radial-gradient(560px 420px at 8% -6%,  rgba(216, 67, 47, .12), transparent 65%),
      radial-gradient(640px 480px at 96% 4%,  rgba(233, 161, 59, .10), transparent 65%),
      radial-gradient(620px 500px at -6% 78%, rgba(63, 163, 124, .10), transparent 65%),
      radial-gradient(560px 460px at 92% 96%, rgba(155, 107, 216, .08), transparent 65%),
      linear-gradient(160deg, #1E1813, #181310 55%, #14100C);
  }
  header, footer { background: rgba(30, 24, 18, .60); }
  .mode-card, .dlg-line, .msg, .upsell,
  .learn-more, #q-input { background: rgba(42, 36, 30, .60); border-color: var(--line); }
  .learn-more:hover { background: rgba(58, 49, 40, .80); border-color: rgba(240, 230, 216, .35); }
  .fav-btn, .share-btn { background: rgba(42, 36, 30, .60); border-color: rgba(255, 255, 255, .18); }
  .hp { background: rgba(255, 255, 255, .10); }
  .detail-inner > div { border-top-color: rgba(255, 255, 255, .14); }
  #q-input:focus { background: #2A241E; }
  .dlg-line.reply {
    background: linear-gradient(135deg, rgba(233, 161, 59, .20), rgba(255, 190, 120, .12));
    border-color: rgba(233, 161, 59, .35);
  }
}
@media (prefers-color-scheme: dark) and (prefers-reduced-transparency: no-preference) {
  :root { --glass: rgba(42, 36, 30, .55); --glass-strong: rgba(48, 41, 34, .78); }
}

/* ---------- desktop two-column adaptation (≥1020px) ---------- */
@media (min-width: 1020px) {
  .quiz-stage {
    max-width: 1020px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
  .quiz-stage .quiz-scene { grid-column: 1; grid-row: 1 / span 4; position: sticky; top: 86px; }
  .quiz-stage > #q-options,
  .quiz-stage > #q-hard-box,
  .quiz-stage > #q-result,
  .quiz-stage > #quiz-controls { grid-column: 2; }

  /* two columns only once a card is on the table; pre-draw stays centered */
  .draw-stage:has(#card-slot > .idiom-card) {
    display: grid;
    grid-template-columns: minmax(0, 460px) minmax(260px, 1fr);
    justify-content: center;
    align-items: start;
    max-width: 1020px;
  }
  .draw-stage:has(#card-slot > .idiom-card) > #card-slot { grid-column: 1; grid-row: 1 / span 2; }
  .draw-stage:has(#card-slot > .idiom-card) > #draw-controls { grid-column: 2; grid-row: 1; align-self: center; }
  .draw-stage:has(#card-slot > .idiom-card) > #upsell { grid-column: 2; grid-row: 2; }
}
