:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #0f1d33;
  --muted: #64718a;
  --line: #e3e8f0;
  --navy: #12294a;
  --navy-deep: #0b1f3a;
  --crimson: #9b1c2e;
  --gold: #f0b94a;
  --ok: #1e7f45;
  --ok-bg: #e4f4ea;
  --warn: #a15c07;
  --warn-bg: #fdf0d8;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(15, 29, 51, .05), 0 8px 24px rgba(15, 29, 51, .06);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans Thai Looped', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.stack > * + * { margin-top: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in { max-width: 560px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 12px; flex: none; }
.brand { min-width: 0; flex: 1; }
.brand b { display: block; font-size: 16px; font-weight: 700; line-height: 1.25; }
.brand span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.btn-ghost {
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 8px 14px; font-weight: 600; font-size: 14px; min-height: 40px;
}
.btn-ghost:active { background: var(--bg); }

section { scroll-margin-top: 76px; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.sec-title { font-size: 19px; font-weight: 700; line-height: 1.3; }
.sec-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; align-content: center; padding: 24px 16px; max-width: 440px; margin: 0 auto; }
.login-hero { text-align: center; margin-bottom: 24px; }
.login-hero .logo { width: 72px; height: 72px; border-radius: 22px; margin-bottom: 14px; box-shadow: var(--shadow); }
.login-hero h1 { font-size: 24px; font-weight: 700; }
.login-hero p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.field { display: block; margin-top: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 14px; background: #fff;
  padding: 13px 14px; font-size: 17px; outline: none; min-height: 50px;
}
.field input:focus { border-color: var(--navy); box-shadow: 0 0 0 4px rgba(18, 41, 74, .1); }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 6px; }
.btn-primary {
  width: 100%; margin-top: 22px; border: 0; border-radius: 14px; min-height: 52px;
  background: linear-gradient(135deg, var(--navy-deep), var(--navy) 55%, var(--crimson));
  color: #fff; font-weight: 700; font-size: 16px;
}
.btn-primary:disabled { opacity: .6; }
.btn-primary:active { transform: translateY(1px); }
.err { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 16px; }
.demo-note { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-top: 16px; }

/* ---------- Greeting ---------- */
.hello { padding-top: 20px; }
.hello h1 { font-size: 26px; font-weight: 700; line-height: 1.25; }
.hello .sid { color: var(--muted); font-size: 14px; margin-top: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 8px 6px 14px; font-size: 12.5px; color: var(--muted);
}
.pill button { border: 0; background: var(--bg); border-radius: 999px; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; }
.pill button svg { width: 16px; height: 16px; }
.pill button.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.offline { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-top: 12px; }

