:root {
  --bg: #f4efe7;
  --paper: #fffaf2;
  --ink: #241912;
  --muted: #74665b;
  --line: #dfd0be;
  --accent: #8f3d2f;
  --accent-dark: #61291f;
  --accent-soft: #f0d7c9;
  --gold: #c69749;
  --shadow: 0 18px 48px rgba(55, 34, 20, 0.14);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(198, 151, 73, 0.23), transparent 30rem),
    linear-gradient(180deg, #fbf4e8 0%, var(--bg) 58%, #efe3d2 100%);
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.hero {
  min-height: 92vh;
  color: #fff7ea;
  background:
    linear-gradient(120deg, rgba(22, 16, 13, .88), rgba(96, 36, 27, .86)),
    radial-gradient(circle at 75% 20%, rgba(255, 255, 255, .16), transparent 14rem),
    conic-gradient(from 25deg, #111 0 25%, #f5eee5 0 50%, #111 0 75%, #f5eee5 0);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 38rem;
  height: 38rem;
  right: -8rem;
  bottom: -10rem;
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 54%, rgba(255,255,255,.13) 55% 56%, transparent 57%),
    linear-gradient(45deg, transparent 49.7%, rgba(255,255,255,.20) 50%, transparent 50.3%),
    linear-gradient(-45deg, transparent 49.7%, rgba(255,255,255,.14) 50%, transparent 50.3%);
  opacity: .7;
}
.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
}
.brand { font-weight: 900; letter-spacing: .08em; }
.navlinks { display: flex; gap: 18px; font-size: .95rem; opacity: .9; }
.navlinks a { padding: 8px 10px; border-radius: 999px; }
.navlinks a:hover { background: rgba(255,255,255,.12); }
.hero-content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 11vh 22px 8vh;
  position: relative;
  z-index: 2;
}
.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: .78rem;
  font-weight: 800;
}
.hero .eyebrow { color: #f0c776; }
h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(2.3rem, 6vw, 5.8rem);
  line-height: 1.03;
  letter-spacing: -0.06em;
}
.lead {
  max-width: 720px;
  margin: 28px 0 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.78;
  color: rgba(255, 247, 234, .84);
}
.hero-actions, .button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.hero-actions { margin-top: 34px; }
.button {
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.button:hover { transform: translateY(-1px); }
.button.primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 12px 28px rgba(143, 61, 47, .27);
}
.button.primary:hover { background: var(--accent-dark); }
.button.ghost {
  background: rgba(255,255,255,.12);
  color: #fff7ea;
  border: 1px solid rgba(255,255,255,.22);
}
.button.ghost-dark {
  background: #fff7ed;
  color: var(--accent-dark);
  border: 1px solid var(--line);
}
.button.small { padding: 10px 14px; font-size: .9rem; }
.stats {
  margin-top: 56px;
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  max-width: 680px;
  gap: 16px;
}
.stats div {
  padding: 18px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 18px;
  backdrop-filter: blur(8px);
}
.stats b { display: block; font-size: 1.9rem; }
.stats span { color: rgba(255,247,234,.74); }

