:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede5;
  --ink: #1d2b25;
  --ink-2: #4d5c55;
  --muted: #7b8882;
  --line: #e2ddd2;
  --brand: #1f5f4a;
  --brand-2: #2f7a60;
  --brand-soft: #e3efe9;
  --accent: #c8862f;
  --accent-soft: #f7ecdc;
  --danger: #b4412f;
  --danger-soft: #f8e4e0;
  --ok: #2f7a4a;
  --ok-soft: #e2f1e6;
  --warn: #9a6a12;
  --warn-soft: #fbf0d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29, 43, 37, .06), 0 4px 16px rgba(29, 43, 37, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131a17; --surface: #1b2420; --surface-2: #222d28; --ink: #e8ede9; --ink-2: #b9c4be; --muted: #8d9a93;
    --line: #2e3a35; --brand: #5fb592; --brand-2: #7cc9a8; --brand-soft: #1f342b; --accent: #e0a24f; --accent-soft: #3a2e1d;
    --danger: #e27a68; --danger-soft: #3b231f; --ok: #6fc28a; --ok-soft: #1d3326; --warn: #e3b555; --warn-soft: #3a3019;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131a17; --surface: #1b2420; --surface-2: #222d28; --ink: #e8ede9; --ink-2: #b9c4be; --muted: #8d9a93;
  --line: #2e3a35; --brand: #5fb592; --brand-2: #7cc9a8; --brand-soft: #1f342b; --accent: #e0a24f; --accent-soft: #3a2e1d;
  --danger: #e27a68; --danger-soft: #3b231f; --ok: #6fc28a; --ok-soft: #1d3326; --warn: #e3b555; --warn-soft: #3a3019;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; font-family: var(--font); font-weight: 650; }
p { margin: 0 0 .8em; }
small, .small { font-size: .86rem; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: .88em; }
pre { white-space: pre-wrap; word-break: break-word; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.app.public { grid-template-columns: 1fr; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 1.3rem; font-weight: 600; color: var(--ink); text-decoration: none; margin: 0 6px 22px; }
.brand svg { flex: none; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 10px 6px; }
.side-foot { margin-top: 24px; padding: 12px 10px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.main { padding: 28px clamp(16px, 4vw, 44px) 60px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; color: var(--ink-2); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; height: 100%; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .main { padding: 20px 16px 60px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.tight { padding: 14px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
@media (min-width: 861px) and (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.right { margin-left: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 9px 16px; font: 600 .92rem var(--font); cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 6px 10px; font-size: .84rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=url], input[type=month], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; min-height: 380px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; accent-color: var(--brand); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 650; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.notice { padding: 12px 14px; border-radius: 8px; background: var(--brand-soft); color: var(--ink); margin-bottom: 16px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); }
.notice.danger { background: var(--danger-soft); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.table-wrap { overflow-x: auto; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }

.stat { padding: 16px; }
.stat .k { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 1.6rem; font-weight: 700; font-family: var(--serif); margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: 600 .92rem var(--font); color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.steps span { font-size: .8rem; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.steps span.done { background: var(--ok-soft); color: var(--ok); }
.steps span.on { background: var(--brand); color: #fff; }

.option { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer; background: var(--surface); }
.option:hover { border-color: var(--brand-2); }
.option.selected { border-color: var(--brand); background: var(--brand-soft); }
.option input { margin-top: 4px; accent-color: var(--brand); }
.qtext { font-size: 1.05rem; font-weight: 550; margin-bottom: 14px; white-space: pre-wrap; }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 6px 12px; border-radius: 8px; background: var(--surface-2); }
.timer.low { background: var(--danger-soft); color: var(--danger); }

.role-card .match { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .8rem; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.chip.gap { background: var(--accent-soft); color: var(--warn); }

.week { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; background: var(--surface); }
.week > summary { padding: 12px 14px; cursor: pointer; font-weight: 600; list-style: none; display: flex; gap: 10px; align-items: center; }
.week > summary::-webkit-details-marker { display: none; }
.week .body { padding: 0 14px 14px; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-top: 1px dashed var(--line); }
.task:first-child { border-top: 0; }
.task.done .t { text-decoration: line-through; color: var(--muted); }

.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; }
.bubble.q { background: var(--surface-2); align-self: flex-start; }
.bubble.a { background: var(--brand-soft); align-self: flex-end; }

.toast-wrap { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 11px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: .92rem; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.modal-back { position: fixed; inset: 0; background: rgba(15, 22, 19, .45); z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: min(720px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 1.15rem; }
.modal .mbody { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.loading-page { padding: 60px 0; text-align: center; color: var(--muted); }

/* public pages */
.hero { padding: 64px clamp(16px, 6vw, 80px) 40px; max-width: 1100px; margin: 0 auto; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); max-width: 16ch; }
.hero .lead { font-size: 1.15rem; color: var(--ink-2); max-width: 60ch; }
.pub-nav { display: flex; justify-content: space-between; align-items: center; padding: 18px clamp(16px, 6vw, 80px); max-width: 1100px; margin: 0 auto; }
.pub-section { max-width: 1100px; margin: 0 auto; padding: 10px clamp(16px, 6vw, 80px) 40px; }
.num { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.auth-box { max-width: 440px; margin: 8vh auto; }
.radar text { font-size: 11px; fill: var(--ink-2); }
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .no-print, .toast-wrap { display: none !important; }
  .app { display: block; } .main { padding: 0; } .card { box-shadow: none; border: 0; }
  .print-only { display: block; }
}
.exam-layout { display: grid; grid-template-columns: 1fr 240px; gap: 18px; align-items: start; }
.exam-nav { position: sticky; top: 16px; }
.qgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.qgrid button { padding: 6px 0; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); font-size: .78rem; cursor: pointer; color: var(--ink); }
.qgrid button.ans { background: var(--brand-soft); border-color: var(--brand-2); }
.qgrid button.cur { outline: 2px solid var(--brand); }
@media (max-width: 860px) { .exam-layout { grid-template-columns: 1fr; } .exam-nav { position: static; } }
.no-select { user-select: none; -webkit-user-select: none; }
