/* 漢字小英雄：水墨練字房主題 */
:root {
  --bg: #f5efe2;
  --bg-2: #e7dcc6;
  --ink: #221d17;
  --muted: #6f6253;
  --accent: #c8402f;
  --accent-2: #3f6b57;
  --accent-3: #d9b86c;
  --good: #3f6b57;
  --bad: #b23a2a;
  --card: #fbf6ea;
  --line: #2a241d;
  --line-soft: rgba(42, 36, 29, 0.18);
  --shadow: 0 7px 0 rgba(42, 36, 29, 0.12), 0 18px 38px rgba(42, 36, 29, 0.14);
  --shadow-sm: 0 4px 0 rgba(42, 36, 29, 0.16);
  --radius: 22px;
  --radius-sm: 14px;
  --font-body: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  --font-display: "Songti TC", "Noto Serif TC", "PMingLiU", "MingLiU", serif;
  --font-zhuyin: "BpmfHuninn", "PingFang TC", "Noto Sans TC", sans-serif;
  --seal: #c8402f;
  --paper: #fbf6ea;
  --bamboo: #3f6b57;
  --gold: #d9b86c;
}

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 8% 4%, rgba(255, 255, 255, 0.72) 0 16%, transparent 46%),
    radial-gradient(circle at 92% 10%, rgba(63, 107, 87, 0.12) 0 12%, transparent 42%),
    radial-gradient(circle at 48% 108%, rgba(200, 64, 47, 0.1) 0 18%, transparent 52%),
    repeating-linear-gradient(0deg, rgba(90, 70, 40, 0.028) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(90deg, rgba(90, 70, 40, 0.022) 0 1px, transparent 1px 7px);
  background-attachment: fixed;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(2px);
}

body::before {
  width: 46vw;
  height: 46vw;
  top: -22vw;
  right: -18vw;
  background: radial-gradient(circle, rgba(63, 107, 87, 0.16), transparent 68%);
}

body::after {
  width: 40vw;
  height: 40vw;
  bottom: -20vw;
  left: -16vw;
  background: radial-gradient(circle, rgba(200, 64, 47, 0.09), transparent 70%);
}

.topbar,
main,
.site-footer {
  position: relative;
  z-index: 1;
}

/* ---------- 筆墨工具列 ---------- */
.topbar {
  background: rgba(245, 239, 226, 0.92);
  border-bottom: 2.5px solid var(--line);
  box-shadow: 0 3px 0 rgba(42, 36, 29, 0.08);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -7px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--seal) 12%, var(--seal) 28%, transparent 46%, var(--bamboo) 72%, transparent);
  opacity: 0.75;
}

.brand-name {
  font-family: var(--font-display);
  font-size: clamp(17px, 2.5vw, 21px);
  letter-spacing: 0.14em;
}

.brand-dot {
  width: 17px;
  height: 17px;
  border: 2.5px solid var(--line);
  border-radius: 3px;
  background: var(--seal);
  box-shadow: inset 0 0 0 2.5px var(--paper), 2px 2px 0 rgba(42, 36, 29, 0.18);
  transform: rotate(-6deg);
}

.icon-btn {
  border-width: 2.5px;
  border-radius: 12px;
  background: var(--paper);
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--gold) 36%, var(--paper));
  transform: translateY(-2px);
}

.icon-btn-zhuyin {
  font-family: var(--font-body);
  color: var(--seal);
}

/* ---------- 首頁 ---------- */
.hero-title {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-shadow: 2px 3px 0 rgba(217, 184, 108, 0.32);
}

.hero-title::after {
  content: "";
  display: inline-block;
  width: 0.24em;
  height: 0.24em;
  margin-left: 0.18em;
  border: 2px solid var(--line);
  border-radius: 2px;
  background: var(--seal);
  box-shadow: inset 0 0 0 2px var(--paper);
  transform: rotate(-8deg) translateY(-0.18em);
}

.eyebrow {
  color: var(--seal);
  font-weight: 900;
  letter-spacing: 0.2em;
}

