/* ทายคำเด้อ — ระบบดีไซน์กลางของทุกหน้า */

:root {
  --ground: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #e4e6eb;
  --line-strong: #d2d5dc;
  --ink: #191c24;
  --ink-2: #4b5160;
  --ink-3: #6b7282;
  --accent: #2f6bff;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --accent-strong: #1f52d6;
  --mole: #b86e00;
  --mole-soft: #fff3df;
  --gm: #0d8a73;
  --gm-soft: #e1f5f0;
  --danger: #d93a40;
  --danger-soft: #fdecec;
  --ok: #138a4b;
  --ok-soft: #e3f5ea;
  --shadow: 0 1px 2px rgba(25, 28, 36, 0.06), 0 4px 14px rgba(25, 28, 36, 0.06);
  --shadow-lift: 0 2px 6px rgba(25, 28, 36, 0.08), 0 14px 34px rgba(25, 28, 36, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Kanit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #101218;
    --surface: #191c24;
    --surface-2: #20242e;
    --line: #2a2f3b;
    --line-strong: #394050;
    --ink: #eef0f4;
    --ink-2: #b9bfcc;
    --ink-3: #8c93a3;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --accent-soft: #1d2a4d;
    --accent-strong: #7da3ff;
    --mole: #ffb547;
    --mole-soft: #3a2a10;
    --gm: #3fd0b2;
    --gm-soft: #0f3029;
    --danger: #ff6b70;
    --danger-soft: #3a1618;
    --ok: #4cd18a;
    --ok-soft: #12301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lift: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--accent);
}

::selection { background: var(--accent-soft); color: var(--ink); }

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.3; font-weight: 600; text-wrap: balance; }
a { color: var(--accent); text-underline-offset: 3px; }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }
.hidden, [hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* ---------- โครงหน้า ---------- */

.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}
.wrap-wide { max-width: 1080px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 18px; color: var(--ink); text-decoration: none;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--ink); color: var(--ground);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; letter-spacing: -0.02em;
}
.spacer { flex: 1; }


/* ---------- ปุ่ม ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border-radius: 12px; border: 1px solid transparent;
  font-weight: 500; font-size: 16px; line-height: 1;
  cursor: pointer; user-select: none; text-decoration: none;
  transition: background-color 150ms var(--ease-out), transform 150ms var(--ease-out), border-color 150ms;
}
.btn:active { transform: scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not([disabled]) { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not([disabled]) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not([disabled]) { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--line-strong); }
.btn-danger:hover:not([disabled]) { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 18px; border-radius: 14px; }
.btn-sm { white-space: nowrap; min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; border-radius: 12px; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--accent-ink) var(--accent-ink) transparent transparent;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ฟอร์ม ---------- */

.field { display: grid; gap: 6px; }
.label { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.input, .select {
  width: 100%; min-height: 50px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); font-size: 17px;
  transition: border-color 150ms, box-shadow 150ms;
}
.input::placeholder { color: var(--ink-3); }
.input:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input-code {
  font-size: 22px; font-weight: 500; letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}
.field-error { font-size: 14px; color: var(--danger); min-height: 1.4em; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .input { flex: 1; min-width: 0; }

/* ตัวเลือกแบบแบ่งช่อง (เลือกเวลา) */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; gap: 4px;
}
.segmented button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  color: var(--ink-2); font-weight: 500; cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms, color 150ms;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented button:disabled { cursor: default; }

/* ---------- พื้นผิว ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 12px; }
.card-title { font-size: 17px; font-weight: 600; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; line-height: 1;
  padding: 5px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge-gm { background: var(--gm-soft); color: var(--gm); }
.badge-mole { background: var(--mole-soft); color: var(--mole); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot-off { background: var(--line-strong); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-weight: 600; font-size: 16px; color: #fff;
}

/* ---------- แจ้งเตือนลอย ---------- */

.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60; display: grid; justify-items: center; gap: 8px; pointer-events: none;
  padding: 0 16px;
}
.toast {
  max-width: 420px; padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--ground);
  font-size: 15px; box-shadow: var(--shadow-lift);
  animation: toast-in 220ms var(--ease-out);
}
.toast-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- dialog ---------- */

dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0;
  width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lift);
  max-height: 88dvh;
}
dialog.sheet[open] { animation: sheet-in 260ms var(--ease-out); }
dialog.sheet::backdrop { background: rgba(10, 12, 18, 0.45); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}
.sheet-body { padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { font-size: 19px; flex: 1; }
.sheet-actions { display: grid; gap: 8px; margin-top: 20px; }

/* ---------- ส่วนท้าย ---------- */

.site-foot {
  padding: 32px 0 calc(32px + env(safe-area-inset-bottom));
  color: var(--ink-3); font-size: 14px;
}
.site-foot a { color: var(--ink-2); }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px 16px; }

/* โฆษณา: เว้นที่ไว้ให้ไม่ดันหน้าเลื่อน */
.ad-slot { margin: 20px 0; min-height: 100px; text-align: center; }
.ad-slot:empty { display: none; }
.ad-label { font-size: 11px; color: var(--ink-3); margin-bottom: 4px; text-align: center; }

/* โปรโมตสตูดิโอ */
.promo {
  display: flex; gap: 14px; align-items: center;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-decoration: none; color: var(--ink);
}
.promo-mark {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  background: #1c1b3a; color: #fff; display: grid; place-items: center;
  font-weight: 600; font-size: 15px; letter-spacing: 0.02em;
}
.promo-title { font-weight: 600; }
.promo-text { font-size: 14px; color: var(--ink-3); }
.promo .icon { color: var(--ink-3); margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
