/* ==========================================================================
   Kroo8 — Components
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  --btn-h: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-h); padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-sm); font-weight: 650; letter-spacing: -.005em;
  white-space: nowrap; text-decoration: none;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), opacity var(--dur-1);
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.995); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); box-shadow: var(--sh-2); }
.btn-primary:hover { background: var(--btn-primary-bg-h); color: var(--btn-primary-fg); box-shadow: var(--sh-3); }

.btn-accent { background: var(--accent); color: #fff; box-shadow: var(--sh-2); }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 86%, #000); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-outline { background: var(--surface); border-color: var(--line-2); color: var(--text); }
.btn-outline:hover { border-color: var(--text-3); background: var(--surface); }

.btn-soft { background: var(--accent-soft); color: var(--accent-ink); }
.btn-soft:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }

.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--st-crit) 40%, transparent); color: var(--st-crit); }
.btn-danger:hover { background: color-mix(in srgb, var(--st-crit) 10%, transparent); }

.btn-lg  { --btn-h: 52px; padding: 0 26px; font-size: var(--fs-md); }
.btn-xl  { --btn-h: 58px; padding: 0 32px; font-size: var(--fs-md); }
.btn-sm  { --btn-h: 34px; padding: 0 13px; font-size: var(--fs-xs); }
.btn-xs  { --btn-h: 28px; padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-icon { width: var(--btn-h); padding: 0; border-radius: var(--r-pill); }
.btn-square { border-radius: var(--r-md); }

.iconbtn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--r-pill);
  background: transparent; color: var(--text-2); font-size: 16px; line-height: 1;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn.on { background: var(--surface-2); color: var(--text); }

/* --------------------------------------------------------------------------
   Cards & panels
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card-p   { padding: var(--s-5); }
.card-p6  { padding: var(--s-6); }
.card-p7  { padding: var(--s-7); }
.card-hover { transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), border-color var(--dur-2); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--sh-3); border-color: var(--line-2); }
.card-flat { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.card-quiet { background: transparent; border-style: dashed; box-shadow: none; }

.panel {
  background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-4);
  border: 1px solid transparent;
}
.panel-accent {
  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 22%, transparent);
}

.divider { height: 1px; background: var(--line); border: 0; margin-block: var(--s-5); }
.vdiv { width: 1px; align-self: stretch; background: var(--line); }

/* --------------------------------------------------------------------------
   Badges / chips / pills
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 650; line-height: 1.6;
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-outline { background: transparent; border: 1px solid var(--line-2); }
.badge-ink { background: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

/* status badges — สีมาพร้อมไอคอน + ข้อความเสมอ (ไม่ใช้สีลำพัง) */
.badge-good { background: color-mix(in srgb, var(--st-good) 14%, var(--surface)); color: color-mix(in srgb, var(--st-good) 78%, var(--text)); }
.badge-warn { background: color-mix(in srgb, var(--st-warn) 20%, var(--surface)); color: color-mix(in srgb, #8a5b00 82%, var(--text)); }
.badge-crit { background: color-mix(in srgb, var(--st-crit) 14%, var(--surface)); color: color-mix(in srgb, var(--st-crit) 82%, var(--text)); }
:root[data-theme="dark"] .badge-warn { color: var(--st-warn); }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: all var(--dur-1) var(--ease);
}
.chip:hover { border-color: var(--text-3); color: var(--text); text-decoration: none; transform: translateY(-1px); }
.chip.on { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.chip-sm { padding: 5px 11px; font-size: var(--fs-xs); }

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label, .lbl {
  font-size: var(--fs-sm); font-weight: 650; color: var(--text);
}
.hint { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.55; }

.input, .select, .textarea {
  width: 100%; padding: 11px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  font-size: var(--fs-base); line-height: 1.5;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.65; }
.select { appearance: none; padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 13px) 50%;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
}

/* big search field */
.searchbox {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-xl); padding: 7px 7px 7px var(--s-5);
  box-shadow: var(--sh-3);
  transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-2);
}
.searchbox:focus-within { border-color: var(--focus); box-shadow: var(--sh-4), 0 0 0 4px color-mix(in srgb, var(--focus) 16%, transparent); }
.searchbox input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-size: var(--fs-md); padding: 12px 0; color: var(--text);
}
.searchbox input::placeholder { color: var(--text-3); }
@media (max-width: 560px) {
  .searchbox { flex-direction: column; align-items: stretch; border-radius: var(--r-lg); padding: var(--s-3); }
  .searchbox input { padding: 6px 8px; }
}