.hero-desc {
  color: #5f5446;
  line-height: 1.85;
}

.hero-art {
  min-height: min(52vw, 440px);
  isolation: isolate;
}

.hero-art .hero-scene {
  position: absolute;
  inset: 3% 1% 5%;
  z-index: 0;
  width: 98%;
  height: 92%;
  max-width: none;
  object-fit: cover;
  border: 3px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  filter: saturate(0.92) contrast(1.02);
  transform: rotate(2deg);
  animation: none;
}

.hero-blob {
  inset: 10% 5%;
  z-index: 0;
  border: 0;
  background: radial-gradient(circle at 40% 30%, rgba(255, 255, 255, 0.6), rgba(217, 184, 108, 0.28) 46%, rgba(63, 107, 87, 0.18) 72%, transparent 76%);
  box-shadow: none;
  opacity: 0.85;
}

.hero-art #home-mascot {
  z-index: 2;
  width: min(76%, 390px);
  margin-top: 9%;
  filter: drop-shadow(0 18px 16px rgba(32, 25, 18, 0.28));
}

.hero-sticker {
  right: 0;
  bottom: 1%;
  z-index: 3;
  padding: 9px 16px;
  border: 2.5px solid var(--line);
  border-radius: 4px;
  background: var(--seal);
  color: #fff8ec;
  box-shadow: inset 0 0 0 3px rgba(255, 248, 236, 0.28), 4px 5px 0 rgba(42, 36, 29, 0.18);
  font-family: var(--font-body);
  font-size: clamp(13px, 1.7vw, 16px);
  font-weight: 800;
  letter-spacing: 0.16em;
  transform: rotate(-4deg);
}

.card {
  border: 2.5px solid var(--line);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 100% 0%, rgba(217, 184, 108, 0.16), transparent 34%),
    repeating-linear-gradient(0deg, rgba(90, 70, 40, 0.022) 0 1px, transparent 1px 6px);
  box-shadow: var(--shadow-sm);
}

.howto {
  position: relative;
  overflow: hidden;
}

.howto::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 82px;
  height: 82px;
  background: linear-gradient(135deg, var(--seal) 0 50%, transparent 50%);
  opacity: 0.14;
}

.section-title,
.screen-title {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
}

.howto-list {
  counter-reset: howto;
  list-style: none;
  padding-left: 0;
}

.howto-list li {
  position: relative;
  padding-left: 38px;
  line-height: 1.8;
}

.howto-list li::before {
  counter-increment: howto;
  content: counter(howto);
  position: absolute;
  left: 0;
  top: 0.15em;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--gold);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

/* ---------- 按鈕 ---------- */
.btn {
  border-width: 2.5px;
  border-radius: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.btn-primary {
  background: var(--seal);
  color: #fff8ec;
  box-shadow: 0 5px 0 #7f281e, 0 10px 18px rgba(42, 36, 29, 0.14);
}

.btn-primary:hover {
  background: #d24a37;
  transform: translateY(-2px);
}

.btn-ghost {
  background: var(--paper);
  color: var(--ink);
  border: 2.5px solid var(--line);
  box-shadow: 0 5px 0 rgba(42, 36, 29, 0.16);
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--gold) 30%, var(--paper));
}

.btn-soft {
  background: color-mix(in srgb, var(--bamboo) 16%, var(--paper));
  border: 2.5px solid var(--line);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(42, 36, 29, 0.14);
}

.btn-danger {
  background: #8d2d22;
  color: #fff8ec;
}

.btn-link {
  color: var(--bamboo);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- 關卡選單 ---------- */
.level-card {
  border-width: 2.5px;
  border-radius: 16px;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(0deg, rgba(90, 70, 40, 0.024) 0 1px, transparent 1px 6px);
}

.level-card::before {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--seal);
  opacity: 0.7;
}

.level-card:not(:disabled):hover {
  border-color: var(--seal);
}

