/* TExES Prep — calm study-desk look: warm paper, deep teal, amber highlights. */
:root {
  --paper: #f6f3ec;
  --card: #fffdf8;
  --ink: #1d2a2a;
  --muted: #5d6b69;
  --line: #e2ddd1;
  --teal: #0f3d3a;
  --teal-2: #17605a;
  --teal-soft: #e3efec;
  --amber: #e8a33d;
  --amber-soft: #fbf0dc;
  --good: #1f7a4d;
  --good-soft: #e3f3ea;
  --bad: #b23a2e;
  --bad-soft: #fbe7e4;
  --mid: #a86a0b;
  --mid-soft: #fbefd9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 42, 42, .06), 0 4px 16px rgba(29, 42, 42, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121a19;
    --card: #1a2423;
    --ink: #e8ece9;
    --muted: #9aa8a5;
    --line: #2c3a38;
    --teal: #7cc7bb;
    --teal-2: #9fd8cd;
    --teal-soft: #1f3431;
    --amber: #f0b45a;
    --amber-soft: #3a2e1a;
    --good: #6fcf9a;
    --good-soft: #193326;
    --bad: #f08a7d;
    --bad-soft: #3a1f1c;
    --mid: #f0b45a;
    --mid-soft: #3a2e1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.55 var(--sans); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--teal-2); }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 6px; }

.shell { min-height: 100vh; min-height: 100dvh; }
.main { max-width: 1040px; margin: 0 auto; padding: 20px 16px calc(40px + env(safe-area-inset-bottom)); }
.shell.focus .main { max-width: 820px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--teal); color: #f6f3ec; }
@media (prefers-color-scheme: dark) { .topbar { background: #0b2422; } }
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; white-space: nowrap; }
.brand img { border-radius: 7px; }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link { color: rgba(246, 243, 236, .82); text-decoration: none; padding: 10px 12px; border-radius: 10px; white-space: nowrap; font-size: .95rem; min-height: 44px; display: flex; align-items: center; }
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link.on { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
@media (max-width: 560px) {
  .brand span { display: none; }
  .nav-link { padding: 10px 9px; font-size: .9rem; }
}

/* layout bits */
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 16px; }
.cards-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.good-text { color: var(--good); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 420px; margin: 8vh auto 0; }
.card.narrow-left { max-width: 560px; }
.card.accent { border-color: var(--amber); background: var(--amber-soft); }
.card.big { display: flex; flex-direction: column; }
.card.big p { flex: 1; }
.card.big .btn { align-self: flex-start; }
.login { text-align: center; }
.login form { text-align: left; }
.login-icon { margin: 0 auto 12px; border-radius: 14px; }
.hello h1 { font-size: 2rem; margin-bottom: 2px; }
.more { display: inline-block; margin-top: 10px; font-weight: 600; text-decoration: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { border-color: var(--teal-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1615; } }
.btn.primary:hover { background: var(--teal-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .875rem; border-radius: 9px; }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }
.spacer-btn { width: 84px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: .95rem; }
input[type=text], input[type=password], input:not([type]), textarea { font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); width: 100%; min-height: 44px; }
input:focus, textarea:focus { border-color: var(--teal-2); outline: none; box-shadow: 0 0 0 3px var(--teal-soft); }
.hint { color: var(--muted); }
.form-error { color: var(--bad); min-height: 0; margin: 0; }
.form-error:empty { display: none; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--teal-2); }
.stat-value { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; color: var(--teal); }
.stat-label { color: var(--muted); font-size: .85rem; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list-main { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
a.list-main:hover strong { text-decoration: underline; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--teal-2); background: var(--teal-soft); padding: 2px 7px; border-radius: 6px; vertical-align: 2px; }
.pill { display: inline-block; font-size: .8rem; font-weight: 700; padding: 3px 10px; border-radius: 8px; background: var(--teal-soft); color: var(--teal-2); white-space: nowrap; }
.lv-strong { background: var(--good-soft); color: var(--good); }
.lv-mid { background: var(--mid-soft); color: var(--mid); }
.lv-weak { background: var(--bad-soft); color: var(--bad); }
.lv-none { background: var(--paper); color: var(--muted); }
.comp-num { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); font-size: .85rem; min-width: 2.6em; }
.weak-list, .comp-table { list-style: none; margin: 0 0 14px; padding: 0; }
.weak-list li, .comp-table li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.weak-list li:first-child, .comp-table li:first-child { border-top: 0; }
.comp-table.compact li { padding: 7px 0; font-size: .93rem; }
.mastery-domain { margin-top: 18px; }
.mastery-domain .comp-table { margin: 6px 0 0 8px; }
@media (max-width: 560px) {
  .comp-table li { flex-wrap: wrap; }
  .comp-table li .grow { flex-basis: calc(100% - 3.2em); }
  .comp-table li .small.muted { margin-left: 3.2em; }
  .spacer-btn { display: none; }
}

/* bars */
.bars > * + * { margin-top: 14px; }
.bar-row { width: 100%; }
.bar-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-weight: 600; font-size: .95rem; }
.bar { height: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--teal-2); border-radius: 6px; transition: width .5s ease; }
.bar-fill.lv-strong { background: var(--good); }
.bar-fill.lv-mid { background: var(--amber); }
.bar-fill.lv-weak { background: var(--bad); }