/* option cards (radio group) */
.optgrid { display: grid; gap: var(--s-3); }
.opt {
  position: relative; display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-4); border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); cursor: pointer; text-align: left;
  transition: all var(--dur-1) var(--ease);
}
.opt:hover { border-color: var(--text-3); transform: translateY(-1px); }
.opt.on { border-color: var(--btn-primary-bg); background: var(--surface); box-shadow: var(--sh-2); }
.opt.on::after {
  content: "✓"; position: absolute; top: 10px; right: 12px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
}
.opt-ico { font-size: 22px; line-height: 1.2; flex: 0 0 auto; }
.opt-ttl { display: block; font-weight: 700; font-size: var(--fs-base); }
.opt-desc { display: block; font-size: var(--fs-xs); color: var(--text-2); line-height: 1.55; margin-top: 2px; }

/* checkbox / switch */
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { width: 19px; height: 19px; margin: 2px 0 0; accent-color: var(--btn-primary-bg); flex: 0 0 auto; cursor: pointer; }
.check-txt { font-size: var(--fs-sm); line-height: 1.6; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 44px; height: 26px; border-radius: 99px; background: var(--surface-3);
  position: relative; transition: background var(--dur-2) var(--ease); flex: 0 0 auto;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: var(--sh-1);
  transition: transform var(--dur-2) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--st-good); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* segmented control */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: var(--r-pill);
}
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  padding: 6px 14px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap;
  transition: all var(--dur-1) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }
:root[data-theme="dark"] .seg button.on { background: var(--surface-3); }

/* --------------------------------------------------------------------------
   Progress
   -------------------------------------------------------------------------- */
.bar {
  height: 8px; border-radius: 99px; background: var(--surface-3);
  overflow: hidden; position: relative;
}
.bar > i {
  display: block; height: 100%; border-radius: 99px;
  background: var(--accent);
  transition: width var(--dur-3) var(--ease-out);
}
.bar-sm { height: 5px; }
.bar-lg { height: 12px; }
.bar-ink > i { background: var(--btn-primary-bg); }
.bar-good > i { background: var(--st-good); }

.bar-stripe > i {
  background-image: linear-gradient(100deg,
    color-mix(in srgb, #fff 26%, transparent) 25%, transparent 25%, transparent 50%,
    color-mix(in srgb, #fff 26%, transparent) 50%, color-mix(in srgb, #fff 26%, transparent) 75%,
    transparent 75%);
  background-size: 18px 18px;
  animation: barmove 900ms linear infinite;
}
@keyframes barmove { to { background-position: 18px 0; } }

.ring { --p: 0; --sz: 132px; width: var(--sz); height: var(--sz); position: relative; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-3); }
.ring-fill  { fill: none; stroke: var(--accent); stroke-linecap: round;
              transition: stroke-dashoffset var(--dur-3) var(--ease-out); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 0; }
.ring-num { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.ring-cap { font-size: 10.5px; color: var(--text-3); letter-spacing: .05em; text-transform: uppercase; margin-top: 4px; }

/* skeleton */
.sk { background: var(--surface-2); border-radius: var(--r-sm); position: relative; overflow: hidden; }
.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.sk-line { height: 13px; margin-bottom: 9px; }
.sk-line:nth-child(3n) { width: 72%; }
.sk-line:nth-child(3n+1) { width: 91%; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, currentColor 24%, transparent);
  border-top-color: currentColor; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dots::after {
  content: "···"; display: inline-block; letter-spacing: 2px;
  animation: dots 1.2s steps(4, end) infinite; width: 1.4em; text-align: left; overflow: hidden;
  vertical-align: bottom;
}
@keyframes dots { 0% { width: 0; } 100% { width: 1.4em; } }

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
.toasts {
  position: fixed; z-index: 200; right: var(--s-5); bottom: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2); pointer-events: none;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--hairline);
  border-left: 3px solid var(--text-3);
  border-radius: var(--r-md); box-shadow: var(--sh-4);
  padding: 12px 14px; font-size: var(--fs-sm); line-height: 1.55;
  animation: toastin var(--dur-3) var(--ease-out);
}
.toast.ok   { border-left-color: var(--st-good); }
.toast.warn { border-left-color: var(--st-warn); }
.toast.err  { border-left-color: var(--st-crit); }
.toast-ico { font-size: 16px; line-height: 1.4; flex: 0 0 auto; }
.toast.out { animation: toastout var(--dur-2) var(--ease) forwards; }
@keyframes toastin  { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes toastout { to   { opacity: 0; transform: translateX(20px); } }
@media (max-width: 940px) { .toasts { bottom: 82px; } }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-root:empty, .sheet-root:empty { display: none; }
.modal-bg {
  position: fixed; inset: 0; z-index: 150; background: var(--overlay);
  display: grid; place-items: center; padding: var(--s-5);
  animation: fadein var(--dur-2) var(--ease); backdrop-filter: blur(3px);
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--sh-4); padding: var(--s-6);
  animation: modalin var(--dur-3) var(--ease-out);
}
.modal-lg { max-width: 720px; }
@keyframes modalin { from { opacity: 0; transform: translateY(18px) scale(.97); } }
.modal-head { display: flex; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-4); }
.modal-head h3 { flex: 1; font-size: var(--fs-lg); }
.modal-foot { display: flex; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-6); flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Side sheet (AI tutor)
   -------------------------------------------------------------------------- */
