:root {
  --bg: #E9E6DD;
  --surface: #FBF8F1;
  --ink: #232323;
  --soft: #55524B;
  --muted: #8C8A84;
  --line: #D8D3C8;
  --paper: #FFF1C6;
  --yellow: #FFD21E;
  --orange: #FF9D00;
  --blue: #3B7CF6;
  --red: #EF3E36;
  --green: #3E8E5E;
  --purple: #A855F7;
  --display: 'Chewy', 'Mali', 'IBM Plex Sans Thai', cursive;
  --body: 'IBM Plex Sans Thai', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'IBM Plex Sans Thai', ui-monospace, monospace;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 80px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; background: var(--yellow);
  border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
  display: grid; place-items: center; font-family: var(--display); font-size: 22px; line-height: 1;
}
.brand-name { font-family: var(--display); font-size: 26px; line-height: 1; }
.nav { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 2px solid var(--ink);
  border-radius: 999px; box-shadow: var(--shadow-sm); }
.nav a, .nav button {
  font-family: var(--mono); font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  padding: 6px 14px; border-radius: 999px; text-decoration: none; border: 0; background: transparent;
  color: var(--soft); cursor: pointer;
}
.nav a.on { background: var(--yellow); color: var(--ink); font-weight: 500; }
.nav a:hover, .nav button:hover { color: var(--ink); }

/* ---------- headings ---------- */
.hero { text-align: center; margin: 8px 0 28px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 7vw, 68px); line-height: 1.05; margin: 0; }
.hero h1 mark { background: var(--yellow); padding: 0 .18em; border-radius: 6px; color: var(--ink); }
.hero p { color: var(--soft); max-width: 620px; margin: 14px auto 0; font-size: 18px; }
.eyebrow { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); }
h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0 0 12px; line-height: 1.15; }

/* ---------- card ---------- */
.card {
  background: var(--surface); border: 2px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 22px; }
.grid { display: grid; gap: 22px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ---------- pills / buttons ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px;
  padding: 3px 10px; border: 1.5px solid var(--ink); border-radius: 999px; background: var(--surface);
  color: var(--soft); white-space: nowrap;
}
.pill.yellow { background: var(--yellow); color: var(--ink); }
.pill.dark { background: var(--ink); color: var(--surface); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--mono); font-weight: 500; font-size: 15px;
  padding: 10px 20px; border: 2px solid var(--ink); border-radius: 999px; background: var(--surface);
  box-shadow: var(--shadow-sm); cursor: pointer; text-decoration: none; transition: transform .06s, box-shadow .06s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--yellow); }
.btn.ghost { box-shadow: none; border-color: transparent; background: transparent; color: var(--soft); }
.btn.ghost:hover { color: var(--ink); transform: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- progress ---------- */
.bar { height: 14px; border: 2px solid var(--ink); border-radius: 999px; background: var(--surface); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--yellow); border-right: 2px solid var(--ink); }
.bar > i[style*="width: 0%"] { border-right: 0; }
.big-num { font-family: var(--display); font-size: 44px; line-height: 1; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 6vh auto 0; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); }
.input, textarea.input {
  width: 100%; padding: 11px 14px; border: 2px solid var(--ink); border-radius: 10px; background: #fff;
}
.error { color: var(--red); font-size: 15px; min-height: 1.4em; }