.level-card[data-current="true"] {
  background: color-mix(in srgb, var(--gold) 34%, var(--paper));
  border-color: var(--seal);
}

.level-num {
  border-width: 2px;
  border-radius: 8px;
  background: var(--bamboo);
  letter-spacing: 0.06em;
}

.level-stars .on {
  color: var(--seal);
  text-shadow: 0 1px 0 rgba(42, 36, 29, 0.28);
}

.level-lock {
  filter: grayscale(1);
  opacity: 0.55;
}

/* ---------- 遊戲進行 ---------- */
.play-kicker {
  color: var(--seal);
  font-weight: 900;
  letter-spacing: 0.16em;
}

.play-title {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
}

.play-objective {
  color: var(--muted);
}

.hud-item {
  border: 2px solid var(--line);
  background: var(--paper);
}

.hud-label {
  color: var(--muted);
  letter-spacing: 0.08em;
}

.hud-item strong {
  color: var(--seal);
  font-family: var(--font-display);
}

.timer {
  border: 2.5px solid var(--line);
  background: color-mix(in srgb, var(--ink) 8%, var(--paper));
}

.timer-fill {
  background: linear-gradient(90deg, var(--bamboo), var(--gold));
}

.timer.is-low .timer-fill {
  background: linear-gradient(90deg, var(--seal), #e07b4a);
}

.timer-text {
  font-family: var(--font-display);
  color: var(--ink);
}

.q-progress .q-dot {
  background: rgba(42, 36, 29, 0.16);
}

.q-progress .q-dot.done {
  background: var(--bamboo);
}

.q-progress .q-dot.now {
  background: var(--seal);
  transform: scale(1.35);
}

.question-host {
  position: relative;
  overflow: hidden;
  border-width: 2.5px;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 100% 100%, rgba(63, 107, 87, 0.08), transparent 40%),
    repeating-linear-gradient(0deg, rgba(90, 70, 40, 0.022) 0 1px, transparent 1px 6px);
}

.question-host::before {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 12px;
  width: 130px;
  height: 130px;
  border: 2px dashed rgba(42, 36, 29, 0.11);
  border-radius: 6px;
  background-image:
    linear-gradient(to right, transparent 49.4%, rgba(42, 36, 29, 0.1) 49.4% 50.6%, transparent 50.6%),
    linear-gradient(to bottom, transparent 49.4%, rgba(42, 36, 29, 0.1) 49.4% 50.6%, transparent 50.6%);
  pointer-events: none;
}

.question-host > * {
  position: relative;
  z-index: 1;
}

.hanzi-prompt {
  color: var(--ink);
}

.hanzi-badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: var(--seal);
  color: #fff8ec;
  box-shadow: inset 0 0 0 2px rgba(255, 248, 236, 0.24);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.22em;
  transform: rotate(-1.5deg);
}

.hanzi-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* 田字格 */
.hanzi-stage,
.compare-stage,
.word-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vw, 22px);
  margin: 10px 0 6px;
}

.tian-grid {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(132px, 27vw, 196px);
  aspect-ratio: 1;
  border: 4px solid var(--ink);
  border-radius: 6px;
  background: #fdf9ef;
  box-shadow: inset 0 0 0 2px rgba(42, 36, 29, 0.12), 5px 6px 0 rgba(42, 36, 29, 0.13);
  overflow: hidden;
}

.tian-grid::before,
.tian-grid::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.tian-grid::before {
  left: 50%;
  top: 0;
  bottom: 0;
  border-left: 2px dashed rgba(200, 64, 47, 0.38);
}

.tian-grid::after {
  top: 50%;
  left: 0;
  right: 0;
  border-top: 2px dashed rgba(200, 64, 47, 0.38);
}

.tian-grid .tian-char {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(78px, 16vw, 124px);
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
  text-shadow: 2px 2px 0 rgba(217, 184, 108, 0.22);
  animation: ink-in 420ms ease both;
}