/* practice builder */
.opt-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.opt-label { font-weight: 600; min-width: 90px; }
.seg { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button, .seg a { font: inherit; font-size: .9rem; border: 0; background: transparent; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 38px; text-decoration: none; display: inline-flex; align-items: center; }
.seg .on { background: var(--teal); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg .on { color: #0b1615; } }
.picker { display: grid; gap: 14px; }
.domain-box { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 6px 16px 10px; margin: 0; }
.domain-box legend { padding: 0 6px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; min-height: 44px; }
.check.strong { font-weight: 700; font-family: var(--serif); font-size: 1.05rem; }
.check input { flex: none; width: 20px; height: 20px; accent-color: var(--teal); }

/* test runner */
.test-head { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 0 10px; background: var(--paper); border-bottom: 1px solid var(--line); margin: -20px 0 14px; }
.test-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.test-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 6px 10px; border-radius: 9px; background: var(--teal-soft); color: var(--teal-2); white-space: nowrap; }
.timer.warn { background: var(--bad-soft); color: var(--bad); }
.q-meta { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; font-weight: 600; margin-bottom: 6px; flex-wrap: wrap; }
.progress-bar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress-fill { height: 100%; width: 0; background: var(--amber); transition: width .3s; }
.q-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.stem { font-size: 1.08rem; margin-bottom: 16px; }
.stem p { margin-bottom: .6em; }
.table-wrap { overflow-x: auto; margin: 8px 0 12px; }
table.data { border-collapse: collapse; font-size: .95rem; min-width: 60%; }
table.data th, table.data td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
table.data th { background: var(--paper); }
.choices { display: grid; gap: 10px; }
.choice { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; min-height: 52px; transition: border-color .12s, background .12s; }
button.choice:hover:not([disabled]) { border-color: var(--teal-2); }
.choice .letter { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; background: var(--card); border: 1px solid var(--line); }
.choice-text { flex: 1; padding-top: 3px; }
.choice .mark { flex: none; font-weight: 700; padding-top: 3px; font-size: .9rem; }
.choice.picked { border-color: var(--teal); background: var(--teal-soft); }
.choice.picked .letter { background: var(--teal); color: #fff; border-color: var(--teal); }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right .letter { background: var(--good); color: #fff; border-color: var(--good); }
.choice.right .mark { color: var(--good); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
.choice.wrong .mark { color: var(--bad); }
.choice[disabled] { cursor: default; }
.choice.static { cursor: default; }
.q-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.q-nav .btn.primary { margin-left: auto; }
.flag-btn.on { background: var(--amber-soft); border-color: var(--amber); color: var(--mid); }
.qgrid-wrap:empty { display: none; }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.qcell { font: inherit; font-size: .85rem; font-weight: 600; min-width: 42px; min-height: 42px; border-radius: 9px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; position: relative; }
.qcell.done { background: var(--teal-soft); border-color: var(--teal-2); }
.qcell.right { background: var(--good-soft); border-color: var(--good); }
.qcell.wrong { background: var(--bad-soft); border-color: var(--bad); }
.qcell.cur { outline: 2px solid var(--amber); outline-offset: 1px; }
.qcell.flag::after { content: ""; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 2px; background: var(--amber); }

/* feedback + chat */
.feedback { margin-top: 18px; padding: 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); }
.feedback.good { border-color: var(--good); }
.feedback.bad { border-color: var(--bad); }
.verdict { font-weight: 700; font-family: var(--serif); font-size: 1.1rem; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.chat { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.chat-toggle { color: var(--teal-2); }
.chat-panel { margin-top: 12px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--teal); color: #fff; max-width: 85%; }
@media (prefers-color-scheme: dark) { .msg.user { color: #0b1615; } }
.msg.assistant { background: var(--card); border: 1px solid var(--line); }
.msg-who { font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; opacity: .7; margin-bottom: 2px; }
.msg-body p:last-child, .msg-body ul:last-child, .msg-body ol:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 0 0 .75em; padding-left: 1.3em; }
.msg-body code { background: var(--paper); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.dots::after { content: "…"; animation: blink 1s infinite steps(2); }
@keyframes blink { 50% { opacity: .2; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; cursor: pointer; min-height: 36px; }
.chip:hover { border-color: var(--teal-2); }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { resize: vertical; min-height: 44px; }

/* results */
.result-hero { display: flex; gap: 24px; align-items: center; }
@media (max-width: 640px) { .result-hero { flex-direction: column; align-items: flex-start; } }
.score-ring { --p: 0; --c: var(--teal-2); flex: none; width: 150px; height: 150px; border-radius: 50%; display: grid; place-content: center; text-align: center; background: radial-gradient(closest-side, var(--card) 78%, transparent 79% 100%), conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); }
.score-ring.lv-strong { --c: var(--good); background-color: transparent; }
.score-ring.lv-mid { --c: var(--amber); background-color: transparent; }
.score-ring.lv-weak { --c: var(--bad); background-color: transparent; }
.score-num { font-family: var(--serif); font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--ink); }
.score-sub { color: var(--muted); font-weight: 600; margin-top: 4px; }

/* trend chart */
.trend { width: 100%; height: auto; max-height: 220px; }
.trend .line { fill: none; stroke: var(--teal-2); stroke-width: 3; stroke-linejoin: round; }
.trend .dot { fill: var(--teal); }
.trend .dot-label { font: 600 13px var(--sans); fill: var(--ink); }
.trend .goal { stroke: var(--amber); stroke-dasharray: 6 5; stroke-width: 2; }
.trend .goal-label { font: 600 12px var(--sans); fill: var(--mid); }

/* misc */
.loading { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 60px 0; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--teal-2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; z-index: 100; transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }

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