:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1c1b29;
  --muted: #6b6a7d;
  --line: #e4e2ef;
  --accent: #5b4bdb;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfd;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn-soft: #fff6e0;
  --warn: #a16207;
  --danger: #c2353f;
  --danger-soft: #fdecee;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 18 50 / 6%), 0 4px 16px rgb(20 18 50 / 5%);
  --tabs-h: 64px;
  color-scheme: light;
}
/* Dark theme: by system setting unless the user picked Light; or when the user picked Dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121119;
    --surface: #1d1c27;
    --text: #ecebf5;
    --muted: #a19fb5;
    --line: #2f2d3d;
    --accent: #8b7ff0;
    --accent-ink: #12111a;
    --accent-soft: #2a2747;
    --ok: #4ade80;
    --ok-soft: #173123;
    --warn-soft: #3a2f12;
    --warn: #facc15;
    --danger: #f87171;
    --danger-soft: #3b1d21;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #121119;
    --surface: #1d1c27;
    --text: #ecebf5;
    --muted: #a19fb5;
    --line: #2f2d3d;
    --accent: #8b7ff0;
    --accent-ink: #12111a;
    --accent-soft: #2a2747;
    --ok: #4ade80;
    --ok-soft: #173123;
    --warn-soft: #3a2f12;
    --warn: #facc15;
    --danger: #f87171;
    --danger-soft: #3b1d21;
    --shadow: none;
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; }
h3 { font-size: .95rem; margin: 14px 0 6px; }
p { margin: 8px 0; }
button { font: inherit; }

/* ---------- shell ---------- */
header.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
header.top h1 { font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main {
  max-width: 760px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
nav.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 500;
}
nav.tabs a .tab-icon { font-size: 1.25rem; line-height: 1; }
nav.tabs a.active { color: var(--accent); }

/* ---------- building blocks ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 14px 16px; margin: 12px 0;
}
.card.ok { background: var(--ok-soft); border-color: transparent; }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.card.error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.card.highlight { background: var(--accent-soft); border-color: transparent; }
.card.install strong { display: block; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.gap { gap: 10px; }
.row.gap > .field { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lead { font-size: 1.1rem; font-weight: 600; }
.break { word-break: break-all; }
.ok-text { color: var(--ok); font-weight: 600; }
.greet { font-size: 1.05rem; color: var(--muted); margin: 0 0 4px; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }
.kbd { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.btn.paid { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.row.gap > .btn { flex: 1; }
.link { background: none; border: 0; padding: 4px; color: var(--accent); font-weight: 600; cursor: pointer; }
.link.danger { color: var(--danger); font-weight: 500; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; color: var(--text); font-size: 1.5rem; border-radius: 50%; cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); }
.chip { font-size: .8rem; font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; margin-left: 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.field { display: block; margin: 12px 0; }
.field .label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.field .hint { display: block; font-size: .78rem; color: var(--muted); margin-top: 4px; }
input, select {
  width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type="color"] { padding: 4px; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); flex: none; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="search"] { margin: 8px 0; }
.switch { display: flex; gap: 10px; align-items: center; margin: 12px 0; cursor: pointer; }

.list { list-style: none; padding: 0; margin: 8px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text); cursor: default; }
li.list-item[role="button"], a.list-item { cursor: pointer; }
.list-item.cancelled b { text-decoration: line-through; }
.list-item .muted { font-size: .85rem; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.avatar.big { width: 52px; height: 52px; font-size: 1.05rem; }
.names { list-style: none; padding: 0; margin: 6px 0 0; }
.names li { padding: 4px 0; }

.stat-card { display: flex; gap: 8px; color: var(--text); }
.stat { flex: 1; display: flex; flex-direction: column; }
.stat-num { font-size: clamp(1.15rem, 5.5vw, 1.6rem); font-weight: 700; letter-spacing: -.01em; }
.stat-label { font-size: .8rem; color: var(--muted); }

.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.week-nav .link { color: var(--text); font-size: 1rem; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin: 4px 0 10px; }
.seg a { flex: 1; text-align: center; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.seg a.on { background: var(--accent); color: var(--accent-ink); }

.class-card { border-left: 4px solid var(--c); }
.class-card.cancelled b { text-decoration: line-through; color: var(--muted); }

/* ---------- week grid ---------- */
.week-grid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.wg-row { display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.wg-row:last-child { border-bottom: 0; }
.wg-head { position: sticky; top: 0; background: var(--surface); }
.wg-time { font-size: .68rem; color: var(--muted); padding: 6px 2px 0; text-align: center; font-variant-numeric: tabular-nums; }
.wg-day { display: flex; flex-direction: column; align-items: center; padding: 6px 0; font-size: .72rem; color: var(--muted); }
.wg-day .wg-date { font-size: .95rem; font-weight: 700; color: var(--text); }
.wg-day.today .wg-date { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; }
.wg-cell { min-height: 52px; border: 0; border-left: 1px solid var(--line); background: transparent; padding: 2px; margin: 0; font: inherit; color: var(--text); }
.wg-cell.today { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.wg-cell.add { color: transparent; cursor: pointer; font-size: 1.1rem; }
.wg-cell.add:hover, .wg-cell.add:focus-visible { color: var(--accent); background: var(--accent-soft); }
.wg-cell.cls {
  position: relative; cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: stretch;
  text-align: left; padding: 4px 3px 4px 5px; margin: 2px; border-radius: 7px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); border-left: 3px solid var(--c);
  min-width: 0; overflow: hidden;
}
.wg-cell.cls.mine { background: var(--c); color: #fff; }
.wg-cell.cls.muted { opacity: .5; }
.wg-cell.cls.full:not(.mine) .wg-sub { color: var(--danger); }
.wg-cell.cls.cancelled { background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 4px, var(--surface) 4px, var(--surface) 8px); border-left-color: var(--muted); }
.wg-cell.cls.cancelled .wg-title { text-decoration: line-through; color: var(--muted); }
.wg-title { font-size: .66rem; font-weight: 700; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wg-sub { font-size: .62rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wg-check { position: absolute; top: 2px; right: 3px; font-size: .65rem; font-weight: 700; }
@media (min-width: 560px) {
  .wg-row { grid-template-columns: 54px repeat(7, minmax(0, 1fr)); }
  .wg-title { font-size: .8rem; }
  .wg-sub { font-size: .72rem; }
  .wg-cell { min-height: 58px; }
}
.legend { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); }
.lg.mine { color: var(--accent); font-weight: 600; }

.spots { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.spots-bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.spots-bar > div { height: 100%; background: var(--accent); }

/* ---------- sheet + toast ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgb(10 8 30 / 0%);
  display: flex; align-items: flex-end; justify-content: center; transition: background .2s;
}
.sheet-backdrop.open { background: rgb(10 8 30 / 45%); }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateY(100%); transition: transform .2s ease-out;
}
.sheet-backdrop.open .sheet { transform: none; }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding-top: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500;
  max-width: calc(100vw - 32px); transition: all .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
#toast.ok { background: var(--ok); color: #fff; }

.spinner { width: 32px; height: 32px; margin: 48px auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- auth + check-in ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 32px) 16px 32px; }
.brand { text-align: center; margin-bottom: 12px; }
.brand img { border-radius: 18px; }
.brand h1 { font-size: 1.5rem; margin-top: 8px; }
.checkin-result { text-align: center; padding: 32px 8px; }
.big-check { width: 110px; height: 110px; margin: 0 auto 18px; border-radius: 50%; display: grid; place-items: center; font-size: 3.6rem; font-weight: 700; background: var(--ok); color: #fff; animation: pop .35s ease-out; }
.checkin-result.already .big-check { background: var(--accent); }
.checkin-result.fail .big-check { background: var(--danger); }
.checkin-result .btn { margin-top: 16px; min-width: 160px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- printable QR ---------- */
.print-sheet { text-align: center; background: #fff; color: #111; border-radius: var(--radius); padding: 24px 16px; border: 1px solid var(--line); }
.qr-img svg { width: min(320px, 80vw); height: auto; }
.print-title { font-size: 1.6rem; margin: 0 0 8px; color: #111; }
.print-cta { font-size: 1.2rem; font-weight: 700; margin: 8px 0 4px; }
.print-sub { color: #555; margin: 0; }
@media print {
  header.top, nav.tabs, .no-print, #toast { display: none !important; }
  body, main { background: #fff; padding: 0; }
  .print-sheet { border: 0; padding-top: 15vh; }
  .qr-img svg { width: 12cm; }
  .print-title { font-size: 32pt; }
  .print-cta { font-size: 22pt; }
  .print-sub { font-size: 14pt; }
}

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

/* ---------- added: overbooked, scan, install popup, packages, messages ---------- */
.wg-cell.cls.over { box-shadow: inset 0 0 0 2px var(--danger); }
.wg-cell.cls.over .wg-sub { color: var(--danger); font-weight: 700; }
.lg.over { color: var(--danger); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.legend { gap: 8px; flex-wrap: wrap; }
textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text); resize: vertical;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pre { white-space: pre-wrap; }
.card.news { background: var(--accent-soft); border-color: transparent; }
.card.news p { margin: 6px 0 0; }
.scan-cta { display: flex; align-items: center; gap: 14px; color: var(--text); }
.scan-cta-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 1.4rem; flex: none; }
.usage { margin: 10px 0; }
.usage .spots-bar { margin-top: 4px; }

.scan-frame { position: relative; width: 100%; max-width: 420px; margin: 8px auto; aspect-ratio: 1; border-radius: 20px; overflow: hidden; background: #000; }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-target { position: absolute; inset: 18%; border: 3px solid rgb(255 255 255 / 85%); border-radius: 18px; box-shadow: 0 0 0 999px rgb(0 0 0 / 35%); }
.scan-status { text-align: center; color: var(--muted); }

.install-pop {
  position: fixed; left: 12px; right: 12px; z-index: 15;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 8px 30px rgb(20 18 50 / 18%);
  transform: translateY(20px); opacity: 0; transition: all .25s;
}
.install-pop.show { transform: none; opacity: 1; }
.install-pop img { border-radius: 10px; }
.steps { padding-left: 20px; }
.steps li { margin: 8px 0; }

.list-item.plain { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.list.pick { max-height: 50vh; overflow: auto; }
.rule { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip-toggle { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip-toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
nav.tabs a { font-size: .68rem; }
.plain-list { list-style: none; padding: 0; margin: 8px 0; }
.plain-list > li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.plain-list > li:last-child { border-bottom: 0; }
.pkg + .pkg { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.pkg-options { display: flex; flex-direction: column; gap: 8px; }
.pkg-option { text-align: left; font: inherit; color: var(--text); background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.pkg-option.on { border-color: var(--accent); background: var(--accent-soft); }
.pkg-option:disabled { opacity: .6; cursor: default; }
.right { text-align: right; } .right .badge { margin: 2px 0 0; }
.update-pop {
  position: fixed; left: 12px; right: 12px; z-index: 25; top: calc(env(safe-area-inset-top) + 10px);
  max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 12px;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 16px; box-shadow: 0 8px 30px rgb(20 18 50 / 18%);
  transform: translateY(-20px); opacity: 0; transition: all .25s;
}
.update-pop.show { transform: none; opacity: 1; }
.update-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 1.2rem; flex: none; }
.consents { margin: 14px 0 4px; }
.switch.top { align-items: flex-start; font-size: .9rem; }
.switch.top input { margin-top: 2px; }
.link.inline { padding: 0; font-weight: 600; font-size: inherit; text-decoration: underline; }
.legal h3 { margin-top: 18px; }
.legal ul { padding-left: 20px; }
.legal li { margin: 6px 0; }
.legal-page h1 { font-size: 1.5rem; margin-bottom: 4px; }
.lang-switch { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin: 6px 0 12px; }
.lang-switch button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; padding: 8px; border-radius: 9px; cursor: pointer; }
.lang-switch button.on { background: var(--accent); color: var(--accent-ink); }
/* sign-in screen: small centered pill above the logo */
.auth .lang-switch { width: max-content; margin: 0 auto 22px; }
.auth .lang-switch button { flex: none; padding: 6px 14px; font-size: .85rem; }
.label.small { font-weight: 600; margin-top: 8px; }
