:root {
  --ink: #1a1814;
  --ink-soft: #5a5348;
  --paper: #f4ead8;
  --paper-2: #fffaf1;
  --seal: #c23a2b;
  --seal-deep: #6b1d16;
  --gold: #c4a35a;
  --line: rgba(26, 24, 20, 0.12);
  --shadow: 0 16px 40px rgba(107, 29, 22, 0.14);
  --radius: 18px;
  --header-h: 4.25rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --kai: "Noto Serif TC", "Kaiti TC", "STKaiti", "Songti TC", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(194, 58, 43, 0.12), transparent 50%),
    radial-gradient(800px 380px at 100% 0%, rgba(196, 163, 90, 0.22), transparent 46%),
    linear-gradient(180deg, #f7efe0 0%, var(--paper) 40%, #ead9bc 100%);
  line-height: 1.55;
}

#main {
  flex: 1 0 auto;
}

img {
  max-width: 100%;
  display: block;
}

button,
a {
  font-family: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 200;
  padding: 0.5rem 0.85rem;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
}

.skip-link:focus {
  top: calc(var(--safe-top) + 0.6rem);
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: calc(0.55rem + var(--safe-top)) 11.5rem 0.55rem 1rem;
  background: rgba(244, 234, 216, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.brand-text {
  line-height: 1.25;
  min-width: 0;
}

.brand-text strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 800;
}

.site-nav {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.site-nav a {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.86rem;
}

.site-nav a:hover,
.site-nav a.is-active {
  background: #fff;
  color: var(--seal-deep);
}

.view {
  width: min(920px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1.1rem 0 calc(2rem + var(--safe-bottom));
}

.hero,
.panel {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 1.25rem 1.25rem 1.35rem;
  margin-bottom: 1rem;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 0.35rem;
  color: var(--seal);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.hero h1,
.panel h1,
.panel h2 {
  margin: 0 0 0.4rem;
  line-height: 1.25;
}

.muted {
  margin: 0;
  color: var(--ink-soft);
}

.login-banner {
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #fff4e8;
  border: 1px solid rgba(194, 58, 43, 0.2);
  color: var(--seal-deep);
  font-size: 0.92rem;
}

.login-banner a {
  color: var(--seal);
  font-weight: 800;
}

.level-grid {
  display: grid;
  gap: 0.75rem;
}

.level-card {
  display: grid;
  gap: 0.55rem;
  width: 100%;
  padding: 1rem 1.05rem;
  text-align: left;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn.is-locked {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.glyph .big.is-hidden {
  color: var(--gold);
}

.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.4rem, 1fr));
  gap: 0.45rem;
}

.glyph-tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}

.glyph-tile .ch {
  font-family: var(--kai);
  font-size: 1.7rem;
  font-weight: 700;
}

.glyph-tile.is-seen {
  background: #f3eee3;
}

.glyph-tile.is-open {
  border-color: var(--seal);
  box-shadow: 0 0 0 2px rgba(194, 58, 43, 0.25);
}

.glyph-tile .mark {
  position: absolute;
  right: 0.2rem;
  bottom: 0.15rem;
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--seal);
}

.heritage-detail {
  margin-top: 1.1rem;
  padding: 1rem;
  border-top: 1px dashed var(--line);
  display: grid;
  gap: 0.75rem;
  justify-items: center;
  text-align: center;
}

.heritage-detail .big {
  font-family: var(--kai);
  font-size: 4.2rem;
  line-height: 1;
  font-weight: 700;
  color: var(--seal-deep);
}

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

.level-card .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.level-card strong {
  font-size: 1.15rem;
}

.level-card .count {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: #efe4cc;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--seal);
  border-radius: inherit;
}

.continue-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 0;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: var(--seal);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 8px 0 var(--seal-deep);
  transform: translateY(0);
  transition: transform 0.12s var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 var(--seal-deep);
}

.btn-ghost {
  background: transparent;
  color: var(--seal-deep);
  box-shadow: none;
  border: 2px solid var(--seal);
}

.btn-gold {
  background: var(--gold);
  color: var(--ink);
  box-shadow: 0 8px 0 #8d7340;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn[hidden] {
  display: none;
}

.panel {
  padding: 1.1rem;
}

.panel + .panel {
  margin-top: 1rem;
}

.panel-head {
  margin-bottom: 1rem;
}

.group-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 0.7rem 0 1rem;
}

.group-toolbar label {
  font-weight: 700;
  font-size: 0.9rem;
}

.group-toolbar select {
  font: inherit;
  font-weight: 700;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  max-width: min(100%, 22rem);
}

.char-stage {
  display: grid;
  gap: 1rem;
  justify-items: center;
}

.pair {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}

.glyph {
  text-align: center;
}

.glyph .label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 0.2rem;
}

.glyph .big {
  font-family: var(--kai);
  font-size: clamp(2.8rem, 12vw, 4.4rem);
  line-height: 1;
  font-weight: 700;
}

.glyph .big.sc {
  color: var(--ink-soft);
}

.glyph .big.tc {
  color: var(--seal-deep);
}

