/* GameOnLearn Hub — สไตล์กลาง (โทเคนสีตามมาตรฐาน dataviz: validated palette) */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;          /* series-1 (blue) */
  --accent-strong: #1c5cab;
  --meter-track: #cde2fb;     /* ขั้นอ่อนของ ramp เดียวกัน */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-strong: #6da7ec;
    --meter-track: #184f95;
    --good-text: #0ca30c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Sarabun", "Noto Sans Thai", sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 18px 56px; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; margin-bottom: 18px;
  border-bottom: 1px solid var(--grid);
}
.brand { font-weight: 700; font-size: 19px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.topbar .sp { flex: 1; }
.topbar .who { color: var(--ink-2); font-size: 14px; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  padding: 8px 14px; font-size: 14.5px; font-family: inherit;
}
.btn:hover { border-color: var(--baseline); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent-strong); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* ---------- การ์ด/กริด ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.section-title { font-size: 16.5px; font-weight: 700; margin: 26px 0 12px; }
.section-title .sub { color: var(--muted); font-weight: 400; font-size: 13.5px; margin-left: 8px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .unit { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 3px; }

/* ---------- meter (ความคืบหน้า) ---------- */
.meter { height: 8px; border-radius: 5px; background: var(--meter-track); overflow: hidden; min-width: 70px; }
.meter > i { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.meter-row { display: flex; align-items: center; gap: 8px; }
.meter-row .pct { color: var(--ink-2); font-size: 12.5px; min-width: 34px; text-align: right;
  font-variant-numeric: tabular-nums; }

/* ---------- ตาราง ---------- */
table.gol { width: 100%; border-collapse: collapse; font-size: 14px; }
table.gol th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
table.gol td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.gol tr:last-child td { border-bottom: 0; }
table.gol td.num { font-variant-numeric: tabular-nums; text-align: right; }
.table-scroll { overflow-x: auto; }

/* ---------- badge/สถานะ ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  font-size: 12px; padding: 2.5px 10px; border: 1px solid var(--border); color: var(--ink-2); }
.badge.published { color: var(--good-text); border-color: currentColor; }
.badge.maintenance { color: var(--critical); border-color: currentColor; }
.badge.testing { color: var(--ink-2); }
.joinkey { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700;
  letter-spacing: 2px; font-size: 17px; color: var(--accent-strong); }

/* ---------- สวิตช์มอบหมายเกม ---------- */
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--baseline); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked + i { background: var(--good); }
.switch input:checked + i::after { left: 19px; }
.assign-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--grid); }
.assign-row:first-of-type { border-top: 0; }

/* ---------- catalog ---------- */
.game-card { display: flex; flex-direction: column; gap: 12px; }
.game-cover { height: 120px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 42px; background: linear-gradient(135deg, #cde2fb, #86b6ef); }
.game-card h3 { margin: 0; font-size: 17px; }
.game-meta { color: var(--ink-2); font-size: 13.5px; }
.game-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

/* ---------- ฟอร์ม ---------- */
input[type=text], input[type=password], select, textarea {
  font-family: inherit; font-size: 14.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--baseline); border-radius: 9px;
  padding: 8px 11px; width: 100%;
}
textarea { min-height: 92px; resize: vertical; }
label.f { display: block; font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
.form-hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

/* ---------- อื่น ๆ ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err-box { background: var(--surface); border: 1px solid var(--critical); color: var(--critical);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; display: none; }
.err-box.on { display: block; }
.loading { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--accent);
  border-top-color: transparent; border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.crumb { font-size: 13.5px; color: var(--muted); margin-bottom: 10px; }
.hidden { display: none !important; }
.warn-note { border-left: 3px solid var(--warning); padding: 8px 12px; background: var(--surface);
  border-radius: 0 9px 9px 0; color: var(--ink-2); font-size: 13.5px; }

/* ---------- hero (หน้าแรก) ---------- */
.hero { margin-bottom: 22px; }
.hero h1 { margin: 2px 0 8px; font-size: 22px; }
.hero-slogan { color: var(--accent-strong); font-weight: 700; letter-spacing: .3px; font-size: 14px; }

/* ---------- tag (สมรรถนะ/กลุ่มสาระที่เกมวัด) ---------- */
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 11.5px; color: var(--ink-2); background: var(--page);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }

/* ---------- tabs (ผลสัมฤทธิ์ / สมรรถนะ) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--grid); margin: 20px 0 14px; }
.tab { cursor: pointer; border: 0; background: transparent; font-family: inherit; font-size: 15px;
  color: var(--ink-2); padding: 9px 15px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- แถบสมรรถนะ (bar chart แนวนอน ซีรีส์เดียว จึงไม่ต้องมี legend) ---------- */
.cbar { display: grid; grid-template-columns: minmax(150px, 1.1fr) 1fr auto; gap: 12px;
  align-items: center; padding: 9px 0; border-top: 1px solid var(--grid); }
.cbar:first-of-type { border-top: 0; }
.cbar .cname { font-size: 14px; }
.cbar .csub { color: var(--muted); font-size: 12px; }
.cbar .ctrack { height: 12px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.cbar .ctrack > i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.cbar .cval { font-size: 14px; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; }
.cbar.nodata .ctrack { background: var(--grid); }
.cbar.nodata .cval { color: var(--muted); font-size: 12.5px; }
.lvl { display: inline-block; font-size: 11.5px; color: var(--ink-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.panel-note { color: var(--muted); font-size: 12.5px; margin-top: 10px; line-height: 1.5; }
.std-slot { margin-top: 10px; }