/* ---------- Attendance ---------- */
.ring-wrap { display: grid; place-items: center; padding: 6px 0 4px; }
.ring { position: relative; width: 180px; height: 180px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: #e8ecf2; }
.ring .bar { transition: stroke-dashoffset .9s cubic-bezier(.2, .8, .2, 1); }
.ring-c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-c b { font-size: 40px; font-weight: 700; line-height: 1.1; }
.ring-c span { font-size: 11.5px; color: var(--muted); max-width: 110px; margin: 2px auto 0; line-height: 1.35; }
.status {
  display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 12px; margin-top: 18px;
}
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.warn { background: var(--warn-bg); color: var(--warn); }
.status.fail { background: var(--bad-bg); color: var(--bad); }
.status-t { font-size: 22px; font-weight: 700; margin-top: 6px; line-height: 1.3; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: #f5f7fa; border-radius: 16px; padding: 14px 16px; min-width: 0; }
.tile.white { background: var(--card); box-shadow: var(--shadow); padding: 18px; border-radius: var(--radius); }
.tile small { display: block; font-size: 12px; color: var(--muted); }
.tile b { display: block; font-size: 24px; font-weight: 700; line-height: 1.3; margin-top: 2px; }
.tile em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.full { grid-column: 1 / -1; }
.mt { margin-top: 14px; }

.dark {
  color: #fff; border-radius: var(--radius); padding: 22px 22px 24px; position: relative; overflow: hidden;
  background: linear-gradient(150deg, #0e2b4d 0%, #123a63 100%);
  box-shadow: var(--shadow);
}
.dark.warn { background: linear-gradient(150deg, #3a2a0a, #7a4b08); }
.dark.fail { background: linear-gradient(150deg, #4a0f14, #9b1c2e); }
.dark small { font-size: 13px; color: rgba(255, 255, 255, .62); }
.dark .big { font-size: 48px; font-weight: 700; color: var(--gold); line-height: 1.15; margin: 4px 0 0; }
.dark .big span { font-size: 40px; }
.dark .eq { font-size: 19px; font-weight: 700; margin-top: 2px; }
.dark p { font-size: 13.5px; color: rgba(255, 255, 255, .78); margin-top: 10px; line-height: 1.55; }

/* ---------- Score ---------- */
.score-card {
  color: #fff; border-radius: 18px; padding: 18px 20px 20px; margin-top: 16px;
  background: linear-gradient(120deg, #0b1f3a 0%, #12294a 55%, #7d1a28 100%);
}
.score-card small { color: rgba(255, 255, 255, .65); font-size: 12.5px; }
.score-card .big { font-size: 52px; font-weight: 700; line-height: 1.1; margin-top: 2px; }
.score-card .big span { font-size: 20px; font-weight: 500; color: rgba(255, 255, 255, .6); margin-left: 6px; }
.meter { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .18); margin-top: 12px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--gold); transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.ch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.ch {
  border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.ch .tag { align-self: flex-start; font-size: 10.5px; font-weight: 700; color: var(--crimson); background: #fbe9ec; border-radius: 8px; padding: 2px 8px; letter-spacing: .03em; }
.ch h3 { font-size: 12.5px; font-weight: 600; line-height: 1.45; flex: 1; overflow-wrap: anywhere; }
.ch .sc { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.ch .sc b { font-size: 18px; color: var(--ink); font-weight: 700; }
.ch.done .sc b { color: var(--ok); }

/* ---------- Calendar ---------- */
.cal-nav { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; margin: 14px 0; }
.cal-nav button { border: 1px solid var(--line); background: #fff; border-radius: 14px; min-height: 48px; font-size: 18px; font-weight: 700; }
.cal-nav .month {
  border: 0; color: #fff; font-size: 15px; font-weight: 700;
  background: linear-gradient(120deg, var(--navy-deep), var(--navy) 45%, var(--crimson));
}
.cal { border: 1px solid var(--line); border-radius: 18px; padding: 10px; background: #fafbfd; }
.cal-head, .cal-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head { background: var(--navy-deep); color: #fff; border-radius: 12px; font-size: 12px; font-weight: 700; text-align: center; padding: 10px 0; margin-bottom: 6px; }
.cal-days { gap: 4px; }
.day {
  position: relative; aspect-ratio: 1 / 1.05; border: 1px solid transparent; border-radius: 12px; background: #fff;
  display: grid; place-content: center; font-weight: 600; font-size: 14px; padding: 0;
}
.day.out { color: #b9c2d1; background: transparent; pointer-events: none; }
.day.has { background: #fbeef0; color: var(--crimson); }
.day.today { outline: 2px solid var(--gold); outline-offset: -2px; }
.day.sel { background: linear-gradient(135deg, var(--navy-deep), var(--crimson)); color: #fff; }
.day .dot { position: absolute; bottom: 7px; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--navy); }
.day .dot.present { background: var(--ok); }
.day .dot.absent { background: var(--bad); }
.day.sel .dot { box-shadow: 0 0 0 2px rgba(255, 255, 255, .8); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

.acts > * + * { margin-top: 12px; }
.act { border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.act .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip { display: inline-block; font-size: 11.5px; font-weight: 700; border-radius: 99px; padding: 2px 10px; background: #fbe9ec; color: var(--crimson); }
.chip.present { background: var(--ok-bg); color: var(--ok); }
.chip.partial { background: var(--warn-bg); color: var(--warn); }
.chip.absent { background: var(--bad-bg); color: var(--bad); }
.chip.pending, .chip.none { background: #eef1f6; color: var(--muted); }
.act h3 { font-size: 17px; font-weight: 700; margin-top: 10px; line-height: 1.4; overflow-wrap: anywhere; }
.act dl { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.act dt { color: var(--muted); }
.act dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px 8px; }

/* ---------- Resources ---------- */
.hero-link {
  display: block; text-decoration: none; color: #fff; border-radius: var(--radius); padding: 22px;
  background: linear-gradient(150deg, #0e2b4d, #174a78); box-shadow: var(--shadow);
}
.hero-link .tag { display: inline-block; background: var(--gold); color: #3a2a00; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 3px 12px; }
.hero-link h3 { font-size: 24px; font-weight: 700; margin-top: 12px; line-height: 1.3; }
.hero-link p { color: rgba(255, 255, 255, .75); font-size: 14px; margin-top: 6px; }
.hero-link .cta { display: block; margin-top: 18px; background: #fff; color: var(--navy-deep); border-radius: 14px; text-align: center; font-weight: 700; padding: 14px; }
.hero-link.album { background: var(--card); color: var(--ink); }
.hero-link.album p { color: var(--muted); }
.hero-link.album .cta { background: var(--navy-deep); color: #fff; }
.doc { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.doc + .doc { margin-top: 10px; }
.doc .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; flex: none; }
.doc .ic svg { width: 22px; height: 22px; }
.doc b { display: block; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.doc span { font-size: 12.5px; color: var(--muted); display: block; overflow-wrap: anywhere; }
.count { font-size: 12px; background: var(--bg); border-radius: 99px; padding: 2px 10px; margin-left: 8px; vertical-align: 2px; font-weight: 600; }

/* ---------- History ---------- */
.hist { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.hist th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.hist td { padding: 12px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.hist tr:last-child td { border-bottom: 0; }
.hist td small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.hist .v { white-space: nowrap; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0; }

@media (min-width: 560px) { .wrap { padding-top: 8px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.linkbtn { border: 0; background: none; padding: 0; color: var(--navy); font-weight: 600; text-decoration: underline; font-size: 12px; cursor: pointer; }