.sheet-bg {
  position: fixed; inset: 0; z-index: 150; background: var(--overlay);
  animation: fadein var(--dur-2) var(--ease);
}
.sheet {
  position: fixed; inset: 0 0 0 auto; z-index: 151;
  width: min(460px, 100vw); background: var(--surface);
  border-left: 1px solid var(--hairline); box-shadow: var(--sh-4);
  display: flex; flex-direction: column;
  animation: sheetin var(--dur-3) var(--ease-out);
}
@keyframes sheetin { from { transform: translateX(100%); } }
.sheet-head {
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s-3);
}
.sheet-body { flex: 1; overflow: auto; padding: var(--s-5); }
.sheet-foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); background: var(--surface); }
@media (max-width: 620px) {
  .sheet { inset: auto 0 0 0; width: 100%; height: 86vh; border-radius: var(--r-xl) var(--r-xl) 0 0; border-left: 0; }
  @keyframes sheetin { from { transform: translateY(100%); } }
}

/* chat bubbles */
.chat { display: flex; flex-direction: column; gap: var(--s-3); }
.bub { max-width: 92%; padding: 11px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.68; }
.bub-me { align-self: flex-end; background: var(--btn-primary-bg); color: var(--btn-primary-fg); border-bottom-right-radius: var(--r-xs); }
.bub-ai { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: var(--r-xs); }
.bub-ai strong { color: var(--text); }
.bub-ai ul { margin: .5em 0; padding-left: 1.2em; }
.bub-src { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 9px; }
.ctx-quote {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: 9px 12px; border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--fs-xs); color: var(--text-2); line-height: 1.6;
  max-height: 92px; overflow: hidden;
}

/* --------------------------------------------------------------------------
   Tooltip
   -------------------------------------------------------------------------- */
