/* Mastery LMS — design system (plain CSS; Tailwind CDN handles utilities)
   Palette: ink navy + warm paper + amber accent (theme-able through CSS variables) */
:root {
  --ink: 16 35 61;          /* #10233d */
  --accent: 232 163 61;     /* #e8a33d */
  --paper: 246 244 239;     /* #f6f4ef */
  --leaf: 15 138 106;       /* success */
  --rose: 200 58 72;        /* danger */
  --radius: 18px;
  --shadow: 0 1px 2px rgb(16 35 61 / .05), 0 8px 28px -12px rgb(16 35 61 / .18);
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Prompt', 'Sarabun', system-ui, sans-serif;
  background: rgb(var(--paper));
  color: rgb(28 43 58);
  min-height: 100vh;
}
.app-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40rem 28rem at 8% -6%, rgb(var(--accent) / .18), transparent 60%),
    radial-gradient(36rem 30rem at 100% 0%, rgb(var(--ink) / .10), transparent 60%),
    radial-gradient(40rem 30rem at 50% 120%, rgb(var(--leaf) / .10), transparent 60%),
    rgb(var(--paper));
}

/* ---------- Surfaces ---------- */
.glass-card {
  background: rgb(255 255 255 / .72);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgb(255 255 255 / .9);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.glass-bar {
  background: rgb(255 255 255 / .78);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgb(16 35 61 / .06);
}
.section-title { font-size: 1.05rem; font-weight: 600; color: rgb(var(--ink)); display: flex; align-items: center; gap: .5rem; }
.muted { color: rgb(89 104 122); }
.divider { border-top: 1px solid rgb(16 35 61 / .08); }

/* ---------- Buttons ---------- */
.btn, .btn-primary, .btn-accent, .btn-ghost, .btn-danger, .btn-soft {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1.05rem; border-radius: 12px; font-weight: 500; font-size: .92rem;
  line-height: 1.2; transition: transform .12s ease, background-color .15s ease, box-shadow .15s ease;
  cursor: pointer; border: 1px solid transparent; text-decoration: none; white-space: nowrap;
  min-height: 42px;
}
.btn-sm { padding: .35rem .7rem; font-size: .82rem; min-height: 34px; border-radius: 10px; }
.btn-primary { background: rgb(var(--ink)); color: #fff; box-shadow: 0 6px 16px -8px rgb(var(--ink) / .7); }
.btn-primary:hover { background: rgb(var(--ink) / .9); transform: translateY(-1px); }
.btn-accent { background: rgb(var(--accent)); color: rgb(40 26 4); box-shadow: 0 6px 16px -8px rgb(var(--accent) / .9); }
.btn-accent:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-ghost { background: rgb(255 255 255 / .7); color: rgb(var(--ink)); border-color: rgb(16 35 61 / .12); }
.btn-ghost:hover { background: #fff; }
.btn-soft { background: rgb(var(--ink) / .06); color: rgb(var(--ink)); }
.btn-soft:hover { background: rgb(var(--ink) / .1); }
.btn-danger { background: rgb(var(--rose)); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
button:disabled, .btn-disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ---------- Forms ---------- */
.label { display: block; font-size: .85rem; font-weight: 500; color: rgb(51 65 85); margin-bottom: .3rem; }
.hint { font-size: .78rem; color: rgb(89 104 122); margin-top: .25rem; }
.input, .select, .textarea {
  width: 100%; border-radius: 12px; border: 1px solid rgb(16 35 61 / .16);
  background: rgb(255 255 255 / .9); padding: .6rem .8rem; font-size: .95rem; color: rgb(15 23 42);
  transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
.textarea { min-height: 96px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: rgb(var(--ink) / .6); box-shadow: 0 0 0 4px rgb(var(--accent) / .25); }
.check { width: 1.1rem; height: 1.1rem; accent-color: rgb(var(--ink)); }
.field-error { color: rgb(var(--rose)); font-size: .8rem; margin-top: .25rem; }

/* ---------- Focus / a11y ---------- */
:focus-visible { outline: 3px solid rgb(var(--accent)); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: -9999px; top: .5rem; z-index: 100; background: rgb(var(--ink)); color: #fff; padding: .6rem 1rem; border-radius: 10px; }
.skip-link:focus { left: .5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ---------- Navigation ---------- */
.side-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .8rem; border-radius: 12px; color: rgb(51 65 85); font-size: .92rem; }
.side-link:hover { background: rgb(var(--ink) / .05); color: rgb(var(--ink)); }
.side-link.active { background: rgb(var(--ink)); color: #fff; box-shadow: 0 8px 18px -10px rgb(var(--ink) / .8); }
.side-link .ico { width: 1.25rem; text-align: center; font-size: 1.05rem; }
.side-group { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: rgb(100 116 139); padding: 1rem .8rem .35rem; }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem; color: rgb(71 85 105); padding: .4rem 0; }
.bottom-nav a.active { color: rgb(var(--ink)); font-weight: 600; }
.bottom-nav .ico { font-size: 1.25rem; line-height: 1; }

/* ---------- Data ---------- */
.kpi { padding: 1.1rem 1.2rem; }
.kpi .kpi-label { font-size: .8rem; color: rgb(100 116 139); }
.kpi .kpi-value { font-size: 1.75rem; font-weight: 600; color: rgb(var(--ink)); line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .75rem; color: rgb(100 116 139); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
.table th { text-align: left; font-weight: 500; font-size: .78rem; color: rgb(100 116 139); padding: .6rem .75rem; border-bottom: 1px solid rgb(16 35 61 / .08); white-space: nowrap; }
.table th.text-right { text-align: right; }
.table th.text-center { text-align: center; }
.table td { padding: .7rem .75rem; border-bottom: 1px solid rgb(16 35 61 / .06); vertical-align: middle; }
.table tr:hover td { background: rgb(255 255 255 / .6); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pill { display: inline-flex; align-items: center; gap: .25rem; padding: .12rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 500; }
.progress { height: .55rem; border-radius: 999px; background: rgb(var(--ink) / .08); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, rgb(var(--ink)), rgb(var(--ink) / .75)); transition: width .6s ease; }
.progress.accent > span { background: linear-gradient(90deg, rgb(var(--accent)), rgb(var(--accent) / .8)); }
.progress.leaf > span { background: linear-gradient(90deg, rgb(var(--leaf)), rgb(var(--leaf) / .8)); }

/* ---------- Lesson content ---------- */
.prose-lms { line-height: 1.8; font-size: 1rem; color: rgb(30 41 59); }
.prose-lms h2 { font-size: 1.3rem; font-weight: 600; margin: 1.2rem 0 .5rem; color: rgb(var(--ink)); }
.prose-lms h3 { font-size: 1.12rem; font-weight: 600; margin: 1rem 0 .4rem; }
.prose-lms p { margin: .6rem 0; }
.prose-lms ul { list-style: disc; padding-left: 1.4rem; margin: .5rem 0; }
.prose-lms ol { list-style: decimal; padding-left: 1.4rem; margin: .5rem 0; }
.prose-lms a { color: rgb(var(--ink)); text-decoration: underline; text-underline-offset: 3px; }
.prose-lms blockquote { border-left: 4px solid rgb(var(--accent)); padding: .3rem 1rem; background: rgb(var(--accent) / .08); border-radius: 0 10px 10px 0; }
.prose-lms code { background: rgb(var(--ink) / .07); padding: .1rem .35rem; border-radius: 6px; font-size: .9em; }
.prose-lms pre { background: rgb(var(--ink)); color: #e2e8f0; padding: 1rem; border-radius: 12px; overflow-x: auto; }
.prose-lms img { border-radius: 12px; max-width: 100%; height: auto; }
.prose-lms table { border-collapse: collapse; }
.prose-lms td, .prose-lms th { border: 1px solid rgb(16 35 61 / .15); padding: .4rem .6rem; }

.video-shell { position: relative; border-radius: 16px; overflow: hidden; background: #0b1524; aspect-ratio: 16/9; }
.video-shell video, .video-shell iframe, .video-shell .yt-host { width: 100%; height: 100%; display: block; border: 0; }
.video-watermark { position: absolute; pointer-events: none; color: rgb(255 255 255 / .35); font-size: .8rem; font-weight: 500; text-shadow: 0 1px 2px rgb(0 0 0 / .5); transition: top 2s ease, left 2s ease; user-select: none; }
.video-guard { position: absolute; inset: 0; display: none; place-items: center; background: rgb(11 21 36 / .78); color: #fff; text-align: center; padding: 1.5rem; }
.video-guard.show { display: grid; }

/* ---------- Kids adventure map ---------- */
.kids-world {
  background:
    radial-gradient(circle at 20% 20%, #fff7d6 0 12%, transparent 13%),
    radial-gradient(circle at 80% 10%, #ffe6f0 0 10%, transparent 11%),
    linear-gradient(180deg, #bfe9ff 0%, #d9f5e5 55%, #b8e6b0 100%);
  border-radius: 28px; position: relative; overflow: hidden;
}
.kids-stage { position: relative; }
.kids-node {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem;
  background: #fff; border: 5px solid #fff; box-shadow: 0 6px 0 rgb(0 0 0 / .12), 0 14px 24px -12px rgb(0 0 0 / .35);
  transition: transform .15s ease;
}
.kids-node:hover { transform: translateY(-3px) scale(1.04); }
.kids-node.done { background: #34c38f; color: #fff; }
.kids-node.current { background: #ffd23f; animation: bob 1.8s ease-in-out infinite; }
.kids-node.locked { background: #d7dde5; color: #8a97a8; filter: grayscale(.4); }
.kids-node.review { background: #ff9f43; color: #fff; }
.kids-node.boss { width: 104px; height: 104px; font-size: 2.6rem; background: #6c5ce7; color: #fff; }
.kids-path { stroke: #fff; stroke-width: 10; stroke-dasharray: 2 18; stroke-linecap: round; fill: none; opacity: .9; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.kids-font { font-family: 'Mitr', 'Prompt', sans-serif; }

/* ---------- Teen missions ---------- */
.teen-card { background: linear-gradient(135deg, rgb(var(--ink)) 0%, rgb(30 58 95) 100%); color: #fff; border-radius: 20px; }
.teen-chip { background: rgb(255 255 255 / .12); border: 1px solid rgb(255 255 255 / .2); border-radius: 999px; padding: .15rem .6rem; font-size: .75rem; }

/* ---------- Timeline (adult) ---------- */
.timeline { position: relative; padding-left: 1.6rem; }
.timeline::before { content: ''; position: absolute; left: .45rem; top: .3rem; bottom: .3rem; width: 2px; background: rgb(var(--ink) / .15); }
.timeline-dot { position: absolute; left: -1.6rem; top: .35rem; width: 1.05rem; height: 1.05rem; border-radius: 50%; background: #fff; border: 3px solid rgb(var(--ink) / .3); }
.timeline-dot.done { background: rgb(var(--leaf)); border-color: rgb(var(--leaf)); }
.timeline-dot.current { border-color: rgb(var(--accent)); box-shadow: 0 0 0 4px rgb(var(--accent) / .25); }

/* ---------- Builder ---------- */
.block-item { cursor: default; }
.drag-handle { cursor: grab; touch-action: none; }
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 12px 30px -12px rgb(16 35 61 / .45); }
.rule-group { border: 1px dashed rgb(16 35 61 / .25); border-radius: 14px; padding: .75rem; background: rgb(255 255 255 / .5); }

/* ---------- Quiz ---------- */
.choice { display: flex; gap: .7rem; align-items: flex-start; padding: .75rem .9rem; border: 1.5px solid rgb(16 35 61 / .12); border-radius: 14px; background: #fff; cursor: pointer; transition: border-color .15s, background .15s; }
.choice:hover { border-color: rgb(var(--ink) / .35); }
.choice:has(input:checked) { border-color: rgb(var(--ink)); background: rgb(var(--ink) / .04); }
.choice.correct { border-color: rgb(var(--leaf)); background: rgb(var(--leaf) / .08); }
.choice.wrong { border-color: rgb(var(--rose)); background: rgb(var(--rose) / .06); }
.order-item { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; background: #fff; border: 1px solid rgb(16 35 61 / .12); border-radius: 12px; }

/* ---------- Image questions (hotspot / drag labels onto a picture) ---------- */
.imgq-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; border-radius: 12px; overflow: hidden; background: #fff; border: 1px solid rgb(16 35 61 / .14); -webkit-user-select: none; user-select: none; }
.imgq-img { display: block; max-width: 100%; height: auto; max-height: 70vh; -webkit-user-drag: none; }
.imgq-click { cursor: crosshair; touch-action: manipulation; }
.imgq-marker { position: absolute; transform: translate(-50%, -50%); width: 28px; height: 28px; border-radius: 50%; background: rgb(var(--accent)); color: rgb(40 26 4); border: 2px solid #fff; box-shadow: 0 2px 8px rgb(0 0 0 / .35); font-size: .75rem; font-weight: 600; line-height: 24px; text-align: center; cursor: pointer; padding: 0; }
.imgq-marker.is-view { cursor: default; }
.imgq-marker.ok { background: rgb(var(--leaf)); color: #fff; }
.imgq-marker.bad { background: rgb(var(--rose)); color: #fff; }
.imgq-cursor { position: absolute; width: 34px; height: 34px; transform: translate(-50%, -50%); border: 2px dashed rgb(var(--ink)); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 2px rgb(255 255 255 / .85); }
.imgq-zone { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 4px; border: 2px dashed rgb(var(--ink) / .75); background: rgb(255 255 255 / .6); border-radius: 8px; line-height: 1.2; font-size: .8rem; color: rgb(var(--ink)); cursor: pointer; overflow: visible; text-align: center; word-break: break-word; }
.imgq-zone:hover, .imgq-zone.over { background: rgb(var(--accent) / .32); }
.imgq-zone.filled { border-style: solid; background: rgb(255 255 255 / .94); font-weight: 600; }
.imgq-zone.is-view { cursor: default; }
.imgq-zone.ok { border-color: rgb(var(--leaf)); background: rgb(236 253 245 / .95); }
.imgq-zone.bad { border-color: rgb(var(--rose)); background: rgb(255 241 242 / .95); }
.imgq-key { display: block; font-size: .7rem; font-weight: 500; color: rgb(4 120 87); }
.imgq-no { position: absolute; top: -9px; left: -9px; width: 20px; height: 20px; border-radius: 50%; background: rgb(var(--ink)); color: #fff; font-size: .68rem; line-height: 20px; text-align: center; font-weight: 600; z-index: 1; }
.imgq-no.is-inline { position: relative; top: auto; left: auto; flex: none; display: inline-block; }
.imgq-bank { display: flex; flex-wrap: wrap; gap: .5rem; min-height: 2.9rem; padding: .5rem; border: 1.5px dashed rgb(16 35 61 / .22); border-radius: 12px; background: rgb(255 255 255 / .6); }
.imgq-label { padding: .4rem .8rem; border-radius: 10px; background: #fff; border: 1.5px solid rgb(16 35 61 / .2); font-size: .88rem; cursor: grab; box-shadow: 0 2px 6px -3px rgb(16 35 61 / .4); color: rgb(var(--ink)); }
.imgq-label.selected { border-color: rgb(var(--ink)); background: rgb(var(--accent) / .28); }
.imgq-area { position: absolute; border: 2px solid rgb(var(--leaf)); background: rgb(var(--leaf) / .2); border-radius: 4px; pointer-events: none; }
.imgq-area.ellipse { border-radius: 50%; }
.imgq-editor { cursor: crosshair; touch-action: none; }
.imgq-ez { position: absolute; border: 2px solid rgb(var(--ink)); background: rgb(var(--accent) / .3); border-radius: 4px; cursor: move; line-height: 1.2; }
.imgq-ez.ellipse { border-radius: 50%; }
.imgq-ez.active { box-shadow: 0 0 0 3px rgb(var(--accent)); }
.imgq-ezlabel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgb(255 255 255 / .9); padding: 0 .3rem; border-radius: 6px; font-size: .72rem; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.imgq-handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 4px; background: rgb(var(--ink)); border: 2px solid #fff; cursor: nwse-resize; }
.imgq-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem; border-radius: 12px; border: 1px solid rgb(16 35 61 / .1); background: rgb(255 255 255 / .7); }
.imgq-row.active { border-color: rgb(var(--accent)); box-shadow: 0 0 0 2px rgb(var(--accent) / .35); }
.imgq-numf { display: flex; flex-direction: column; width: 4.6rem; }
/* pop-up menus stay readable over anything behind them (watermarks, images) */
.menu-pop { background: rgb(255 255 255 / .98); }
/* the hidden attribute always hides, also on elements whose class sets a display (buttons, flex rows) */
[hidden] { display: none !important; }
.imgq-dot { position: absolute; width: 10px; height: 10px; transform: translate(-50%, -50%); border-radius: 50%; border: 1.5px solid #fff; opacity: .85; pointer-events: none; }
.imgq-dot.ok { background: rgb(var(--leaf)); }
.imgq-dot.bad { background: rgb(var(--rose)); }

/* ---------- Toast / realtime ---------- */
.live-dot { width: .55rem; height: .55rem; border-radius: 50%; background: rgb(148 163 184); display: inline-block; }
.live-dot.on { background: rgb(var(--leaf)); box-shadow: 0 0 0 0 rgb(var(--leaf) / .6); animation: pulse 2s infinite; }
.live-dot.poll { background: rgb(var(--accent)); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(var(--leaf) / .5); } 70% { box-shadow: 0 0 0 8px rgb(var(--leaf) / 0); } 100% { box-shadow: 0 0 0 0 rgb(var(--leaf) / 0); } }
.fade-up { animation: fadeUp .5s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Certificate ---------- */
.cert-paper { background: #fffdf7; border: 12px solid rgb(var(--ink)); outline: 2px solid rgb(var(--accent)); outline-offset: -22px; aspect-ratio: 1.414/1; position: relative; }

/* ---------- Motion / print ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media print {
  .no-print, header.app-header, aside.app-side, nav.bottom-nav, .app-bg { display: none !important; }
  body { background: #fff; }
  main { padding: 0 !important; margin: 0 !important; }
  .glass-card { box-shadow: none; border: 1px solid #ddd; background: #fff; }
  @page { margin: 12mm; }
}

/* Grid/flex children must be allowed to shrink (prevents horizontal overflow on phones) */
.grid > *, .flex-1 { min-width: 0; }
select.select { max-width: 100%; text-overflow: ellipsis; }
/* status watermark on a refunded receipt / revoked certificate: decoration only (the status is also written out on the page),
   drawn as generated content so it is neither read out nor treated as body text */
.watermark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.watermark::after { content: attr(data-text); font-size: 3.75rem; line-height: 1; font-weight: 700; color: rgb(225 29 72 / .2); transform: rotate(-12deg); }
.watermark.wm-lg::after { font-size: 4.5rem; }