.section {
  max-width: 1180px;
  margin: 0 auto;
  padding: 76px 22px;
}
.section-title { max-width: 760px; margin-bottom: 26px; }
.section-title.wide { max-width: 980px; }
.section-title h2 {
  margin: 0;
  font-size: clamp(1.8rem, 3.8vw, 3rem);
  letter-spacing: -0.04em;
}
.section-title p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.75;
  font-size: 1.02rem;
}
.cards { display: grid; gap: 18px; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
.cards.two { grid-template-columns: repeat(2, 1fr); }
.card, .panel {
  background: rgba(255, 250, 242, .86);
  border: 1px solid rgba(139, 95, 59, .18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 24px; }
.card h3, .panel h3, .panel h4 { margin-top: 0; }
.card p, .panel p { color: var(--muted); line-height: 1.72; }
.step-card { position: relative; overflow: hidden; }
.step-card .step {
  display: inline-flex;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 900;
  margin-bottom: 12px;
}
.step-card.highlight { background: #fff2e6; }
pre {
  white-space: pre-wrap;
  margin: 12px 0 0;
  padding: 14px;
  background: #2b201b;
  color: #fff2d8;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.55;
}

.interactive, .game-section { max-width: 1320px; }
.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.workspace.reverse { grid-template-columns: minmax(0, 1fr) 360px; }
.panel { padding: 20px; }
.controls { position: sticky; top: 16px; }
.controls hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.muted { color: var(--muted); }
textarea {
  width: 100%;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: #fffdf8;
  color: var(--ink);
  resize: vertical;
  line-height: 1.45;
  font-family: "Consolas", "Menlo", monospace;
  font-size: .86rem;
}
label {
  display: block;
  margin: 14px 0;
  font-weight: 800;
}
output { float: right; color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
select, input[type="text"] {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fffdf8;
}
.toggles label, .inline-check {
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0;
}
.toggles input, .inline-check input { accent-color: var(--accent); }
.status, .feedback {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff6e8;
  border: 1px solid var(--line);
  color: var(--accent-dark) !important;
}
.canvas-panel { overflow: hidden; }
.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.canvas-header h3 { margin-bottom: 4px; }
.scorebox {
  min-width: 100px;
  text-align: center;
  padding: 12px;
  border-radius: 16px;
  background: #2b201b;
  color: #fff7ec;
}
.scorebox span { display: block; color: rgba(255,247,236,.65); font-size: .78rem; }
.scorebox b { font-size: 1.25rem; }
canvas {
  width: 100%;
  max-width: 820px;
  height: auto;
  display: block;
  margin: 0 auto;
  background: #fffdf8;
  border-radius: 24px;
  border: 1px solid var(--line);
}
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.result-grid > div {
  background: #fff7ed;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.result-grid p { margin-bottom: 0; }
.table-wrap { margin-top: 18px; }
.table-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: baseline;
}
.table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: #fff4e6; z-index: 1; }
tbody tr:hover { background: rgba(143, 61, 47, .06); }
.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
}
.badge.yes { background: #ffe0d2; color: #7b2d1e; }
.badge.no { background: #eee6dc; color: #61554b; }
.hint-card {
  margin-top: 16px;
  padding: 16px;
  border-radius: 18px;
  background: #fff6e8;
  border: 1px solid var(--line);
}
.feedback { margin-top: 14px; font-weight: 800; }
.reference-img {
  width: 100%;
  border-radius: 24px;
  box-shadow: var(--shadow);
  background: white;
  border: 1px solid var(--line);
}
footer {
  padding: 34px 22px;
  text-align: center;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

@media (max-width: 980px) {
  .cards.three, .cards.two, .workspace, .workspace.reverse, .result-grid { grid-template-columns: 1fr; }
  .controls { position: static; }
  .navlinks { display: none; }
  .stats { grid-template-columns: 1fr; }
  .table-heading { display: block; }
}

/* v2: richer interactive modules */
.mini-title h3 { margin: 0 0 8px; font-size: clamp(1.35rem, 2.3vw, 2rem); }
.correction-lab { margin-top: 22px; overflow: hidden; }
.correction-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.controls.embedded {
  position: static;
  background: #fff7ed;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.principle-lab {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  background:
    radial-gradient(circle at 84% 20%, rgba(198,151,73,.16), transparent 16rem),
    rgba(255,250,242,.9);
}
.principle-text h3 { margin-bottom: 10px; }
.principle-text p:not(.eyebrow) { font-size: 1.02rem; }
.principle-cards { margin-top: 20px; }
.reference-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.reference-card {
  margin: 0;
  padding: 14px;
  background: rgba(255,250,242,.86);
  border: 1px solid rgba(139, 95, 59, .18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.reference-card figcaption {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.7;
  font-weight: 700;
}
#gameCanvas { cursor: crosshair; }
#gameHintBox { margin-bottom: 0; color: var(--accent-dark); font-weight: 700; }
.status { line-height: 1.65; }
#stationNarration { margin-top: 12px; }
.section.reference { max-width: 1320px; }

@media (max-width: 980px) {
  .correction-grid, .principle-lab, .reference-grid { grid-template-columns: 1fr; }
}