.tip {
  position: fixed; z-index: 300; pointer-events: none;
  background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  padding: 8px 11px; border-radius: var(--r-sm); font-size: var(--fs-xs);
  line-height: 1.5; box-shadow: var(--sh-3); max-width: 260px;
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 700; }
.tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tip-sw { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--r-md); background: var(--surface); }
.tbl { width: 100%; font-size: var(--fs-sm); }
.tbl th, .tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl thead th {
  background: var(--surface-2); font-size: var(--fs-xs); font-weight: 700;
  color: var(--text-2); text-transform: uppercase; letter-spacing: .05em;
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl-compact th, .tbl-compact td { padding: 8px 11px; }

/* --------------------------------------------------------------------------
   Accordion
   -------------------------------------------------------------------------- */
.acc { border: 1px solid var(--hairline); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.acc + .acc { margin-top: var(--s-2); }
.acc summary {
  padding: var(--s-4) var(--s-5); cursor: pointer; font-weight: 650;
  display: flex; align-items: center; gap: var(--s-3); list-style: none;
  font-size: var(--fs-base);
}
.acc summary::-webkit-details-marker { display: none; }
.acc summary::after {
  content: "＋"; margin-left: auto; color: var(--text-3); font-size: 17px;
  transition: transform var(--dur-2) var(--ease); flex: 0 0 auto;
}
.acc[open] summary::after { content: "－"; }
.acc summary:hover { background: var(--surface-2); }
.acc-body { padding: 0 var(--s-5) var(--s-5); color: var(--text-2); font-size: var(--fs-sm); line-height: 1.75; }

/* --------------------------------------------------------------------------
   Stat tiles + charts
   -------------------------------------------------------------------------- */
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--sh-1);
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.tile-cap { font-size: var(--fs-xs); color: var(--text-2); font-weight: 650; letter-spacing: .01em; }
.tile-val { font-size: 32px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.tile-val .unit { font-size: 15px; font-weight: 650; color: var(--text-2); margin-left: 3px; letter-spacing: 0; }
.tile-sub { font-size: var(--fs-xs); color: var(--text-3); }
.tile-delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 700; }
.tile-delta.up   { color: color-mix(in srgb, var(--st-good) 80%, var(--text)); }
.tile-delta.down { color: color-mix(in srgb, var(--st-crit) 82%, var(--text)); }

.chartcard { background: var(--chart-surface); border: 1px solid var(--hairline); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--sh-1); }
.chart-head { display: flex; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-4); }
.chart-title { font-size: var(--fs-base); font-weight: 700; }
.chart-note { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.chart-body svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--s-4); margin-top: var(--s-4); font-size: var(--fs-xs); color: var(--text-2); }
.chart-legend .lg-item { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend .lg-sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.chart-tblview { margin-top: var(--s-4); }
.chart-axis   { font-size: 11px; fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart-vlabel { font-size: 11.5px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.chart-rlabel { font-size: 12px; fill: var(--text); }
.chart-grid   { stroke: var(--grid); stroke-width: 1; }
.chart-base   { stroke: var(--axis); stroke-width: 1; }
.chart-hit    { fill: transparent; cursor: crosshair; }
.chart-cross  { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }

/* --------------------------------------------------------------------------
   Course / lesson content bits
   -------------------------------------------------------------------------- */
.cover-art { border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); position: relative; }
.cover-art svg { width: 100%; height: 100%; display: block; }

.figure { margin: var(--s-6) 0; }
.figure .fig-frame { border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--hairline); background: var(--surface-2); position: relative; }
.figure figcaption { margin-top: 9px; font-size: var(--fs-xs); color: var(--text-2); line-height: 1.6; display: flex; gap: 7px; align-items: flex-start; }
.figure figcaption .fig-n { font-weight: 700; color: var(--text); flex: 0 0 auto; }
.ai-tag {
  position: absolute; right: 8px; bottom: 8px; z-index: 2;
  background: color-mix(in srgb, #0b0d12 62%, transparent); color: #fff;
  font-size: 10px; padding: 3px 8px; border-radius: var(--r-pill);
  backdrop-filter: blur(4px); letter-spacing: .03em; font-weight: 600;
}

.callout {
  border-radius: var(--r-md); padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5);
  border-left: 4px solid var(--text-3); background: var(--surface-2);
  margin: var(--s-5) 0; font-size: .98em;
}
.callout-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: var(--fs-sm); margin-bottom: 6px; }
.callout.tip  { border-left-color: var(--st-good); background: color-mix(in srgb, var(--st-good) 8%, var(--surface)); }
.callout.warn { border-left-color: var(--st-warn); background: color-mix(in srgb, var(--st-warn) 12%, var(--surface)); }
.callout.crit { border-left-color: var(--st-crit); background: color-mix(in srgb, var(--st-crit) 8%, var(--surface)); }
.callout.note { border-left-color: var(--accent); background: var(--accent-soft); }

.srcpill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: var(--r-xs);
  background: var(--surface-3); color: var(--text-2);
  font-size: 11px; font-weight: 700; text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.srcpill:hover { background: var(--btn-primary-bg); color: var(--btn-primary-fg); text-decoration: none; }

.factlist { display: flex; flex-direction: column; gap: var(--s-3); margin: var(--s-5) 0; }
.fact {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--hairline);
}
.fact-ck { color: var(--st-good); font-size: 15px; line-height: 1.6; flex: 0 0 auto; }
.fact-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; font-size: var(--fs-xs); color: var(--text-3); }

.stepsbox { counter-reset: st; margin: var(--s-5) 0; }
.stepsbox .st {
  display: flex; gap: var(--s-4); padding: var(--s-3) 0;
  border-bottom: 1px dashed var(--line);
}
.stepsbox .st:last-child { border-bottom: 0; }
.stepsbox .st::before {
  counter-increment: st; content: counter(st);
  width: 27px; height: 27px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 800;
  font-variant-numeric: tabular-nums; margin-top: 2px;
}