body.zhuyin-on .tian-grid .tian-char[data-zy] {
  font-family: var(--font-zhuyin);
  font-size: clamp(66px, 13vw, 108px);
  font-weight: 400;
  line-height: 1.5;
  padding-top: 0.1em;
  text-shadow: none;
}

.tian-grid-compare {
  width: clamp(112px, 22vw, 164px);
}

.tian-grid-order .tian-char {
  color: var(--ink);
}

.compare-vs {
  align-self: center;
  padding: 5px 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  transform: rotate(-3deg);
}

@keyframes ink-in {
  from {
    opacity: 0;
    transform: scale(0.82) rotate(-2deg);
    filter: blur(2px);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
    filter: blur(0);
  }
}

/* 筆畫示範 */
.stroke-stage {
  display: grid;
  place-items: center;
  gap: 2px;
  margin: 4px 0 8px;
}

.stroke-figure {
  width: min(46vw, 220px);
  height: auto;
  overflow: visible;
}

.stroke-glow {
  fill: none;
  stroke: rgba(200, 64, 47, 0.16);
  stroke-width: 34;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stroke-ink {
  fill: none;
  stroke: var(--ink);
  stroke-width: 20;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  animation: brush-draw 780ms cubic-bezier(0.4, 0.05, 0.2, 1) forwards;
}

@keyframes brush-draw {
  to {
    stroke-dashoffset: 0;
  }
}

.stroke-caption {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* 部件組合 */
.parts-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5vw, 14px);
  margin: 8px 0 12px;
}

.parts-chip {
  display: grid;
  place-items: center;
  min-width: clamp(66px, 15vw, 92px);
  min-height: clamp(66px, 15vw, 92px);
  padding: 6px;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 4px 5px 0 rgba(42, 36, 29, 0.12);
}

.parts-char {
  font-family: var(--font-display);
  font-size: clamp(34px, 7vw, 50px);
  font-weight: 900;
  line-height: 1;
}

body.zhuyin-on .parts-char[data-zy] {
  font-family: var(--font-zhuyin);
  font-size: clamp(30px, 6vw, 44px);
  font-weight: 400;
  line-height: 1.5;
}

.parts-plus,
.parts-equals {
  color: var(--seal);
  font-family: var(--font-display);
  font-size: clamp(24px, 5vw, 38px);
  font-weight: 900;
}

.parts-mystery {
  border-style: dashed;
  border-color: var(--seal);
  background: color-mix(in srgb, var(--gold) 18%, var(--paper));
}

.parts-mystery .parts-char {
  color: var(--seal);
}

/* 句子填空 */
.sentence-card {
  margin: 10px 0 6px;
  padding: clamp(14px, 3vw, 22px);
  border: 2.5px dashed rgba(42, 36, 29, 0.34);
  border-radius: 12px;
  background: color-mix(in srgb, var(--gold) 13%, var(--paper));
  font-family: var(--font-display);
  font-size: clamp(23px, 4.2vw, 34px);
  font-weight: 900;
  line-height: 2;
  letter-spacing: 0.06em;
  text-align: center;
}

body.zhuyin-on .sentence-card[data-zy] {
  font-family: var(--font-zhuyin);
  font-weight: 400;
  line-height: 2.5;
}

/* 大字詞 */
.word-display {
  display: inline-block;
  padding: 0.08em 0.35em 0.16em;
  border-bottom: 5px solid var(--seal);
  font-family: var(--font-display);
  font-size: clamp(52px, 12vw, 92px);
  font-weight: 900;
  line-height: 1.35;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(217, 184, 108, 0.24);
}

body.zhuyin-on .word-display[data-zy] {
  font-family: var(--font-zhuyin);
  font-size: clamp(46px, 10vw, 84px);
  font-weight: 400;
  line-height: 1.6;
  padding-top: 0.12em;
  text-shadow: none;
}

/* 部首提示 */
.radical-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 4px 10px;
  border: 2px solid var(--bamboo);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bamboo) 12%, var(--paper));
  color: var(--bamboo);
  font-size: 13px;
  font-weight: 900;
}

