/* ==========================================================================
   Outer Classroom Skills — Design System (ocs.css)
   ดีไซน์กลาง ใช้ร่วมทุกหน้า แก้ที่นี่ที่เดียว เปลี่ยนทั้งเว็บ
   ========================================================================== */

:root {
  /* Palette (light) */
  --bg:            #f6f7fb;
  --bg-soft:       #eef0f7;
  --surface:       #ffffff;
  --surface-2:     #f8f9fd;
  --border:        #e4e7f0;
  --text:          #1a1d29;
  --text-soft:     #565b6e;
  --text-faint:    #8b90a3;

  /* Brand */
  --brand:         #6c4bf4;
  --brand-2:       #22b8cf;

  /* Accent — override per subject via body[style] or .subject class */
  --accent:        var(--brand);
  --accent-soft:   color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-ink:    color-mix(in srgb, var(--accent) 78%, #000 22%);

  --radius:        18px;
  --radius-sm:     12px;
  --shadow:        0 1px 2px rgba(20,22,40,.04), 0 8px 24px rgba(20,22,40,.06);
  --shadow-lg:     0 12px 40px rgba(20,22,40,.14);
  --maxw:          1080px;

  --font: "Noto Sans Thai", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e0f17;
    --bg-soft:   #14151f;
    --surface:   #191b26;
    --surface-2: #1f2130;
    --border:    #2a2d3d;
    --text:      #f2f3f8;
    --text-soft: #b6b9c9;
    --text-faint:#797e93;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
    --accent-ink: color-mix(in srgb, var(--accent) 70%, #fff 30%);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

.wrap { max-width: var(--maxw); margin-inline: auto; padding-inline: 20px; }

/* ---------- Top bar ---------- */
.ocs-nav {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(1.4) blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
.ocs-nav .wrap { display: flex; align-items: center; gap: 14px; height: 62px; }
.ocs-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; color: var(--text); }
.ocs-brand .logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 18px;
}
.ocs-nav .spacer { flex: 1; }
.ocs-nav a.navlink { color: var(--text-soft); font-weight: 600; font-size: 15px; }
.ocs-nav a.navlink:hover { color: var(--text); text-decoration: none; }

/* ---------- Hero ---------- */
.hero { padding: 68px 0 40px; text-align: center; }
.hero h1 { font-size: clamp(30px, 5vw, 52px); line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; }
.hero h1 .grad { background: linear-gradient(120deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: clamp(16px, 2.4vw, 20px); color: var(--text-soft); max-width: 640px; margin: 0 auto 28px; }
.badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 13px; margin-bottom: 22px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 22px; border-radius: 999px;
  font-weight: 700; font-size: 15px; border: 1px solid transparent; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ---------- Subject grid (hub) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card {
  position: relative; display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease; color: var(--text);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); text-decoration: none; border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card .emoji { font-size: 30px; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--accent-soft); margin-bottom: 14px; }
.card h3 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.card p { margin: 0; color: var(--text-soft); font-size: 14.5px; }
.card .count { position: absolute; top: 18px; right: 18px; font-size: 12px; font-weight: 700; color: var(--accent-ink);
  background: var(--accent-soft); padding: 3px 10px; border-radius: 999px; }

/* ---------- Section headings ---------- */
.section { padding: 34px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.section-head h2 { font-size: clamp(22px, 3.2vw, 30px); margin: 0; letter-spacing: -.02em; }
.section-head p { margin: 0; color: var(--text-soft); }

/* ---------- Lesson list (subject page) ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.chip { padding: 7px 15px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-soft); font-weight: 600; font-size: 14px; cursor: pointer; transition: .12s; }
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.lessons { display: grid; gap: 16px; }
.lesson {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: clip; box-shadow: var(--shadow);
}
.lesson > summary {
  list-style: none; cursor: pointer; padding: 20px 22px; display: flex; align-items: center; gap: 14px;
}
.lesson > summary::-webkit-details-marker { display: none; }
.lesson .lv { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 4px 9px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap; }
.lesson .l-title { font-weight: 700; font-size: 17.5px; flex: 1; letter-spacing: -.01em; }
.lesson .l-sum { color: var(--text-soft); font-size: 14px; width: 100%; margin-top: 2px; }
.lesson summary .caret { color: var(--text-faint); transition: transform .18s; }
.lesson[open] summary .caret { transform: rotate(90deg); }
.lesson .body { padding: 4px 22px 24px; border-top: 1px solid var(--border); }
.lesson .body > *:first-child { margin-top: 16px; }
.lesson .body h4 { font-size: 16px; margin: 18px 0 6px; }
.lesson .body code { background: var(--bg-soft); padding: 2px 7px; border-radius: 6px; font-size: .92em; }
.lesson .body .eg { background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 14px 16px; margin: 14px 0; }
.lesson .body .takeaway { display: flex; gap: 12px; background: var(--accent-soft); border-radius: var(--radius-sm); padding: 14px 16px; margin: 16px 0 0; font-weight: 600; }
.lesson .body .takeaway .k { font-size: 20px; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.tag { font-size: 12px; color: var(--text-faint); background: var(--bg-soft); padding: 3px 9px; border-radius: 999px; }

/* ---------- Footer ---------- */
.ocs-foot { border-top: 1px solid var(--border); margin-top: 40px; padding: 30px 0; color: var(--text-faint); font-size: 14px; text-align: center; }

/* ---------- AI widget ---------- */
.ai-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 60; border: none; cursor: pointer;
  height: 58px; padding: 0 22px 0 18px; border-radius: 999px; display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700; font-size: 15px;
  font-family: var(--font); box-shadow: var(--shadow-lg); transition: transform .12s; }
.ai-fab:hover { transform: translateY(-2px); }
.ai-fab .dot { width: 8px; height: 8px; border-radius: 50%; background: #7CFFB2; box-shadow: 0 0 0 0 #7CFFB2; animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(124,255,178,.6)} 70%{box-shadow:0 0 0 8px rgba(124,255,178,0)} 100%{box-shadow:0 0 0 0 rgba(124,255,178,0)} }

.ai-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 61; width: min(420px, calc(100vw - 32px)); height: min(620px, calc(100vh - 40px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg);
  display: none; flex-direction: column; overflow: clip; }
.ai-panel.open { display: flex; }
.ai-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.ai-head .t { font-weight: 800; flex: 1; }
.ai-head .t small { display: block; font-weight: 500; opacity: .85; font-size: 12px; }
.ai-head button { background: rgba(255,255,255,.2); border: none; color: #fff; width: 32px; height: 32px; border-radius: 10px; cursor: pointer; font-size: 18px; }
.ai-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.ai-msg { max-width: 88%; padding: 11px 15px; border-radius: 16px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.ai-msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.ai-msg.bot .src { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-soft); }
.ai-msg.bot .src a { display: inline-block; margin: 2px 6px 2px 0; }
.ai-suggest { display: flex; flex-wrap: wrap; gap: 7px; }
.ai-suggest button { font-size: 13px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-soft); cursor: pointer; font-family: var(--font); }
.ai-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.ai-foot input { flex: 1; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  border-radius: 999px; padding: 12px 16px; font-size: 15px; font-family: var(--font); outline: none; }
.ai-foot input:focus { border-color: var(--accent); }
.ai-foot button { border: none; background: var(--accent); color: #fff; width: 46px; border-radius: 50%; cursor: pointer; font-size: 18px; }
.ai-typing { align-self: flex-start; color: var(--text-faint); font-size: 14px; }

/* ---------- Utility ---------- */
.center { text-align: center; }
.muted { color: var(--text-soft); }
.hidden { display: none !important; }
@media (max-width: 560px) { .hero { padding: 44px 0 26px; } }
