:root {
  --paper: #f6f0e2;
  --paper-line: #e6dcc4;
  --ink: #2b2622;
  --indigo: #2b4a6f;
  --indigo-dark: #1c3350;
  --jade: #2f7d5f;
  --red: #b3251e;
  --red-dark: #7d1a15;
  --gold: #b8860b;
  --green-ok: #2f7d4f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(246,240,226,0.82), rgba(246,240,226,0.82)),
    url('assets/art/bg-texture.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
}
.topbar {
  text-align: center;
  padding: 16px 12px 12px;
  border-bottom: 3px double var(--indigo);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(43,74,111,0.06), transparent);
}
.topbar-mascot {
  width: 48px; height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--indigo);
  box-shadow: 0 2px 6px rgba(43,74,111,0.25);
}
.topbar h1 { margin: 0; color: var(--indigo); letter-spacing: 0.2em; font-size: 1.6rem; }
.subtitle { margin: 4px 0 0; font-size: 0.85rem; color: #574a38; }

.hero-banner {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  object-position: center 30%;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(43,74,111,0.18);
  border: 1px solid var(--paper-line);
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view.hidden { display: none; }

.section-label {
  font-size: 0.78rem;
  font-weight: bold;
  color: var(--indigo);
  letter-spacing: 0.15em;
  margin: 18px 2px 8px;
}
.section-label:first-of-type { margin-top: 4px; }

.paper-note {
  font-size: 0.72rem;
  color: #8a7c62;
  text-align: center;
  margin: 18px 0 4px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 14px 16px;
  background: #fff;
  border: 2px solid var(--indigo);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  box-shadow: 0 2px 6px rgba(43,74,111,0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.mode-card:hover {
  box-shadow: 0 4px 12px rgba(43,74,111,0.22);
  border-color: var(--indigo-dark);
}
.mode-card:active {
  transform: scale(0.97);
  box-shadow: 0 1px 3px rgba(43,74,111,0.15);
}
.mode-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mode-icon {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--indigo);
  object-fit: cover;
  background: #fdfaf2;
}
.mode-title { font-weight: bold; }
.mode-desc { font-size: 0.75rem; color: #6b5d4a; }

.quiz-topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; font-size: 0.9rem;
}
.btn-back {
  background: none; border: none; color: var(--indigo); font-size: 0.95rem; cursor: pointer;
  padding: 10px 12px; min-height: 44px; display: inline-flex; align-items: center;
}

.quiz-card {
  background: #fff;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  padding: 20px 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.quiz-sentence { font-size: 1.15rem; line-height: 1.9; margin-bottom: 18px; }
.quiz-sentence .blank-target { color: var(--red); font-weight: bold; text-decoration: underline dotted; }

.quiz-progress { height: 4px; background: var(--paper-line); border-radius: 2px; margin: -20px -16px 18px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: linear-gradient(90deg, var(--jade), var(--indigo)); border-radius: 2px; transition: width 0.5s cubic-bezier(.4,0,.2,1); }

.opt-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.opt-btn {
  padding: 16px 10px; font-size: 1.05rem; line-height: 1.4; min-height: 56px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #c9bda0; border-radius: 6px; background: #fffdf8;
  cursor: pointer;
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.15s ease;
}
.opt-btn:hover { border-color: var(--indigo); }
.opt-btn:active { transform: scale(0.98); }
.opt-btn.correct { border-color: var(--green-ok); background: #eaf6ee; animation: opt-pulse 0.4s ease; }
.opt-btn.wrong { border-color: var(--red); background: #fbeceb; animation: opt-shake 0.35s ease; }
@keyframes opt-pulse { 0%{transform:scale(1)} 40%{transform:scale(1.04)} 100%{transform:scale(1)} }
@keyframes opt-shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }

.judge-row { display: flex; gap: 10px; margin-bottom: 14px; }
.judge-btn {
  flex: 1; padding: 12px; min-height: 44px; border-radius: 6px; border: 2px solid #c9bda0;
  background: #fffdf8; cursor: pointer; font-size: 1rem;
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.15s ease;
}
.judge-btn:active { transform: scale(0.98); }
.judge-btn.correct { border-color: var(--green-ok); background: #eaf6ee; animation: opt-pulse 0.4s ease; }
.judge-btn.wrong { border-color: var(--red); background: #fbeceb; animation: opt-shake 0.35s ease; }
.fill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.fill-input { width: 48px; height: 48px; font-size: 1.2rem; text-align: center; border: 2px solid #c9bda0; border-radius: 6px; }
.pick-list { display: flex; flex-direction: column; gap: 10px; }
.pick-option {
  padding: 12px; border: 2px solid #c9bda0; border-radius: 6px; background: #fffdf8;
  cursor: pointer; text-align: left;
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.15s ease;
}
.pick-option:active { transform: scale(0.98); }
.pick-option.correct { border-color: var(--green-ok); background: #eaf6ee; animation: opt-pulse 0.4s ease; }
.pick-option.wrong { border-color: var(--red); background: #fbeceb; animation: opt-shake 0.35s ease; }

.kbd-hint {
  display: inline-block; margin-right: 6px; padding: 1px 6px;
  font-size: 0.7rem; font-family: monospace; color: #8a7c62;
  border: 1px solid #c9bda0; border-radius: 4px; background: #f6f0e2;
  vertical-align: middle;
}

.feedback-bar {
  position: relative; margin-top: 14px; padding: 10px; border-radius: 6px;
  font-weight: bold; text-align: center; overflow: hidden;
  animation: fb-rise 0.3s cubic-bezier(.2,.7,.3,1) 0.1s both;
}
.feedback-bar.correct { background: #eaf6ee; color: var(--green-ok); }
.feedback-bar.wrong { background: #fbeceb; color: var(--red); }
.feedback-bar.correct::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 2px;
  background: var(--green-ok); width: 100%;
  animation: fb-countdown 0.9s linear forwards;
}
@keyframes fb-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fb-countdown { from { width: 100%; } to { width: 0%; } }
.next-btn {
  margin-top: 12px; width: 100%; padding: 12px; background: var(--indigo); color: #fff;
  border: none; border-radius: 6px; font-size: 1rem; cursor: pointer;
  animation: fb-rise 0.3s cubic-bezier(.2,.7,.3,1) 0.25s both;
}

.result-card { background: #fff; border-radius: 8px; padding: 24px; text-align: center; border: 1px solid var(--paper-line); }
.btn-primary, .btn-secondary {
  display: inline-block; margin: 10px 6px 0; padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; font-size: 1rem;
}
.btn-primary { background: var(--indigo); color: #fff; }
.btn-secondary { background: #eee; color: var(--ink); }

.battle-hp-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.hp-block { flex: 1; min-width: 0; }
.hp-label { font-size: 0.85rem; font-weight: 600; display: block; margin-bottom: 3px; }
.hp-bar { height: 14px; background: #e3d9c2; border-radius: 7px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.25); }
.hp-fill { height: 100%; background: var(--indigo); transition: width 0.3s; }
.hp-fill.enemy { background: var(--red); }
.hp-enemy-row { display: flex; align-items: center; gap: 6px; }
.hp-enemy-row .hp-bar { flex: 1; }
.combo-indicator {
  flex: 0 0 auto; text-align: center; font-size: 0.68rem; color: #8a6508;
  line-height: 1.3;
}
.combo-indicator span { font-size: 1.1rem; font-weight: bold; }

.roster-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.roster-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 4px 8px; text-align: center; border-radius: 8px;
  border: 2px solid var(--indigo); background: #fffdf8; font-size: 0.75rem; cursor: pointer;
  overflow: hidden;
}
.roster-portrait {
  width: calc(100% + 8px); aspect-ratio: 1; object-fit: cover;
  border-radius: 6px 6px 0 0; margin: -6px -4px 4px;
}
.roster-item.locked { opacity: 0.4; cursor: not-allowed; }
.roster-item.cleared { border-color: var(--gold); background: #fff8e6; }
.roster-item.cleared .roster-portrait {
  filter: sepia(0.15) saturate(1.1);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.battle-enemy-portrait {
  display: block; width: 44px; height: 44px; object-fit: cover;
  border-radius: 50%; border: 2px solid var(--red); flex: 0 0 auto;
  box-shadow: 0 2px 6px rgba(179,37,30,0.25);
}
.battle-enemy-portrait.hidden { display: none; }
#battle-hard-section.hidden { display: none; }
.roster-item.hard.cleared { border-color: var(--red); background: #fbeceb; }

.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.dex-card { position: relative; aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; border: 2px solid #c9bda0; background: #efe7d4; color: #b9ac8e; background-image: repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(0,0,0,.03) 4px, rgba(0,0,0,.03) 8px); }
.dex-hint {
  position: absolute; top: -5px; right: -5px;
  background: var(--red); color: #fff; font-size: 0.55rem; font-weight: bold;
  border-radius: 999px; padding: 1px 5px; line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.dex-card.bronze { background: radial-gradient(circle at 35% 30%, #fbead0, #f3e1c9 60%, #e6c690); border-color: #c98b3f; color: var(--ink); }
.dex-card.silver { background: radial-gradient(circle at 35% 30%, #f5f7fa, #e9edf2 60%, #d3d9e0); border-color: #9aa7b4; color: var(--ink); }
.dex-card.gold {
  background: radial-gradient(circle at 35% 30%, #fff9e0, #fff3cf 60%, #f0d998);
  border: 3px double var(--gold); color: var(--red); font-weight: bold;
  font-size: 1.6rem; text-shadow: 0 1px 0 rgba(255,255,255,.6);
}

.streak-badge {
  text-align: center; font-size: 0.85rem; font-weight: bold;
  color: var(--red); margin-bottom: 8px; min-height: 1em;
}

.quest-panel {
  display: flex; flex-direction: column; gap: 8px;
  background: #fff; border: 1px solid var(--paper-line); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px; font-size: 0.85rem;
}
.quest-row { display: flex; align-items: center; gap: 10px; color: #6b5d4a; }
.quest-icon {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--paper-line); display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: bold; color: #6b5d4a;
}
.quest-body { flex: 1; min-width: 0; }
.quest-label { font-size: 0.78rem; margin-bottom: 3px; }
.quest-track { height: 6px; background: var(--paper-line); border-radius: 3px; overflow: hidden; }
.quest-fill { height: 100%; background: var(--jade); border-radius: 3px; transition: width 0.4s ease; }
.quest-count { flex: 0 0 auto; font-size: 0.75rem; color: #8a7c62; }
.quest-row.done { color: var(--jade); }
.quest-row.done .quest-icon { border-color: var(--jade); background: #eaf6ee; color: var(--jade); }
.quest-row.done .quest-label { font-weight: bold; }

.btn-link {
  display: block; margin: 4px auto 0; background: none; border: none;
  border-top: 1px solid var(--paper-line);
  color: #574a38; font-size: 0.8rem; text-decoration: underline;
  cursor: pointer; text-align: center; width: 100%;
  padding: 14px 16px 10px; min-height: 44px;
}

.backup-label { font-size: 0.85rem; color: #6b5d4a; margin: 14px 0 6px; }
.backup-textarea {
  width: 100%; min-height: 90px; font-family: monospace; font-size: 0.75rem;
  padding: 8px; border: 2px solid #c9bda0; border-radius: 6px; background: #fffdf8;
  resize: vertical;
}
.backup-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.backup-file-label { cursor: pointer; }
.cloud-code-display {
  margin-top: 10px; padding: 12px; text-align: center; font-size: 1.3rem;
  font-weight: 700; letter-spacing: 0.15em; color: var(--indigo);
  background: #fffdf8; border: 2px dashed var(--gold); border-radius: 8px;
}
.cloud-code-display.hidden { display: none; }
.cloud-code-input {
  font-family: monospace; font-size: 1rem; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 8px 10px; border: 2px solid #c9bda0; border-radius: 6px; background: #fffdf8;
  width: 140px;
}

.mode-card:focus-visible, .opt-btn:focus-visible, .judge-btn:focus-visible,
.pick-option:focus-visible, .roster-item:focus-visible,
.btn-primary:focus-visible, .btn-secondary:focus-visible,
.btn-back:focus-visible, .btn-link:focus-visible {
  outline: 3px solid var(--indigo-dark);
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .opt-grid { grid-template-columns: 1fr; }
  .kbd-hint { display: none; }
}

.font-toggle-btn {
  margin-left: auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid var(--indigo);
  background: var(--paper);
  color: var(--indigo);
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
}
.font-toggle-btn:hover { background: rgba(43,74,111,0.08); }
body.font-large { font-size: 1.15em; }

.onboarding-banner {
  background: #fbf6e6;
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
.onboarding-banner p { margin: 0 0 6px; }
.onboarding-banner .onboarding-modes { color: #574a38; }
.onboarding-banner .btn-link { margin: 0; padding: 0; min-height: auto; border-top: none; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin: 4px 0 10px;
  color: #574a38;
}
.filter-row select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--paper-line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.85rem;
}

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

.summary-card {
  font-size: 0.85rem;
  color: var(--indigo);
  text-align: center;
  margin-bottom: 6px;
  min-height: 1.2em;
}

.mark-icon { font-weight: bold; margin-right: 6px; }
.opt-btn.correct .mark-icon, .judge-btn.correct .mark-icon, .pick-option.correct .mark-icon { color: var(--green-ok); }
.opt-btn.wrong .mark-icon, .judge-btn.wrong .mark-icon, .pick-option.wrong .mark-icon { color: var(--red); }

.report-btn {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: #8a7c62;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px;
}
.report-form { margin-top: 8px; text-align: center; }
.report-form.hidden { display: none; }
.report-note {
  width: 100%;
  max-width: 320px;
  height: 50px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.85rem;
  resize: none;
}
.report-status { display: block; font-size: 0.8rem; color: var(--jade); margin-top: 4px; }

.dex-tier-badge {
  position: absolute;
  top: 4px; left: 4px;
  font-size: 0.65rem;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 4px;
  padding: 1px 4px;
}
.dex-pct {
  position: absolute;
  bottom: 3px; left: 0; right: 0;
  text-align: center;
  font-size: 0.62rem;
  color: #574a38;
}
.dex-card.dex-clickable { cursor: pointer; }
.dex-card.dex-clickable:hover { box-shadow: 0 0 0 2px var(--indigo) inset; }

@media (min-width: 768px) {
  main { max-width: 960px; }
  .mode-grid { grid-template-columns: repeat(3, 1fr); }
  .roster-grid { grid-template-columns: repeat(4, 1fr); }
}