.glyph .big,
.glyph .label,
.glyph-tile,
.glyph-tile .ch,
.learned-tile,
.bank-item .ch,
.missing-stroke,
.writer-frame,
.writer-frame *,
.grid-frame,
.grid-frame canvas,
.medal-seal,
.compare img,
.compare canvas {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.glyph .big {
  pointer-events: none;
}

body.is-writing {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.is-writing .char-stage {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.is-writing .pair,
body.is-writing .hint,
body.is-writing .alts,
body.is-writing .steps {
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.arrow {
  font-size: 1.4rem;
  color: var(--gold);
  font-weight: 900;
}

.hint,
.alts {
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.steps {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.steps span {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: #efe4cc;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.steps span.is-on {
  background: var(--seal);
  color: #fff;
}

.writer-frame,
.grid-frame {
  width: min(320px, 86vw);
  height: min(320px, 86vw);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  position: relative;
  touch-action: none;
}

.writer-frame > div {
  width: 100%;
  height: 100%;
}

.grid-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}

.missing-stroke {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--kai);
  font-size: 8rem;
  font-weight: 700;
  color: var(--ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: min(100%, 420px);
}

.compare figure {
  margin: 0;
  text-align: center;
}

.compare figcaption {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 0.3rem;
}

.compare img,
.compare canvas,
.compare .preview {
  width: 100%;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.verdict {
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  margin: 0;
}

.verdict.ok {
  color: #2d6a4f;
}

.verdict.bad {
  color: var(--seal);
}

.bank-list {
  display: grid;
  gap: 0.5rem;
}

.bank-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.85rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
}

.bank-item .ch {
  font-family: var(--kai);
  font-size: 2rem;
  font-weight: 700;
  width: 2.4rem;
  text-align: center;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.stat {
  background: #fff;
  border-radius: 12px;
  padding: 0.85rem;
  border: 1px solid var(--line);
}

.stat b {
  display: block;
  font-size: 1.5rem;
}

.empty {
  padding: 1.2rem 0.4rem;
  text-align: center;
  color: var(--ink-soft);
}

.learned-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.9rem 0 0;
}

.learned-tabs a {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: #efe4cc;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.86rem;
}

.learned-tabs a.is-on {
  background: var(--seal);
  color: #fff;
}

.learned-block + .learned-block {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--line);
}

.learned-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.2rem, 1fr));
  gap: 0.45rem;
}

.learned-tile {
  display: grid;
  place-items: center;
  gap: 0.1rem;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.2rem;
}

.learned-tile .tc {
  font-family: var(--kai);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  color: var(--seal-deep);
}

.learned-tile .sc {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.medal-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.9rem 0 0;
}

.medal-strip a {
  font-weight: 800;
  color: var(--seal);
  text-decoration: none;
  font-size: 0.86rem;
}

.medal-head {
  margin-bottom: 0.85rem;
}

.medal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr));
  gap: 0.65rem;
}

.medal {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  padding: 0.85rem 0.45rem 0.75rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
  opacity: 0.42;
}

.medal.is-on {
  opacity: 1;
  border-color: var(--gold);
  box-shadow: 0 8px 18px rgba(196, 163, 90, 0.22);
}

.medal strong {
  font-size: 0.92rem;
}

.medal .muted {
  font-size: 0.72rem;
  line-height: 1.35;
}

.medal-seal {
  width: 3.35rem;
  height: 3.35rem;
  border-radius: 50%;
  border: 3px solid rgba(194, 58, 43, 0.35);
  display: grid;
  place-items: center;
  font-family: var(--kai);
  font-size: 1.35rem;
  font-weight: 700;
  color: rgba(107, 29, 22, 0.4);
  transform: rotate(-8deg);
}

.medal.is-on .medal-seal,
.medal-seal.is-mini,
.medal-seal.is-hero {
  background: radial-gradient(circle at 32% 28%, #e85a4a, var(--seal-deep));
  color: #fff8e8;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--gold);
}

.medal-seal.is-mini {
  width: 2.15rem;
  height: 2.15rem;
  font-size: 0.92rem;
  border-width: 2px;
}

.medal-seal.is-hero {
  width: 5.4rem;
  height: 5.4rem;
  font-size: 2.2rem;
  margin: 0.2rem auto 0.4rem;
  border-width: 4px;
}

.medal-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: rgba(26, 24, 20, 0.46);
}

.medal-overlay[hidden] {
  display: none;
}

.medal-card {
  width: min(100%, 22rem);
  padding: 1.35rem 1.2rem 1.2rem;
  background: var(--paper-2);
  border-radius: 22px;
  border: 1px solid var(--gold);
  box-shadow: var(--shadow);
  text-align: center;
}

.medal-card h2 {
  margin: 0.15rem 0 0.35rem;
}

.medal-card .btn {
  margin-top: 0.9rem;
}

.site-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0.85rem 1rem calc(0.85rem + var(--safe-bottom));
  font-size: 0.82rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  background: rgba(244, 234, 216, 0.92);
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--seal-deep);
  font-weight: 700;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(4rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .site-header {
    flex-wrap: wrap;
    padding: calc(0.45rem + var(--safe-top)) 1rem 0.45rem;
  }

  .brand-text strong {
    font-size: 0.86rem;
  }

  .site-nav {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .site-nav a {
    font-size: 0.8rem;
    padding: 0.35rem 0.55rem;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }
}
