:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #23201b;
  --muted: #6b6357;
  --line: #e3ddd0;
  --accent: #0f766e;
  --accent-ink: #0b5850;
  --accent-soft: #d7ece9;
  --warn: #b4472e;
  --shadow: 0 1px 2px rgba(60,50,30,.06), 0 6px 20px rgba(60,50,30,.06);
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --card: #201d16;
    --ink: #ece7dc;
    --muted: #a49a88;
    --line: #35301f;
    --accent: #5ec9bd;
    --accent-ink: #8fe0d6;
    --accent-soft: #143b37;
    --warn: #e78a71;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
/* Ensure [hidden] always wins — otherwise .gate{display:grid} keeps the
   sign-in gate on screen after login. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  font-size: 16px;
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; font-weight: 600; }
h2 { font-size: 1.5rem; margin: 0 0 .5rem; }
h3 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; color: var(--accent-ink); }
a { color: var(--accent-ink); }
em { color: var(--muted); font-style: italic; }
.lead { color: var(--muted); margin: .25rem 0 1rem; }
.chip { background: var(--accent-soft); color: var(--accent-ink); padding: .05rem .4rem; border-radius: 6px; font-size: .85em; }

/* ---------- Gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.gate-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2rem 1.75rem; width: 100%; max-width: 400px; text-align: center;
}
.brand { font-size: 2.5rem; }
.gate-card h1 { font-size: 1.4rem; margin: .5rem 0 .15rem; }
.tagline { color: var(--muted); margin: 0 0 1.5rem; }
.gate-card form { display: grid; gap: .9rem; text-align: left; }
label { display: grid; gap: .35rem; font-size: .9rem; color: var(--muted); }
input[type=text] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; width: 100%;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: .7rem 1rem;
}
button:hover { background: var(--accent-ink); }
.fineprint { color: var(--muted); font-size: .8rem; margin: 1.25rem 0 0; }
.error { color: var(--warn); font-size: .88rem; margin: 0; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 780px; margin: 0 auto; display: flex; align-items: center; gap: .75rem;
  padding: .55rem 1rem; flex-wrap: wrap; }
.topbar-title { font-family: var(--serif); font-weight: 600; }
.tabs { display: flex; gap: .25rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: var(--muted); text-decoration: none; padding: .3rem .55rem; border-radius: 8px; white-space: nowrap; font-size: .9rem; }
.tabs a:hover { background: var(--accent-soft); color: var(--accent-ink); }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.whoami { font-size: .85rem; color: var(--muted); max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn, .ghostbtn { background: none; color: var(--accent-ink); padding: .3rem .4rem; font-size: .85rem; }
.linkbtn:hover { background: none; text-decoration: underline; }
.ghostbtn { border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
.ghostbtn:hover { background: var(--accent-soft); }
.save-status { max-width: 780px; margin: 0 auto; padding: 0 1rem; height: 0; overflow: visible; }
.save-status span { position: absolute; transform: translateY(-2px); font-size: .78rem; color: var(--accent-ink); }

/* ---------- Layout ---------- */
.wrap { max-width: 780px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem 1.35rem; margin: 1.25rem 0; scroll-margin-top: 4.5rem; }

/* ---------- Sessions strip ---------- */
.sessions { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.sess { display: block; width: 100%; text-align: left; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; background: var(--card); cursor: pointer; }
.sess:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.sess .num, .sess .ttl, .sess .badge { display: block; }
.sess .num { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sess .ttl { font-size: .9rem; font-weight: 600; margin: .1rem 0; }
.sess.active { border-color: var(--accent); background: var(--accent-soft); }
.sess.locked, .sess:disabled { opacity: .55; cursor: default; }
.sess .badge { font-size: .68rem; color: var(--muted); }

.session-head { margin: .25rem 0 1rem; }
.session-kicker { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.session-head h2 { margin: .1rem 0 0; }
.assessment-block { margin-top: .5rem; }

.leadbox { border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; margin: 0 0 1.25rem; background: var(--bg); }
.leadbox h3 { margin-top: 0; }

/* ---------- Assessment ---------- */
.mark { border-top: 1px solid var(--line); padding: 1rem 0 .5rem; }
.mark:first-child { border-top: none; }
.mark-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.mark-title { font-weight: 600; }
.mark-total { font-variant-numeric: tabular-nums; color: var(--accent-ink); font-weight: 600; white-space: nowrap; }
.qrow { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }
.qnum { width: 1.4rem; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.scale { display: inline-flex; gap: .25rem; margin-left: auto; }
.scale button {
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
  width: 2rem; height: 2rem; padding: 0; border-radius: 8px; font-weight: 600;
}
.scale button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.scalekey { font-size: .78rem; color: var(--muted); margin: .25rem 0 .75rem; }

.results { margin-top: 1.5rem; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: .35rem .6rem; align-items: center; margin: .5rem 0; }
.bar .blabel { font-size: .85rem; }
.bar .btrack { grid-column: 1 / -1; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; height: 12px; overflow: hidden; }
.bar .bfill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-ink)); border-radius: 6px 0 0 6px; transition: width .3s; }
.levelkey { margin-top: 1.25rem; display: grid; gap: .5rem; }
.levelkey .lv { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; font-size: .9rem; }
.levelkey .lv b { color: var(--accent-ink); }

/* ---------- Fields / reflections ---------- */
.field { margin: 1rem 0; }
.field > label { color: var(--ink); font-size: .95rem; font-weight: 600; margin-bottom: .35rem; }
.field .ref { font-size: .82rem; }
.field .note { font-size: .8rem; color: var(--muted); }
textarea, input.textline {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem .7rem; width: 100%; resize: vertical; min-height: 3rem;
}
.reflect { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem; }
.reflect:first-child { border-top: none; }
.reflect .day { font-family: var(--serif); font-weight: 600; }
.reflect .theme { color: var(--muted); font-size: .85rem; }
.share-row { display: flex; align-items: center; gap: .5rem; margin-top: .4rem; flex-wrap: wrap; }
.share-row label { flex-direction: row; align-items: center; gap: .35rem; font-size: .82rem; }
select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .35rem .5rem; }
.shared-tag { font-size: .75rem; color: var(--accent-ink); background: var(--accent-soft); padding: .1rem .45rem; border-radius: 6px; }