/* ---------- annotate ---------- */
.ann-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ann-head .id { font-family: var(--mono); font-size: 14px; }
.quote {
  font-size: 21px; line-height: 1.75; background: #fff; border: 2px solid var(--ink); border-radius: 12px;
  padding: 18px 20px; word-break: break-word; overflow-wrap: anywhere;
}
.quote mark {
  background: var(--yellow); color: var(--ink); padding: 1px 6px; border-radius: 6px;
  border: 2px solid var(--ink); font-weight: 600; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.q { display: grid; grid-template-columns: 1fr auto; gap: 8px 18px; align-items: center; padding: 16px 4px;
  border-bottom: 1.5px dashed var(--line); border-radius: 10px; }
.q.active { background: var(--paper); padding-left: 14px; padding-right: 14px; }
.q:last-of-type { border-bottom: 0; }
.q-title { font-weight: 600; }
.q-title .num { font-family: var(--mono); font-size: 13px; color: var(--soft); margin-right: 6px; }
.q-hint { grid-column: 1 / 2; color: var(--soft); font-size: 14.5px; margin-top: -4px; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; background: var(--surface);
  padding: 3px; gap: 3px; grid-row: 1 / span 2; grid-column: 2; }
.seg button {
  border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  font-family: var(--mono); font-size: 14px; color: var(--soft); min-width: 64px;
}
.seg button:hover { color: var(--ink); background: var(--bg); }
.seg button[aria-pressed="true"][data-v="Y"] { background: var(--green); color: #fff; }
.seg button[aria-pressed="true"][data-v="N"] { background: var(--ink); color: var(--surface); }
.seg button[aria-pressed="true"][data-v="?"] { background: var(--orange); color: var(--ink); }
.forms { display: flex; flex-wrap: wrap; gap: 8px; }
.forms button {
  border: 1.5px solid var(--ink); background: var(--surface); border-radius: 999px; padding: 6px 14px;
  cursor: pointer; font-size: 15px;
}
.forms button[aria-pressed="true"] { background: var(--yellow); font-weight: 600; box-shadow: var(--shadow-sm); }
.forms button:disabled { opacity: .4; cursor: not-allowed; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.result { font-family: var(--mono); font-size: 13px; }
.result b { font-family: var(--display); font-weight: 400; font-size: 20px; margin-left: 6px; }
.keys { font-family: var(--mono); font-size: 12px; color: var(--soft); }
kbd { font-family: var(--mono); font-size: 11px; border: 1.5px solid var(--ink); border-bottom-width: 3px;
  border-radius: 6px; padding: 0 6px; background: var(--surface); color: var(--ink); }
.stickybar {
  position: sticky; bottom: 12px; margin-top: 22px; z-index: 5;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow);
  padding: 8px; display: flex; gap: 8px; align-items: center;
}
.stickybar .result { padding-left: 14px; }

/* ---------- item map ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--mono); font-size: 11px; padding: 3px 7px; border-radius: 7px; border: 1.5px solid var(--ink);
  background: var(--surface); text-decoration: none; color: var(--soft);
}
.chip.done { background: var(--yellow); color: var(--ink); }
.chip:hover { box-shadow: var(--shadow-sm); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { font-family: var(--mono); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--soft); text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--ink); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1.5px dashed var(--line); vertical-align: top; }
td.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.k-good { background: #D9EEDF; } .k-mid { background: var(--paper); } .k-bad { background: #FBD9D6; }

/* ---------- guide ---------- */
.guide-q { border-left: 6px solid var(--yellow); padding: 4px 0 4px 16px; margin: 18px 0; }
.guide-q h3 { margin: 0 0 4px; font-size: 19px; }
.ex { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.ex div { background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.ex b { font-family: var(--mono); font-size: 12px; display: block; color: var(--soft); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(150%);
  background: var(--ink); color: var(--surface); font-family: var(--mono); font-size: 14px;
  padding: 10px 18px; border-radius: 999px; transition: transform .2s, opacity .2s; z-index: 50; pointer-events: none;
  opacity: 0;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.muted { color: var(--soft); }
.small { font-size: 14px; }

@media (max-width: 680px) {
  body { font-size: 16px; }
  .q { grid-template-columns: 1fr; }
  .seg { grid-row: auto; grid-column: 1; justify-self: start; }
  .q-hint { grid-column: 1; }
  .two, .ex { grid-template-columns: 1fr; }
  .quote { font-size: 18px; padding: 14px; }
  .stickybar { border-radius: 18px; flex-wrap: wrap; }
  .stickybar .result { width: 100%; padding: 4px 8px; }
  .keys { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.card.practice { background: var(--paper); }
.card.ref.ok { border-color: var(--green); box-shadow: 6px 6px 0 var(--green); }
.card.ref.miss { box-shadow: 6px 6px 0 var(--orange); }
