:root {
  --bg: #f6efe6;
  --surface: #fffaf3;
  --surface-2: #f1e6d8;
  --ink: #2e2118;
  --muted: #7a6656;
  --line: #e2d3c1;
  --brand: #7b4a2b;
  --brand-ink: #fff;
  --accent: #d98b3a;
  --good: #2f8a57;
  --ok: #c98a14;
  --bad: #c2463b;
  --user: #7b4a2b;
  --shadow: 0 2px 10px rgba(80, 50, 20, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1612; --surface: #26201b; --surface-2: #332a23; --ink: #f3e9df; --muted: #b3a291;
    --line: #43372e; --brand: #c98b5e; --brand-ink: #1c1612; --accent: #e7a45e;
    --good: #5cc28a; --ok: #e3b146; --bad: #ea7065; --user: #a4683f; --shadow: 0 2px 10px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1612; --surface: #26201b; --surface-2: #332a23; --ink: #f3e9df; --muted: #b3a291;
  --line: #43372e; --brand: #c98b5e; --brand-ink: #1c1612; --accent: #e7a45e;
  --good: #5cc28a; --ok: #e3b146; --bad: #ea7065; --user: #a4683f; --shadow: 0 2px 10px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Prompt', system-ui, sans-serif; font-size: 15px; line-height: 1.5;
}
button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; transition: transform .08s, background .15s;
}
button:hover { background: var(--surface-2); }
button:active { transform: scale(.97); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo { font-size: 30px; }
h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ctl { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.ctl select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.engine { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px;
  max-width: 1280px; margin: 0 auto; padding: 18px 20px 40px;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; padding: 12px 16px 32px; } }

.counter { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel-sub { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ---------- mission ---------- */
.mission { background: linear-gradient(135deg, var(--accent), var(--brand)); color: #fff; border-radius: 16px; padding: 12px 16px; }
.mission-tag { font-size: 12px; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
.mission-title { font-weight: 700; font-size: 17px; }

/* ---------- scene ---------- */
.scene {
  position: relative; height: 170px; border-radius: 16px; overflow: hidden;
  background: linear-gradient(180deg, #caa27d 0%, #b5875f 60%, #8a5a36 60%, #6d4428 100%);
}
.decor { /* ชั้นวางของ */
  position: absolute; top: 14px; left: 0; right: 0; text-align: center;
  font-size: 22px; letter-spacing: 16px; opacity: .55; white-space: nowrap; overflow: hidden;
}
.actor { position: absolute; left: 50%; bottom: 58px; transform: translateX(-50%); text-align: center; }
.face { font-size: 64px; line-height: 1; transition: transform .3s; }
.state-label {
  margin-top: 4px; font-size: 12px; background: rgba(255,255,255,.9); color: #3a2a1e;
  padding: 2px 10px; border-radius: 999px; white-space: nowrap;
}
.counter-top { position: absolute; left: 0; right: 0; bottom: 0; height: 64px; background: #5a3820; border-top: 6px solid #3e2715; }
.actor[data-state="thinking"] .face { animation: bob 1s infinite; }
.actor[data-state="asking"] .face { transform: rotate(-6deg); }
.actor[data-state="looking"] .face { transform: translateX(22px) rotate(8deg); }
.actor[data-state="confused"] .face { animation: shake .5s 2; }
.actor[data-state="warning"] .face { animation: shake .4s 3; }
.actor[data-state="warning"] .state-label { background: var(--bad); color: #fff; }
.actor[data-state="confirming"] .face { transform: rotate(4deg); }
.actor[data-state="making"] .face { animation: bob .5s infinite; }
.actor[data-state="serving"] .face { transform: scale(1.1); }
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes shake { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
@media (prefers-reduced-motion: reduce) { .face { animation: none !important; } }

/* ---------- chat ---------- */
.chat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 86%; padding: 9px 13px; border-radius: 14px; word-wrap: break-word; }
.msg.actor { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: var(--user); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; font-size: 11.5px; opacity: .85; }
.msg .chip { background: rgba(255,255,255,.2); padding: 1px 8px; border-radius: 999px; }
.msg.actor .speak { border: 0; background: none; padding: 0 0 0 6px; cursor: pointer; }
.msg.typing { color: var(--muted); font-style: italic; }

/* ---------- composer ---------- */
.composer { display: flex; flex-direction: column; gap: 8px; }
.staged { display: flex; gap: 8px; align-items: flex-start; }
.staged .chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.staged .chip { background: var(--accent); color: #fff; padding: 3px 11px; border-radius: 999px; font-size: 13px; }
.staged .chip.alg { background: var(--bad); }
.staged .x { padding: 2px 10px; border-radius: 999px; }
.input-row { display: flex; gap: 8px; }
.input-row input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.input-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.mic { font-size: 20px; padding: 6px 14px; }
.mic.rec { background: var(--bad); border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(194,70,59,.2); } }
.send { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); min-height: 1.2em; }

/* ---------- menu board ---------- */
.menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.card {
  border: 2px solid var(--line); border-radius: 14px; padding: 10px; background: var(--surface);
  text-align: center; cursor: pointer; transition: border-color .15s, transform .1s; user-select: none;
}
.card:hover { border-color: var(--accent); }
.card.picked { border-color: var(--accent); background: var(--surface-2); transform: translateY(-2px); }
.card .emoji { font-size: 30px; }
.card .name { font-weight: 600; font-size: 14px; }
.card .alt { font-size: 11.5px; color: var(--muted); }
.card .price { font-size: 13px; color: var(--brand); font-weight: 600; }
.temps { display: flex; gap: 4px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.temps button { padding: 1px 8px; font-size: 12px; border-radius: 999px; }
.temps button.picked { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- ticket ---------- */
.slots { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.slots li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.slots li .v { font-weight: 600; }
.slots li.empty .v { color: var(--muted); font-weight: 400; }
.slots li.filled::before { content: '✓'; color: var(--good); font-weight: 700; margin-right: 6px; }
.slots li .k { flex: 1; }
.total { display: flex; justify-content: space-between; font-size: 16px; border-top: 1px dashed var(--line); padding-top: 8px; }
.ticket.done { border-color: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }

/* ---------- coach ---------- */
.coach-body { display: flex; flex-direction: column; gap: 8px; }
.rating { align-self: flex-start; padding: 3px 12px; border-radius: 999px; font-weight: 600; color: #fff; font-size: 13.5px; }
.rating.excellent { background: var(--good); }
.rating.good { background: var(--ok); }
.rating.improve { background: var(--bad); }
.coach-body ul { margin: 0; padding-left: 18px; }
.tip { background: var(--surface-2); border-left: 4px solid var(--accent); padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.bar { display: grid; grid-template-columns: 90px 1fr 36px; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }

.actions { display: flex; gap: 10px; }
.actions button { flex: 1; padding: 11px; }

/* ---------- scenario tabs ---------- */
.scenarios {
  display: flex; gap: 8px; max-width: 1280px; margin: 0 auto; padding: 14px 20px 0; overflow-x: auto;
}
.scenarios button { display: flex; gap: 8px; align-items: center; white-space: nowrap; border-radius: 12px; padding: 8px 14px; }
.scenarios button .code { font-size: 12px; color: var(--muted); }
.scenarios button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.scenarios button.on .code { color: inherit; opacity: .8; }
@media (max-width: 900px) { .scenarios { padding: 10px 16px 0; } }
.focus { font-size: 13px; color: var(--muted); }
.focus strong { color: var(--ink); }
.mission-desc { font-size: 14px; }
.mission-profile { margin-top: 6px; background: rgba(0,0,0,.18); padding: 4px 10px; border-radius: 8px; font-weight: 600; font-size: 13.5px; }

/* ---------- menu extras ---------- */
.card .algs { font-size: 12px; min-height: 16px; letter-spacing: 2px; }

/* ---------- customize (checkbox modifiers) ---------- */
.custom-head { font-weight: 600; margin-bottom: 6px; }
.opt-row { margin: 8px 0; }
.opt-row .lbl { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.opt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.opt-chips button { padding: 3px 11px; font-size: 13px; border-radius: 999px; }
.opt-chips button.current { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.opt-chips button.picked { background: var(--accent); color: #fff; border-color: var(--accent); }
.mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; }
.mods label { display: flex; gap: 6px; align-items: center; font-size: 13.5px; cursor: pointer; }
.mods label.forced { color: var(--bad); }
.mods .extra { color: var(--muted); font-size: 12px; }

/* ---------- AAC allergy cards ---------- */
.aac summary { cursor: pointer; font-weight: 600; font-size: 16px; }
.aac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.aac-grid button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; border-radius: 12px; font-size: 13px; }
.aac-grid button .ic { font-size: 26px; }
.aac-grid button.picked { background: var(--bad); color: #fff; border-color: var(--bad); }
.aac-grid button.declared { border-color: var(--bad); color: var(--bad); }

/* ---------- ticket extras ---------- */
.phase { font-size: 12.5px; display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin: 2px 0 4px; }
.phase.confirming { background: var(--ok); color: #fff; }
.phase.complete { background: var(--good); color: #fff; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag { font-size: 12.5px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.tag.alg { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); font-weight: 600; }

/* ---------- debrief extras ---------- */
.checks { list-style: none; padding: 0 !important; margin: 0; display: grid; gap: 2px; font-size: 13.5px; }
.checks .ok::before { content: '✓ '; color: var(--good); font-weight: 700; }
.checks .no::before { content: '✗ '; color: var(--bad); font-weight: 700; }

.devbox summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.devbox pre { font-size: 11.5px; max-height: 260px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: 10px; }

/* ---------- debrief ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(30, 20, 10, .5); }
.debrief { padding: 22px 22px 8px; display: flex; flex-direction: column; gap: 12px; }
.debrief h3 { margin: 0; font-size: 20px; }
.score-big { display: flex; align-items: baseline; gap: 12px; }
.score-big .num { font-size: 48px; font-weight: 700; color: var(--brand); }
.stars { font-size: 26px; letter-spacing: 2px; }
.debrief .bar { grid-template-columns: 150px 1fr 40px; }
.debrief .note { font-size: 12.5px; color: var(--muted); margin: -6px 0 0 158px; }
@media (max-width: 520px) { .debrief .bar { grid-template-columns: 110px 1fr 36px; } .debrief .note { margin-left: 0; } }
.debrief h4 { margin: 6px 0 2px; font-size: 15px; }
.debrief ul { margin: 0; padding-left: 20px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 20px; }

/* ---------- Chapter 2 extras ---------- */
.card .alc { font-size: 11.5px; color: var(--bad); font-weight: 600; }
.card .extras { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.tag.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); font-weight: 600; }
.aac-grid button.id { border-color: var(--brand); }
.aac-grid button.id.picked { background: var(--brand); color: var(--brand-ink); }
.phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.phrases button { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); }

/* ---------- ตัวช่วย (Assist Bot) ---------- */
.assist-btn { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; white-space: nowrap; }
.assist-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.assist-btn.pulse { border-color: var(--accent); animation: helpPulse 1.2s ease-in-out infinite; }
@keyframes helpPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 139, 58, .55); } 50% { box-shadow: 0 0 0 7px rgba(217, 139, 58, 0); } }
.assist {
  border: 2px solid var(--accent); background: var(--surface); border-radius: 14px; padding: 10px 12px;
  margin-bottom: 8px; box-shadow: var(--shadow); max-height: 46vh; overflow-y: auto; font-size: 14px;
}
.assist-head { display: flex; align-items: center; gap: 8px; }
.assist-head strong { flex: 1; }
.assist-head .x { padding: 2px 8px; }
.assist h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.assist p { margin: 6px 0; }
.assist .now span { font-weight: 600; }
.assist .auto { color: var(--accent); font-weight: 600; }
.assist .warn { color: var(--bad); font-weight: 500; }
.assist .small { font-size: 12px; margin: 4px 0 0; }
.polite-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.polite-seg button { border: 0; border-radius: 0; padding: 2px 10px; font-size: 12.5px; background: transparent; }
.polite-seg button.on { background: var(--brand); color: var(--brand-ink); }
.gloss { margin: 0; padding-left: 18px; }
.gloss li { margin: 2px 0; }
.gloss .other { color: var(--muted); font-size: 12.5px; }
.say { display: flex; flex-wrap: wrap; gap: 6px; }
.say-chip { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); max-width: 100%; }
.say-chip.star { border-color: var(--accent); }
.say-chip button { border: 0; border-radius: 0; background: transparent; padding: 5px 10px; text-align: left; }
.say-chip .use { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.say-chip .use:hover { background: var(--surface); }
.say-chip .hear { border-left: 1px solid var(--line); padding: 5px 8px; }
.say-chip em { font-style: normal; color: var(--accent); font-weight: 600; }
.price-calc { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 6px 10px; }
.assist .model { margin-top: 10px; }
.assist .model summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.assist .model div { margin-top: 6px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.assist .model .use-model { margin-left: 6px; font-size: 12.5px; padding: 2px 10px; }
.assist .slow { margin-top: 10px; font-size: 13px; padding: 4px 12px; }
.assist-used { margin-top: 12px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); font-size: 13.5px; }
@media (max-width: 560px) {
  .assist-btn span:last-child { display: none; }
}
