/* CS Simulator · Gentech House */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #e4e8ee;
  --text: #111a27;
  --muted: #5d6b7e;
  --faint: #8a96a8;
  --border: #dfe4eb;
  --brand: #0f2a44;
  --brand-2: #173b5e;
  --accent: #0a7cff;
  --accent-soft: #e6f1ff;
  --on-accent: #ffffff;
  --gold: #b88a2e;
  --good: #15803d;
  --good-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --bubble-in: #eceff3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d141d;
    --surface: #141d29;
    --surface-2: #1b2635;
    --surface-3: #243244;
    --text: #e8edf4;
    --muted: #9aa8ba;
    --faint: #6f7d90;
    --border: #263447;
    --brand: #0b1f33;
    --brand-2: #12304d;
    --accent: #3b94ff;
    --accent-soft: #15314f;
    --gold: #d8ae55;
    --good: #4ade80;
    --good-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #33270f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --bubble-in: #223044;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── โครงหน้า ───────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { width: 30px; height: 30px; }
.brand b { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand span { color: #b9c7d8; font-size: .82rem; white-space: nowrap; }
.nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a, .nav button {
  color: #d9e3ef; background: transparent; border: 0; text-decoration: none;
  padding: 7px 11px; border-radius: 9px; font-size: .92rem;
}
.nav a:hover, .nav button:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
.page { max-width: 1120px; margin: 0 auto; padding: 22px 16px 60px; }
.stack { display: grid; gap: 16px; align-content: start; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.card-title .step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .85rem; flex: none;
}
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* ── ปุ่มและฟอร์ม ──────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 11px; font-weight: 600; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 13px 22px; font-size: 1.05rem; border-radius: 13px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 9px; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: .84rem; }
input.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 11px; padding: 11px 13px; outline: none;
}
input.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.error-text { color: var(--bad); font-size: .9rem; }

/* ── หน้าเข้าสู่ระบบ ───────────────────────────── */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; }
.login-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.login-head img { width: 52px; height: 52px; }
.login-head p { color: var(--muted); font-size: .92rem; }