.radical-value {
  font-family: var(--font-display);
  font-size: 22px;
}

body.zhuyin-on .radical-value[data-zy] {
  font-family: var(--font-zhuyin);
  font-size: 20px;
}

/* 選項 */
.hanzi-choices {
  margin-top: 14px;
}

.hanzi-choice {
  border-width: 2.5px;
  border-radius: 12px;
  background: var(--paper);
}

.hanzi-choice:hover:not(:disabled) {
  background: color-mix(in srgb, var(--gold) 30%, var(--paper));
  border-color: var(--seal);
}

.hanzi-choice.correct {
  border-color: var(--bamboo);
  box-shadow: 0 5px 0 var(--bamboo);
  background: color-mix(in srgb, var(--bamboo) 16%, white);
}

.hanzi-choice.wrong {
  border-color: var(--bad);
  box-shadow: 0 5px 0 var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, white);
}

.choices-one {
  grid-template-columns: 1fr;
}

.choices-numbers {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choice-label {
  font-family: var(--font-display);
  font-size: clamp(19px, 3.2vw, 27px);
  font-weight: 900;
  letter-spacing: 0.04em;
}

.choice-number-label,
.choice-number {
  font-family: var(--font-display);
  font-size: clamp(23px, 4vw, 34px);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.choice-zhuyin {
  font-family: var(--font-body);
  font-size: clamp(24px, 4.8vw, 38px);
  font-weight: 700;
  letter-spacing: 0.14em;
}

.choice-big {
  font-size: clamp(28px, 5.6vw, 44px);
}

/* ---------- 回饋、結果、頁尾 ---------- */
.feedback-burst {
  border: 3px solid var(--line);
  background: var(--paper);
  box-shadow: 0 10px 0 rgba(42, 36, 29, 0.16), 0 24px 50px rgba(42, 36, 29, 0.2);
}

.feedback-burst.bad {
  background: #fff3ef;
}

.feedback-text {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
}

.feedback-explain {
  color: var(--muted);
}

.result-card {
  border: 3px solid var(--line);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 100% 0%, rgba(200, 64, 47, 0.1), transparent 36%);
}

.result-title {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
}

.star.on {
  color: var(--seal);
  text-shadow: 0 2px 0 var(--line);
}

.result-stats strong {
  color: var(--seal);
  font-family: var(--font-display);
}

.toast {
  border: 2.5px solid var(--line);
  background: var(--paper);
  font-weight: 900;
}

.site-footer {
  border-top: 2.5px solid var(--line);
  background: rgba(245, 239, 226, 0.86);
  color: var(--muted);
}

.site-footer a {
  color: var(--seal);
}

/* ---------- 動畫 ---------- */
.feedback-burst {
  animation: seal-pop 260ms cubic-bezier(0.2, 0.9, 0.2, 1.4);
}

@keyframes seal-pop {
  from {
    opacity: 0;
    transform: scale(0.78) rotate(-3deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.screen-enter {
  animation: paper-in 280ms ease both;
}

@keyframes paper-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 響應式 ---------- */
@media (max-width: 860px) {
  .hero-art {
    min-height: min(72vw, 420px);
  }

  .hero-art #home-mascot {
    width: min(68%, 330px);
  }

  .level-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .question-host {
    min-height: 300px;
    padding: 14px;
  }

  .question-host::before {
    width: 96px;
    height: 96px;
    right: 8px;
    bottom: 8px;
  }
}

@media (max-width: 560px) {
  .choices-numbers {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compare-stage {
    gap: 8px;
  }

  .compare-vs {
    font-size: 11px;
    padding: 4px 8px;
  }

  .tian-grid-compare {
    width: 42vw;
  }

  .hanzi-badge {
    font-size: 11px;
  }

  .play-bottom {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stroke-ink,
  .feedback-burst,
  .screen-enter,
  .tian-grid .tian-char {
    animation: none;
  }
}