/* ---------- CTR ---------- */
.ctr-item { margin: .9rem 0; }
.ctr-item .cname { font-weight: 600; }
.ctr-item .stem { color: var(--accent-ink); font-family: var(--serif); }
.ctr-item .hint { font-size: .82rem; color: var(--muted); margin: .1rem 0 .35rem; }

/* ---------- Homework ---------- */
.check { display: flex; align-items: center; gap: .55rem; margin: .5rem 0; font-size: .95rem; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

/* ---------- Feed ---------- */
.feed { display: grid; gap: .75rem; margin-top: 1rem; }
.post { border: 1px solid var(--line); border-radius: 10px; padding: .75rem .85rem; background: var(--bg); }
.post .meta { display: flex; justify-content: space-between; gap: .5rem; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
.post .author { font-weight: 600; color: var(--ink); }
.post .ctx { font-size: .78rem; color: var(--muted); font-style: italic; }
.post .body { white-space: pre-wrap; }
.empty { color: var(--muted); font-size: .9rem; padding: .75rem 0; }

/* ---------- Subgroups ---------- */
.subgroup-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.inline-form { display: flex; gap: .4rem; }
.inline-form input { width: 11rem; }
.inline-form button { padding: .55rem .8rem; }
.subgroups { display: grid; gap: .6rem; }
.sg { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .85rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.sg .sgname { font-weight: 600; }
.sg .sgmeta { font-size: .8rem; color: var(--muted); }
.sg .code { font-family: var(--serif); letter-spacing: .08em; background: var(--accent-soft); color: var(--accent-ink); padding: .1rem .45rem; border-radius: 6px; cursor: pointer; }
.sg-actions { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--muted); flex-wrap: wrap; justify-content: flex-end; }
.delbtn { background: none; border: 1px solid var(--line); color: var(--warn); border-radius: 8px; padding: .3rem .55rem; font-size: .8rem; font-weight: 600; }
.delbtn:hover { background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: var(--warn); }

.appfoot { color: var(--muted); font-size: .82rem; margin-top: 2rem; text-align: center; }
.appfoot em { font-style: italic; }

/* ---------- Insights / visualization ---------- */
.stat-row { display: flex; gap: .6rem; flex-wrap: wrap; margin: .75rem 0 1.25rem; }
.stat { flex: 1 1 120px; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .85rem; background: var(--bg); }
.stat-num { font-family: var(--serif); font-size: 1.7rem; line-height: 1; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

.vizbars { display: grid; gap: .45rem; margin: .5rem 0 1rem; }
.vbar { display: grid; grid-template-columns: 7rem 1fr 2rem; align-items: center; gap: .55rem; }
.vbar-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vbar-track { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; height: 14px; overflow: hidden; }
.vbar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-ink)); border-radius: 0 3px 3px 0; min-width: 2px; }
.vbar-val { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--accent-ink); text-align: right; }

.grid-scroll { overflow-x: auto; margin: .35rem 0 .25rem; -webkit-overflow-scrolling: touch; }
table.pgrid { border-collapse: collapse; font-size: .82rem; }
.pgrid th, .pgrid td { border: 1px solid var(--line); padding: .3rem .35rem; text-align: center; }
.pgrid thead th { background: var(--bg); color: var(--muted); font-weight: 600; }
.pgrid .colnum { min-width: 1.7rem; font-variant-numeric: tabular-nums; cursor: default; }
.pgrid .corner, .pgrid .rowname { position: sticky; left: 0; background: var(--card); text-align: left;
  white-space: nowrap; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.pgrid td.cell { color: transparent; }
.pgrid td.cell.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.promptkey { margin: .5rem 0 0; padding-left: 1.3rem; color: var(--muted); font-size: .82rem; display: grid; gap: .18rem; }
.keywrap { margin-top: .5rem; }
.keywrap summary { cursor: pointer; color: var(--accent-ink); font-size: .85rem; }

@media (max-width: 520px) {
  .topbar-title { display: none; }
  .inline-form input { width: 8.5rem; }
}