.objbox {
  background: var(--accent-soft); border-radius: var(--r-md);
  padding: var(--s-5); margin-bottom: var(--s-6);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}
.objbox h4 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); margin-bottom: 10px; }
.objbox ul { margin: 0; padding-left: 1.15em; }
.objbox li { color: var(--text); }

/* checklist */
.cklist { display: flex; flex-direction: column; gap: 2px; }
.ck {
  display: flex; gap: 11px; align-items: flex-start; padding: 11px 13px;
  border-radius: var(--r-md); cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}
.ck:hover { background: var(--surface-2); }
.ck input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--st-good); flex: 0 0 auto; cursor: pointer; }
.ck.done .ck-t { text-decoration: line-through; color: var(--text-3); }
.ck-t { font-size: var(--fs-sm); line-height: 1.62; }

/* quiz */
.quiz { display: flex; flex-direction: column; gap: var(--s-5); }
.qz { border: 1px solid var(--hairline); border-radius: var(--r-md); padding: var(--s-5); background: var(--surface); }
.qz-q { font-weight: 650; margin-bottom: var(--s-3); display: flex; gap: 9px; }
.qz-q .qn { color: var(--text-3); font-weight: 800; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.qz-opts { display: flex; flex-direction: column; gap: 7px; }
.qz-opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 10px 13px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); font-size: var(--fs-sm); line-height: 1.6;
  transition: all var(--dur-1) var(--ease); width: 100%;
}
.qz-opt:hover:not(:disabled) { border-color: var(--text-3); }
.qz-opt .qk {
  width: 21px; height: 21px; border-radius: 50%; background: var(--surface-2);
  display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: 0 0 auto;
}
.qz-opt.picked { border-color: var(--btn-primary-bg); }
.qz-opt.right { border-color: var(--st-good); background: color-mix(in srgb, var(--st-good) 9%, var(--surface)); }
.qz-opt.right .qk { background: var(--st-good); color: #fff; }
.qz-opt.wrong { border-color: var(--st-crit); background: color-mix(in srgb, var(--st-crit) 8%, var(--surface)); }
.qz-opt.wrong .qk { background: var(--st-crit); color: #fff; }
.qz-why { margin-top: var(--s-3); font-size: var(--fs-xs); color: var(--text-2); line-height: 1.7;
          background: var(--surface-2); padding: 10px 13px; border-radius: var(--r-sm); }
.qz-score {
  display: flex; align-items: center; gap: var(--s-4); padding: var(--s-5);
  border-radius: var(--r-md); background: var(--surface-2);
}
.qz-score .big { font-size: 30px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

/* ask-AI affordance on paragraphs */
.askable { position: relative; }
.askbtn {
  position: absolute; top: -2px; right: -40px; width: 30px; height: 30px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 13px; color: var(--text-3);
  opacity: 0; transform: scale(.9); transition: all var(--dur-1) var(--ease);
  box-shadow: var(--sh-1);
}
.askable:hover .askbtn, .askbtn:focus-visible { opacity: 1; transform: scale(1); }
.askbtn:hover { color: var(--text); border-color: var(--text-3); }
@media (max-width: 1240px) { .askbtn { right: -2px; top: -34px; } }

/* --------------------------------------------------------------------------
   เครื่องเล่นวิดีโอสรุปบท (จริง + สตอรีบอร์ดสาธิต)
   -------------------------------------------------------------------------- */
.vwrap { margin: var(--s-5) 0; }
.vplayer-real { width: 100%; border-radius: var(--r-md); display: block; background: #000; }
.vplayer {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--r-md);
  overflow: hidden; cursor: pointer; user-select: none;
  background: linear-gradient(140deg,
    color-mix(in srgb, var(--accent) 88%, #0b0d12) 0%,
    color-mix(in srgb, var(--accent) 42%, #0b0d12) 55%,
    #14161c 100%);
  border: 1px solid var(--hairline);
}
.vplayer::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.20), transparent 62%);
}
.vstage { position: absolute; inset: 0; }
.vscene {
  position: absolute; inset: 0; margin: 0; padding: 8% 10%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px; color: #fff;
  opacity: 0; transform: translateY(10px) scale(.985);
  transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out);
}
.vscene.on { opacity: 1; transform: none; }
.vscene-ico { font-size: clamp(30px, 6vw, 54px); line-height: 1; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.vscene-t { font-size: clamp(15px, 2.3vw, 22px); font-weight: 800; letter-spacing: -.015em; text-shadow: 0 2px 10px rgba(0,0,0,.35); }
.vscene-c { font-size: clamp(11.5px, 1.5vw, 14.5px); line-height: 1.6; max-width: 46ch; opacity: .93; text-shadow: 0 1px 8px rgba(0,0,0,.4); }
.vplay {
  position: absolute; left: 14px; bottom: 14px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.92); color: #14161c; font-size: 14px;
  display: grid; place-items: center; box-shadow: var(--sh-2);
  transition: transform var(--dur-1) var(--ease);
}
.vplay:hover { transform: scale(1.07); }
.vbar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.22); z-index: 2; }
.vbar > i { display: block; height: 100%; width: 0; background: #fff; transition: width .12s linear; }
.vcount {
  position: absolute; right: 14px; bottom: 16px; z-index: 3;
  font-size: 11.5px; font-variant-numeric: tabular-nums; color: rgba(255,255,255,.9);
  background: rgba(0,0,0,.32); padding: 3px 9px; border-radius: var(--r-pill); backdrop-filter: blur(4px);
}
.vmeta {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s-3);
  flex-wrap: wrap; margin-top: 9px; font-size: var(--fs-xs); color: var(--text-2);
}