/* ── หน้าแรก ───────────────────────────────────── */
.hello { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.stat b { display: block; font-size: 1.45rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .84rem; }
.choice-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choice {
  text-align: left; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 13px; padding: 14px; display: grid; gap: 4px; position: relative;
}
.choice:hover { border-color: var(--accent); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice .title { font-weight: 700; }
.choice .sub { color: var(--muted); font-size: .88rem; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-3); color: var(--muted); vertical-align: middle;
}
.badge.beta { background: var(--warn-soft); color: var(--warn); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.levels { display: grid; gap: 8px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.level {
  border: 1.5px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 10px 8px; text-align: center; display: grid; gap: 2px;
}
.level b { font-size: 1.35rem; line-height: 1.1; }
.level span { font-size: .8rem; color: var(--muted); }
.level:hover { border-color: var(--accent); }
.level.selected { border-color: var(--accent); background: var(--accent-soft); }
.level.selected span { color: var(--accent); }
.level-desc { margin-top: 10px; color: var(--muted); font-size: .92rem; min-height: 1.5em; }
.tips { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-size: .9rem; }
.tips li { margin: 2px 0; }
.list { display: grid; gap: 8px; }
.list-item {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 11px 14px;
  text-decoration: none; color: var(--text);
}
.list-item:hover { border-color: var(--accent); }
.list-item .meta { color: var(--muted); font-size: .84rem; }
.score-pill {
  min-width: 52px; text-align: center; font-weight: 700; border-radius: 10px; padding: 4px 8px;
  background: var(--surface-2);
}
.score-pill.good { background: var(--good-soft); color: var(--good); }
.score-pill.mid { background: var(--warn-soft); color: var(--warn); }
.score-pill.low { background: var(--bad-soft); color: var(--bad); }

/* ── หน้าแชท ───────────────────────────────────── */
.chat-page { height: 100dvh; display: flex; flex-direction: column; background: var(--surface); }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #7aa7d8, #3f6fa6); color: #fff; font-weight: 700;
}
.avatar.small { width: 28px; height: 28px; font-size: .8rem; }
.chat-head .who { min-width: 0; flex: 1; }
.chat-head .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who span { display: block; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .counter { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px 14px 8px; background: var(--surface); }
.chat-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 3px; }
.msg-row { display: flex; align-items: flex-end; gap: 8px; }
.msg-row.out { justify-content: flex-end; }
.msg-row .avatar-slot { width: 28px; flex: none; }
.bubble {
  max-width: min(78%, 520px); padding: 8px 13px; border-radius: 19px; white-space: pre-wrap;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg-row.in .bubble { background: var(--bubble-in); border-bottom-left-radius: 6px; }
.msg-row.out .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.msg-row.gap { margin-top: 10px; }
.bubble.attach { display: flex; gap: 10px; align-items: center; border-radius: 14px; }
.msg-row.in .bubble.attach { background: var(--surface); border: 1px solid var(--border); }
.msg-row.out .bubble.attach { background: var(--brand-2); color: #fff; }
.bubble.attach .ico { font-size: 1.4rem; line-height: 1; }
.bubble.attach .kind { font-size: .74rem; opacity: .75; display: block; }
.sys {
  align-self: center; margin: 10px 0; font-size: .8rem; color: var(--muted);
  background: var(--surface-2); padding: 4px 12px; border-radius: 99px; text-align: center; max-width: 92%;
}
.sys.skip { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.seen { align-self: flex-end; font-size: .74rem; color: var(--faint); margin: 2px 4px 6px; }
.day-divider { align-self: center; font-size: .76rem; color: var(--faint); margin: 12px 0 6px; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: block;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 760px; margin: 0 auto; display: grid; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; min-height: 44px; border-radius: 22px;
  border: 1px solid var(--border); background: var(--surface-2); padding: 10px 16px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); background: var(--surface); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; font-size: 1.25rem; flex: none; color: var(--accent);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn.send:disabled { opacity: .45; }
.composer-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 5px 12px; font-size: .84rem; display: inline-flex; gap: 6px; align-items: center;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 600; }
.chip.end { margin-left: auto; color: var(--bad); }
.menu {
  position: absolute; z-index: 30; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 240px; max-height: 50vh; overflow-y: auto;
}
.menu h4 { margin: 8px 10px 4px; font-size: .74rem; color: var(--faint); font-weight: 600; }
.menu button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  padding: 8px 10px; border-radius: 8px; font-size: .9rem;
}
.menu button:hover { background: var(--surface-2); }
.end-banner {
  align-self: stretch; margin: 14px 0 6px; padding: 14px; border-radius: 14px; text-align: center;
  background: var(--surface-2); display: grid; gap: 8px; justify-items: center;
}
.end-banner.won { background: var(--good-soft); }
.end-banner.lost { background: var(--bad-soft); }
.mock-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .82rem; padding: 4px 8px; }

/* ── หน้าผลประเมิน ─────────────────────────────── */
.result-head { display: grid; gap: 18px; grid-template-columns: auto 1fr; align-items: center; }
.ring { width: 150px; height: 150px; }
.ring text { font-family: var(--font); }
.criteria { display: grid; gap: 12px; }
.crit-row { display: grid; gap: 6px; }
.crit-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.bar { height: 9px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.bar > i.good { background: var(--good); }
.bar > i.mid { background: var(--warn); }
.bar > i.low { background: var(--bad); }
.crit-row p { color: var(--muted); font-size: .9rem; }
.crit-row q { color: var(--text); }
ul.clean { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.improve { border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: grid; gap: 10px; background: var(--surface); }
.improve-head { display: flex; gap: 10px; align-items: baseline; }
.improve-head .num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: .85rem;
}
.improve dl { margin: 0; display: grid; gap: 8px; }
.improve dt { font-size: .8rem; font-weight: 700; color: var(--muted); }
.improve dd { margin: 0; }
.better {
  background: var(--good-soft); border-radius: 12px; padding: 10px 12px;
  white-space: pre-wrap; border-left: 4px solid var(--good);
}
.better .copy { display: block; margin: 6px 0 0 auto; white-space: nowrap; }
.chart { width: 100%; height: 190px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .area { fill: var(--accent-soft); opacity: .7; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; cursor: pointer; }
.chart .dot.won { stroke: var(--good); }
.chart .axis { fill: var(--faint); font-size: 11px; font-family: var(--font); }
.chart-note { min-height: 3em; font-size: .9rem; color: var(--muted); }
.reveal dt { font-weight: 700; margin-top: 8px; }
.reveal dd { margin: 2px 0 0; color: var(--muted); }
details.transcript summary { cursor: pointer; font-weight: 600; }
.transcript-body { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; }
.hidden-note {
  align-self: flex-start; margin: 2px 0 8px 36px; font-size: .78rem; color: var(--muted);
  background: var(--surface-2); border-radius: 8px; padding: 3px 9px;
}
.center-box { display: grid; justify-items: center; gap: 14px; text-align: center; padding: 40px 10px; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ตาราง ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.table tr:hover td { background: var(--surface-2); }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 14px; }

/* ── การแจ้งเตือน ─────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }

@media (max-width: 640px) {
  h1 { font-size: 1.3rem; }
  .brand span { display: none; }
  .topbar-inner { gap: 6px; padding: 8px 10px; }
  .brand b { font-size: .95rem; }
  .nav { gap: 0; flex-wrap: nowrap; }
  .nav a, .nav button { padding: 6px 7px; font-size: .82rem; white-space: nowrap; }
  .levels { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .level span { font-size: .72rem; }
  .result-head { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .bubble { max-width: 84%; }
  .page { padding-top: 16px; }
}
