:root {
  --brand: #0b4f9c;
  --brand-2: #1677d2;
  --bg: #f2f5fa;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --text: #1a2433;
  --muted: #5d6b80;
  --line: #dde4ee;
  --today: #fff4d6;
  --shadow: 0 1px 2px rgba(16, 40, 80, .06), 0 4px 14px rgba(16, 40, 80, .07);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1520;
    --surface: #172131;
    --surface-2: #1e2a3d;
    --text: #e8eef7;
    --muted: #9aa8bd;
    --line: #2a374b;
    --today: #3a3217;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1520; --surface: #172131; --surface-2: #1e2a3d; --text: #e8eef7;
  --muted: #9aa8bd; --line: #2a374b; --today: #3a3217; --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .top-name, .tile b, .school-name, .tabbar a, .role-switch button, .btn, .big-choice {
  font-family: "Prompt", "Sarabun", system-ui, sans-serif;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}
.top-logo { border-radius: 50%; background: #fff; padding: 2px; flex: none; }
.top-text { flex: 1; min-width: 0; }
.top-name { font-weight: 600; font-size: 18px; line-height: 1.25; }
.top-sub { font-size: 14px; opacity: .88; }
.install-btn {
  flex: none; border: 0; border-radius: 999px; padding: 8px 14px;
  background: #fff; color: var(--brand); font-weight: 600; font-size: 14px;
  font-family: "Prompt", sans-serif; cursor: pointer;
}
.offline {
  background: #7a5a00; color: #fff; text-align: center; font-size: 14px; padding: 6px 16px;
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 22px; margin: 4px 0 14px; }
.sub-title { font-size: 18px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Role switch */
.role-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--surface-2); border-radius: 999px; padding: 4px; margin-bottom: 14px;
}
.role-switch button {
  border: 0; background: transparent; border-radius: 999px; padding: 9px 4px;
  font-size: 14.5px; white-space: nowrap; font-weight: 500; color: var(--muted); cursor: pointer;
}
.role-switch button[aria-selected="true"] {
  background: var(--surface); color: var(--brand); box-shadow: var(--shadow);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .role-switch button[aria-selected="true"] { color: #8cc2ff; } }
:root[data-theme="dark"] .role-switch button[aria-selected="true"] { color: #8cc2ff; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border-radius: var(--radius); padding: 16px 14px;
  text-decoration: none; box-shadow: var(--shadow); min-height: 140px;
  border-top: 4px solid var(--c, var(--brand-2));
  transition: transform .12s ease;
}
.tile:active { transform: scale(.97); }
.tile .ti {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  font-size: 26px; background: color-mix(in srgb, var(--c, #1677d2) 16%, transparent);
}
.tile > div { display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 16px; font-weight: 600; line-height: 1.3; }
.tile small { color: var(--muted); font-size: 13.5px; line-height: 1.35; }
.tiles.single { grid-template-columns: 1fr; }
.tiles.single .tile { flex-direction: row; align-items: center; min-height: 0; }
.tiles.single .tile > div { display: flex; flex-direction: column; }
.hint { text-align: center; color: var(--muted); font-size: 13.5px; margin: 12px 0 0; }

/* Blocks */
.block { margin-top: 26px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.block-head h2 { font-size: 18px; margin: 0; }
.block-head a { color: var(--brand-2); font-size: 15px; text-decoration: none; }

/* Events */
.month { font-family: "Prompt", sans-serif; font-weight: 600; color: var(--muted); font-size: 15px; margin: 18px 0 8px; }
.month:first-child { margin-top: 0; }
.event {
  display: flex; gap: 12px; background: var(--surface); border-radius: 14px; padding: 12px;
  box-shadow: var(--shadow); margin-bottom: 10px; border-left: 5px solid var(--c, var(--brand-2));
}
.event.is-today { background: var(--today); }
.ev-date {
  flex: none; width: 54px; text-align: center; border-radius: 10px; background: var(--surface-2);
  padding: 6px 0; line-height: 1.1;
}
.ev-date b { display: block; font-size: 22px; font-family: "Prompt", sans-serif; }
.ev-date small { font-size: 12.5px; color: var(--muted); }
.ev-body { min-width: 0; }
.ev-title { font-weight: 600; line-height: 1.35; }
.ev-meta { color: var(--muted); font-size: 14px; }
.badge { display: inline-block; font-size: 12px; background: #e0a800; color: #000; border-radius: 6px; padding: 0 6px; margin-left: 4px; vertical-align: 2px; }

/* News */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: 15px; cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.post {
  display: flex; gap: 12px; align-items: center; background: var(--surface); border-radius: 14px;
  padding: 10px; box-shadow: var(--shadow); margin-bottom: 10px; text-decoration: none;
}
.post img, .post .noimg {
  flex: none; width: 76px; height: 76px; border-radius: 10px; object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-size: 28px;
}
.post-title { font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.post-meta { color: var(--muted); font-size: 13.5px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; background: var(--surface); border-radius: 14px; }

/* Contact */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.school-card { display: flex; gap: 14px; align-items: center; }
.school-card img { border-radius: 50%; background: #fff; flex: none; }
.school-name { font-weight: 600; font-size: 17px; line-height: 1.3; }
.motto { font-size: 14px; margin-top: 4px; color: var(--brand-2); }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 12px; overflow: hidden; }
.row {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 13px 16px; text-decoration: none;
  border: 0; background: none; text-align: left; cursor: pointer; border-top: 1px solid var(--line);
}
.list > .row:first-child { border-top: 0; }
.row .ri { font-size: 22px; width: 30px; text-align: center; flex: none; }
.row span:last-child { display: flex; flex-direction: column; min-width: 0; }
.row small { color: var(--muted); font-size: 14px; }
.share-card { display: flex; gap: 16px; align-items: center; }
.qr { flex: none; width: 132px; height: 132px; background: #fff; border-radius: 10px; padding: 6px; display: grid; place-items: center; }
.qr img, .qr svg { width: 100%; height: 100%; image-rendering: pixelated; }
.share-side p { margin: 0 0 6px; font-size: 15px; }
.url { font-size: 13px; color: var(--muted); word-break: break-all; margin-bottom: 8px; }
.btn {
  border: 0; border-radius: 12px; background: var(--brand-2); color: #fff; padding: 10px 16px;
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.btn.wide { width: 100%; margin-top: 8px; }
.version { text-align: center; color: var(--muted); font-size: 13px; margin-top: 24px; }
@media (max-width: 380px) { .share-card { flex-direction: column; text-align: center; } }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  height: var(--tabbar-h); text-decoration: none; font-size: 13px; color: var(--muted);
}
.tabbar a span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar a[aria-current="page"] { color: var(--brand-2); font-weight: 600; }
.tabbar a[aria-current="page"] span { filter: none; opacity: 1; }

/* Dialogs */
dialog.sheet {
  border: 0; border-radius: 22px; padding: 22px 20px; width: min(420px, calc(100% - 32px));
  background: var(--surface); color: var(--text); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  max-height: calc(100% - 40px); overflow: auto;
}
dialog.sheet::backdrop { background: rgba(8, 20, 40, .55); }
dialog.sheet h2 { margin: 8px 0 4px; font-size: 21px; }
dialog.sheet img { border-radius: 50%; background: #fff; }
.big-choice {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 10px; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--surface-2);
  font-size: 18px; font-weight: 600; cursor: pointer; text-align: left;
}
.big-choice span { font-size: 28px; }
.big-choice:active { border-color: var(--brand-2); }
.steps { text-align: left; background: var(--surface-2); border-radius: 14px; padding: 4px 14px 2px; margin-top: 12px; }
.steps h3 { font-size: 16px; margin: 10px 0 0; }
.steps ol { padding-left: 22px; margin: 6px 0 10px; }
.steps li { margin: 4px 0; }
.ico { font-size: 15px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1a2433; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px;
  transition: .2s ease; max-width: calc(100% - 32px); text-align: center; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.skeleton { height: 76px; border-radius: 14px; margin-bottom: 10px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .tile, .toast { transition: none; } }