/* --------------------------------------------------------------------------
   การ์ดเลือกโมเดลสร้างสื่อ
   -------------------------------------------------------------------------- */
.mgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: var(--s-3); }
.mcard {
  position: relative; text-align: left; padding: var(--s-4);
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  display: flex; flex-direction: column; gap: 7px; cursor: pointer;
  transition: all var(--dur-1) var(--ease);
}
.mcard:hover { border-color: var(--text-3); transform: translateY(-2px); box-shadow: var(--sh-2); }
.mcard.on { border-color: var(--btn-primary-bg); box-shadow: var(--sh-2); }
.mcard.on::after {
  content: "✓"; position: absolute; top: 9px; right: 11px;
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  display: grid; place-items: center; font-size: 10.5px; font-weight: 800;
}
.mcard-h { display: flex; align-items: center; gap: 8px; }
.mcard-ico { font-size: 20px; line-height: 1; }
.mcard-n { font-weight: 750; font-size: var(--fs-sm); line-height: 1.25; }
.mcard-v { font-size: 10.5px; color: var(--text-3); }
.mcard-p { display: flex; gap: 9px; flex-wrap: wrap; font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.mcard-p b { color: var(--text); font-weight: 700; }
.mcard-s { font-size: var(--fs-xs); color: var(--text-2); line-height: 1.55; }
.mcard-tag {
  align-self: flex-start; font-size: 10px; font-weight: 700; padding: 2px 8px;
  border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent-ink);
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty {
  text-align: center; padding: var(--s-10) var(--s-5);
  border: 1.5px dashed var(--line-2); border-radius: var(--r-xl); background: var(--surface);
}
.empty-ico { font-size: 46px; margin-bottom: var(--s-4); }
.empty h3 { margin-bottom: 8px; }
.empty p { color: var(--text-2); max-width: 44ch; margin-inline: auto; }

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px var(--s-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }

.log {
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
  font-family: var(--font-mono); font-size: 11.8px; line-height: 1.85;
  max-height: 258px; overflow-y: auto;
}
.log-line { display: flex; gap: 10px; }
.log-t { color: var(--text-3); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.log-m { min-width: 0; word-break: break-word; }
.log-line.ok  .log-m { color: color-mix(in srgb, var(--st-good) 78%, var(--text)); }
.log-line.warn .log-m { color: color-mix(in srgb, #8a5b00 80%, var(--text)); }
.log-line.err .log-m { color: color-mix(in srgb, var(--st-crit) 84%, var(--text)); }
:root[data-theme="dark"] .log-line.warn .log-m { color: var(--st-warn); }

.crumbs { display: flex; align-items: center; gap: 7px; font-size: var(--fs-xs); color: var(--text-3); flex-wrap: wrap; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { opacity: .5; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  background: var(--surface-3); color: var(--text);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.credit-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: var(--r-pill); background: var(--surface-2);
  font-size: var(--fs-xs); font-weight: 700; font-variant-numeric: tabular-nums;
}
