/* KM Transfer: navy ink, jade for learning progress, gold for rewards */
:root {
  --ink: #1C2B4A;
  --ink-2: #3A4866;
  --slate: #5A6478;
  --paper: #F3F5F9;
  --surface: #FFFFFF;
  --line: #D9DFE8;
  --jade: #1F7A63;
  --jade-dark: #17614E;
  --jade-light: #4FC3A1;
  --jade-soft: #E3F1EC;
  --gold: #D9A21B;
  --gold-soft: #FBF1D9;
  --danger: #B3261E;
  --r-s: 6px;
  --r-m: 12px;
  --font: "Noto Sans SC", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.7; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.85rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; font-weight: 700; margin-top: 1.5rem; }
h3 { font-size: 1.1rem; font-weight: 700; }
h4 { font-size: 1rem; font-weight: 500; color: var(--ink-2); }
p { margin: 0 0 .8em; }
ul, ol { padding-left: 1.3rem; }
a { color: var(--jade); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header and progress rail (the signature element) ---------- */
.top { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 1100px; margin: 0 auto; padding: .8rem 1.25rem; display: flex; align-items: center; gap: 1.5rem; }
.brand { color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.rail { list-style: none; margin: 0; padding: 0; display: flex; flex: 1; min-width: 0; }
.rail li { flex: 1; display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: #AEB8CC; min-width: 0; }
.rail li:last-child { flex: 0 0 auto; }
.rail li:not(:last-child)::after { content: ""; flex: 1; height: 2px; background: #46557A; margin: 0 .4rem; min-width: .75rem; }
.rail li.done::after { background: var(--jade-light); }
.dot { width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; border: 2px solid #46557A; font-size: .8rem; flex: none; }
.rail li.done .dot { background: var(--jade-light); border-color: var(--jade-light); color: var(--ink); }
.rail li.now { color: #fff; font-weight: 500; }
.rail li.now .dot { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 860px) { .rail .lbl { display: none; } .rail li.now .lbl { display: inline; } }
.points { background: var(--gold); color: var(--ink); font-weight: 700; padding: .2rem .75rem; border-radius: 999px; white-space: nowrap; }
.points.bump { animation: bump .45s ease; }
@keyframes bump { 50% { transform: scale(1.18); } }

/* ---------- layout ---------- */
.wrap { max-width: 820px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.wrap-wide { max-width: 1100px; }
.intro { margin-bottom: 1.5rem; }
.intro p { color: var(--ink-2); max-width: 65ch; }
.hint { color: var(--slate); font-size: .92rem; }
.notice { background: var(--jade-soft); padding: 1rem 1.2rem; border-radius: var(--r-s); }
.tag { display: inline-block; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .6rem; margin: .15rem .2rem; font-size: .88rem; }
.admin-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.exports { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- case cards ---------- */
.case-title { font-size: 1.5rem; margin-top: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--jade); border-radius: var(--r-s); padding: 1.1rem 1.3rem; margin-bottom: 1rem; }
.card h3 { margin-bottom: .7rem; }
.card-problem { border-left-color: var(--ink); }
.card-evidence { border-left-color: var(--gold); }
.card-steps { border-left-color: var(--slate); }
.evidence { list-style: none; padding: 0; margin: 0; }
.evidence li { padding: .6rem 0; border-top: 1px dashed var(--line); }
.evidence li:first-child { border-top: 0; padding-top: 0; }
.evidence p { margin: .2rem 0 0; }
.role-banner { background: var(--ink); color: #fff; border-radius: var(--r-m); padding: 1rem 1.3rem; margin-bottom: 1rem; }
.role-banner p { margin: .2em 0; }

/* ---------- forms ---------- */
.form-card, .response-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 1.5rem; margin: 1.5rem 0; }
.form-card h2, .response-form h2 { margin-top: 0; }
.field { margin-bottom: 1.2rem; }
label { display: block; font-weight: 500; margin-bottom: .35rem; }
.zh { display: block; font-weight: 400; color: var(--slate); font-size: .92rem; }
.q-num { display: inline-grid; place-items: center; width: 1.55rem; height: 1.55rem; border-radius: 50%; background: var(--jade-soft); color: var(--jade); font-size: .8rem; font-weight: 700; margin-right: .45rem; }
input[type=text], input[type=password], select, textarea {
  width: 100%; font: inherit; color: inherit; padding: .65rem .8rem;
  border: 1px solid var(--line); border-radius: var(--r-s); background: #fff;
}
input[type=text]:focus, input[type=password]:focus, select:focus, textarea:focus { border-color: var(--jade); outline: 2px solid var(--jade-soft); }
textarea { resize: vertical; min-height: 6rem; }
.locked textarea { background: var(--paper); color: var(--ink-2); }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.counter { color: var(--slate); font-variant-numeric: tabular-nums; }
.counter.met { color: var(--jade); font-weight: 500; }
.form-error { color: var(--danger); margin-top: .8rem; }
.consent { border: 1px solid var(--line); border-radius: var(--r-s); padding: 1rem 1.2rem; margin: 0 0 1.2rem; }
.consent legend { font-weight: 700; padding: 0 .3rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; }
.check input { margin-top: .4rem; }
.inline-field { display: flex; gap: .6rem; }
.form-resume { background: transparent; }

.btn { display: inline-block; font: inherit; font-weight: 500; background: var(--jade); color: #fff; border: 0; border-radius: var(--r-s); padding: .7rem 1.3rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--jade-dark); }
.btn:disabled { background: #A9B3C2; cursor: not-allowed; }
.btn-quiet { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-quiet:hover { background: var(--paper); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--jade); text-decoration: underline; cursor: pointer; }

.error-box { background: #FDECEA; border: 1px solid #F3C2BD; color: var(--danger); border-radius: var(--r-s); padding: 1rem 1.2rem; }
.error-box p { margin-bottom: .6rem; }
.loading { display: flex; align-items: center; gap: .8rem; padding: 2rem 0; color: var(--slate); }
.loading p { margin: 0; }
.spinner { width: 1.3rem; height: 1.3rem; border: 3px solid var(--line); border-top-color: var(--jade); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- intervention ---------- */
.badges { display: flex; gap: .5rem; flex-wrap: wrap; }
.badge { font-size: .85rem; padding: .25rem .75rem; border-radius: 999px; border: 1px dashed #A9B3C2; color: var(--slate); }
.badge.earned { border: 1px solid var(--gold); background: var(--gold-soft); color: var(--ink); font-weight: 500; }
.badge.earned::before { content: "★ "; color: var(--gold); }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 1.2rem 0 1rem; }
.tabs button { font: inherit; font-weight: 700; text-align: left; padding: .75rem 1rem; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-s); cursor: pointer; color: var(--ink); }
.tabs button span { display: block; font-weight: 400; font-size: .85rem; color: var(--slate); }
.tabs button[aria-selected=true] { border-color: var(--ink); box-shadow: inset 0 -4px 0 var(--gold); }
.tabs button:disabled { color: #9AA4B5; background: transparent; cursor: not-allowed; }
.tabs button:disabled span { color: #B4BCC9; }
@media (max-width: 640px) { .tabs { grid-template-columns: 1fr; } }

.case-wrap { margin-bottom: 1rem; }
.case-wrap > summary { cursor: pointer; font-weight: 500; padding: .5rem 0; color: var(--jade); }

.dp-progress { color: var(--slate); }
.dp { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-s); padding: 1rem 1.2rem; margin-bottom: .8rem; }
.dp-done { background: transparent; }
.dp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.dp-choice { font-weight: 500; margin-bottom: .3rem; }
.dp-consequence { color: var(--ink-2); margin: 0; }
.dp-current { border: 2px solid var(--ink); }
.options { display: grid; gap: .5rem; }
.option { font: inherit; text-align: left; padding: .75rem 1rem; border: 1px solid var(--line); border-radius: var(--r-s); background: #fff; cursor: pointer; color: var(--ink); }
.option:hover:not(:disabled) { border-color: var(--jade); background: var(--jade-soft); }
.option:disabled { cursor: default; }
.option.chosen { border-color: var(--jade); background: var(--jade-soft); }
.stars { color: var(--gold); letter-spacing: .12em; white-space: nowrap; }
.stars .off { color: var(--line); }
.dp-complete { padding: 1rem 0; }

.chat-log { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 1rem; height: min(60vh, 520px); overflow-y: auto; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 85%; padding: .65rem .9rem; border-radius: var(--r-m); }
.msg p:last-child { margin: 0; }
.msg-assistant { background: var(--jade-soft); align-self: flex-start; border-bottom-left-radius: 2px; }
.msg-user { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
.msg-system { align-self: center; color: var(--danger); font-size: .9rem; }
.typing { color: var(--slate); }
.chat-form { display: flex; gap: .5rem; margin-top: .7rem; align-items: flex-end; }
.chat-form textarea { min-height: 3.2rem; }
.chat-progress { color: var(--slate); font-size: .92rem; margin-top: .5rem; }

.feedback { background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--gold); border-radius: var(--r-s); padding: 1.3rem; margin-top: 1.5rem; }
.fb-dim { border-bottom: 1px solid var(--line); padding: .8rem 0; }
.fb-head { display: flex; justify-content: space-between; align-items: center; font-weight: 500; margin-bottom: .3rem; }
.meter { display: flex; gap: 4px; }
.meter i { width: 22px; height: 8px; border-radius: 2px; background: var(--line); }
.meter i.on { background: var(--jade); }
.feedback h4 { margin-top: 1rem; }
.fb-question { background: var(--gold-soft); padding: .8rem 1rem; border-radius: var(--r-s); margin-top: 1rem; }
.fb-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- questionnaire ---------- */
.likert { border: 0; padding: 0; margin: 0 0 1.4rem; }
.likert legend { font-weight: 500; margin-bottom: .5rem; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.scale label { display: flex; flex-direction: column; align-items: center; font-weight: 500; font-size: .95rem; border: 1px solid var(--line); border-radius: var(--r-s); padding: .5rem .2rem; cursor: pointer; background: #fff; text-align: center; margin: 0; }
.scale small { font-weight: 400; font-size: .72rem; color: var(--slate); line-height: 1.3; }
.scale input { margin: 0 0 .2rem; }
.scale label:has(input:checked) { border-color: var(--jade); background: var(--jade-soft); }

/* ---------- admin and expert ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; background: var(--surface); }
th, td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
th { background: var(--paper); }
.grid-nav { display: flex; flex-wrap: wrap; gap: .3rem; margin: 1rem 0; }
.grid-nav a { display: grid; place-items: center; min-width: 2.2rem; height: 2.2rem; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface); text-decoration: none; color: var(--ink); font-size: .9rem; }
.grid-nav a.scored { background: var(--jade-soft); border-color: var(--jade); }
.grid-nav a.current { border: 2px solid var(--ink); font-weight: 700; }
.score-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .score-layout { grid-template-columns: 1fr; } }
.score-form { position: sticky; top: 5rem; margin-top: 0; }
.answer-part { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-s); padding: 1rem 1.2rem; margin-bottom: .8rem; }
.rubric-levels { border: 0; padding: 0; margin: 0 0 1.2rem; }
.rubric-levels legend { font-weight: 700; margin-bottom: .4rem; }
.rubric-levels label { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; font-size: .92rem; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: var(--r-s); margin-bottom: .4rem; background: #fff; cursor: pointer; }
.rubric-levels input { margin-top: .35rem; }
.rubric-levels label:has(input:checked) { border-color: var(--jade); background: var(--jade-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- translator: Socratic chat + knowledge assistant ---------- */
.translator-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.2rem; align-items: start; }
.translator-grid.single { grid-template-columns: 1fr; }
@media (max-width: 860px) { .translator-grid { grid-template-columns: 1fr; } }
.panel-title { font-size: 1rem; margin-bottom: .6rem; }
.kb { background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--gold); border-radius: var(--r-m); padding: 1rem; }
.kb .hint { margin-bottom: .8rem; }
.kb-log { max-height: min(50vh, 420px); overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; margin-bottom: .7rem; }
.kb-q { font-weight: 500; color: var(--ink); padding-left: .7rem; border-left: 3px solid var(--ink); }
.kb-q p { margin: 0; }
.kb-a { background: var(--gold-soft); border-radius: var(--r-s); padding: .6rem .8rem; font-size: .95rem; }
.kb-a p { margin: 0 0 .35rem; }
.kb-a p:last-child { margin: 0; }
.kb-empty { color: var(--slate); font-size: .9rem; margin: 0; }
.kb-form { display: flex; gap: .5rem; }
.kb-form input { flex: 1; min-width: 0; }

/* ---------- intervention notice and step tips ---------- */
.stage-notice { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--gold); border-radius: var(--r-m); padding: 1.3rem 1.5rem; margin: 0 0 1.5rem; }
.stage-notice h2 { margin-top: 0; font-size: 1.3rem; }
.stage-notice h2 .zh { font-size: 1rem; margin-top: .2rem; }
.stage-notice p.zh { display: block; margin-bottom: 1rem; }
.notice-steps { margin: 0 0 1rem; padding-left: 1.4rem; }
.notice-steps li { margin-bottom: .5rem; }
.notice-steps .zh, .thinking-guide .zh { font-size: .9rem; }
.thinking-guide { background: var(--jade-soft); border-radius: var(--r-s); padding: .8rem 1rem; }
.thinking-guide > summary { cursor: pointer; font-weight: 700; color: var(--jade-dark); }
.thinking-guide ul { margin: .7rem 0 .5rem; padding-left: 1.2rem; }
.thinking-guide li { margin-bottom: .5rem; }
.thinking-guide .hint { margin: 0; }
.step-tip { background: var(--gold-soft); border-radius: var(--r-s); padding: .8rem 1rem; margin: 0 0 1rem; }
.step-tip .zh { margin-top: .2rem; }
#improve-note .zh { margin-top: .4rem; }

/* ---------- "What to do" box on every stage ---------- */
.todo { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--gold); border-radius: var(--r-m); padding: 1.2rem 1.5rem; margin: 0 0 1.5rem; }
.todo-label { display: inline-block; background: var(--gold); color: var(--ink); font-weight: 700; font-size: .8rem; letter-spacing: .02em; padding: .15rem .6rem; border-radius: 999px; margin: 0 0 .6rem; }
.todo h2 { margin-top: 0; font-size: 1.25rem; }
.todo h2 .zh { font-size: .95rem; margin-top: .2rem; }
.todo-steps { margin: 0 0 .8rem; padding-left: 1.4rem; }
.todo-steps li { margin-bottom: .55rem; }
.todo-steps .zh, .todo-note .zh { font-size: .9rem; }
.todo-note { margin: 0; color: var(--ink-2); }
.todo-note .zh { margin-top: .15rem; }

/* ---------- CPS stage tag on decision points ---------- */
.stage-tag { display: inline-block; font-size: .8rem; font-weight: 700; color: var(--jade-dark); background: var(--jade-soft); border-radius: 999px; padding: .1rem .65rem; margin: 0 0 .5rem; }
.stage-tag span { font-weight: 400; color: var(--slate); }

/* ---------- accounts and language ---------- */
.lang-switch { display: flex; align-items: center; gap: .5rem; margin: 0 0 .4rem; }
.lang-label { font-weight: 700; margin-right: .3rem; }
.lang-switch a { text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--surface); padding: .35rem 1rem; border-radius: 999px; font-weight: 500; }
.lang-switch a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.lang-note { margin-bottom: 1.2rem; }
.auth-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.2rem; align-items: start; }
.auth-grid .form-card { margin: 0; }
@media (max-width: 760px) { .auth-grid { grid-template-columns: 1fr; } }
.top-logout { color: #C9D2E3; text-decoration: none; font-size: .85rem; white-space: nowrap; margin-left: auto; }
.points + .top-logout { margin-left: 0; }
.top-logout:hover { color: #fff; text-decoration: underline; }

.resume-card { border-left: 6px solid var(--jade); }
