/* =========================================================================
   Study Bot — "private bank dossier" editorial theme
   Display: Fraunces · Body: Hanken Grotesk · Labels: Spline Sans Mono
   ========================================================================= */
:root {
  --paper:      #f4efe4;   /* warm parchment */
  --paper-2:    #fbf8f1;   /* card / raised */
  --paper-3:    #efe8d9;   /* sunken / sidebar */
  --ink:        #1f1b15;   /* near-black, warm */
  --ink-2:      #4a4338;   /* secondary text */
  --ink-3:      #857c6c;   /* muted */
  --rule:       #ddd3bf;   /* hairlines */
  --rule-2:     #cabfa6;
  --gold:       #9c7320;   /* brass accent (text-safe) */
  --gold-2:     #f0b400;   /* bright highlight / active */
  --forest:     #20352b;   /* deep accent (examiner) */
  --good:       #2f6b3a;
  --good-bg:    #e7f0e3;
  --bad:        #9c3320;
  --bad-bg:     #f4e3dd;
  --warn:       #8a6410;
  --radius:     4px;
  --shadow-sm:  0 1px 2px rgba(31,27,21,.06);
  --shadow:     0 14px 40px -22px rgba(31,27,21,.45);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.62;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(120% 90% at 12% -10%, rgba(240,180,0,.10), transparent 55%),
    radial-gradient(120% 120% at 110% 10%, rgba(32,53,43,.08), transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(31,27,21,.022) 0.6px, transparent 0.6px);
  background-size: auto, auto, 22px 22px;
  background-attachment: fixed;
  min-height: 100vh;
}

::selection { background: var(--gold-2); color: var(--ink); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  padding: 2.4rem 1.6rem;
  background: var(--paper-3);
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column;
}
.logo-img { display: block; width: 100%; max-width: 188px; height: auto; }
.mark { display: flex; align-items: baseline; gap: .55rem; }
.mark-glyph {
  font-family: "Fraunces", serif; font-size: 1.7rem; color: var(--gold);
  line-height: 1; transform: translateY(2px);
}
.mark-name {
  font-family: "Fraunces", serif; font-weight: 500; font-size: 1.45rem;
  letter-spacing: -.01em; color: var(--ink);
}
.mark-sub {
  margin: .45rem 0 0; font-family: "Spline Sans Mono", monospace;
  font-size: .64rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}

.nav { margin-top: 2.6rem; display: flex; flex-direction: column; gap: .15rem; }
.tab {
  appearance: none; border: none; background: none; cursor: pointer;
  display: flex; align-items: baseline; gap: .8rem;
  padding: .62rem .7rem .62rem 1rem; margin-left: -.4rem;
  color: var(--ink-2); text-align: left; width: 100%;
  border-left: 2px solid transparent; border-radius: 0 var(--radius) var(--radius) 0;
  transition: color .2s, background .2s, border-color .2s;
}
.tab i {
  font-family: "Spline Sans Mono", monospace; font-style: normal;
  font-size: .68rem; color: var(--ink-3); letter-spacing: .05em;
  width: 1.4em; flex: none; transition: color .2s;
}
.tab span {
  font-family: "Fraunces", serif; font-size: 1.06rem; font-weight: 400;
  letter-spacing: -.005em;
}
.tab:hover { color: var(--ink); background: rgba(156,115,32,.07); }
.tab.active { color: var(--ink); border-left-color: var(--gold-2); background: rgba(156,115,32,.10); }
.tab.active i { color: var(--gold); }

.sidefoot {
  margin-top: auto; padding-top: 1.4rem; border-top: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: .6rem;
  font-family: "Spline Sans Mono", monospace; font-size: .62rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}
.signout {
  appearance: none; background: none; border: none; cursor: pointer;
  font-family: "Spline Sans Mono", monospace; font-size: .62rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
  padding: 0; text-align: left; transition: color .2s;
}
.signout:hover { color: var(--gold); background: none; box-shadow: none; }

/* ---------- main ---------- */
main { padding: 3rem clamp(1.5rem, 4vw, 3.4rem) 5rem; }
.panel { display: none; max-width: 1000px; }
.panel.active { display: block; animation: rise .5s cubic-bezier(.2,.7,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* panel header */
.ph { max-width: 62ch; margin-bottom: 1.8rem; }
.ph-idx {
  font-family: "Spline Sans Mono", monospace; font-size: .68rem;
  letter-spacing: .2em; text-transform: uppercase; color: var(--gold);
}
.ph h2 {
  font-family: "Fraunces", serif; font-weight: 400; font-optical-sizing: auto;
  font-size: clamp(1.9rem, 3.6vw, 2.7rem); line-height: 1.08;
  letter-spacing: -.02em; margin: .5rem 0 .55rem; color: var(--ink);
}
.ph h2::after {
  content: ""; display: block; width: 46px; height: 2px;
  background: var(--gold-2); margin-top: .9rem;
}
.ph p { margin: 0; color: var(--ink-2); font-size: .96rem; }

/* ---------- toggle switch ---------- */
.toggle {
  display: inline-flex; align-items: center; gap: .6rem; cursor: pointer;
  font-size: .82rem; color: var(--ink-2); margin-bottom: 1.1rem; user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  width: 38px; height: 21px; border-radius: 999px; background: var(--rule-2);
  position: relative; transition: background .22s; flex: none;
}
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px;
  border-radius: 50%; background: var(--paper-2); box-shadow: var(--shadow-sm);
  transition: transform .22s;
}
.toggle input:checked + .track { background: var(--gold); }
.toggle input:checked + .track::after { transform: translateX(17px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--gold-2); outline-offset: 2px; }

/* ---------- controls ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: 1rem 1.4rem; align-items: end;
  padding: 1.2rem 1.3rem; margin-bottom: 1.6rem;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.controls.slim { padding: .9rem 1.3rem; }
.controls label {
  display: flex; flex-direction: column; gap: .35rem;
  font-family: "Spline Sans Mono", monospace; font-size: .62rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}
select, input[type="number"], input[type="date"] {
  font-family: "Hanken Grotesk", sans-serif; font-size: .92rem; color: var(--ink);
  padding: .5rem .65rem; min-width: 150px;
  background: var(--paper); border: 1px solid var(--rule-2); border-radius: var(--radius);
  transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(156,115,32,.14);
}

/* ---------- buttons ---------- */
button {
  font-family: "Hanken Grotesk", sans-serif; font-weight: 600; font-size: .86rem;
  letter-spacing: .01em; cursor: pointer; color: var(--paper);
  background: var(--ink); border: 1px solid var(--ink);
  padding: .62rem 1.3rem; border-radius: var(--radius);
  transition: transform .12s, background .2s, box-shadow .2s;
}
button:hover { background: #000; box-shadow: 0 6px 16px -8px rgba(31,27,21,.6); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: progress; box-shadow: none; }

/* ---------- chat ---------- */
.chatlog {
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.4rem 1.5rem; min-height: 240px; max-height: 56vh; overflow-y: auto;
  box-shadow: var(--shadow-sm); margin-bottom: .9rem;
}
.msg { display: flex; gap: .9rem; margin-bottom: 1.4rem; }
.msg:last-child { margin-bottom: 0; }
.who {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: "Spline Sans Mono", monospace; font-size: .58rem; letter-spacing: .04em;
  border: 1px solid var(--rule-2); color: var(--ink-2); background: var(--paper);
}
.msg.assistant .who { background: var(--forest); color: #e9e3d4; border-color: var(--forest); }
.msg.user .who { background: var(--gold); color: var(--paper); border-color: var(--gold); }
.bubble {
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: .8rem 1.05rem; font-size: .94rem; max-width: 64ch;
}
.msg.assistant .bubble { background: var(--paper); border-left: 2px solid var(--forest); }
.msg.user .bubble { background: #fbf3df; border-left: 2px solid var(--gold-2); }
.bubble p { margin: 0 0 .65rem; } .bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: var(--ink); }
.bubble code { font-family: "Spline Sans Mono", monospace; font-size: .82em; background: var(--paper-3); padding: .08rem .32rem; border-radius: 3px; }
.bubble ul, .bubble ol { margin: .4rem 0; padding-left: 1.2rem; }
.empty { color: var(--ink-3); font-style: italic; font-family: "Fraunces", serif; }

.sources { margin-top: .7rem; padding-top: .6rem; border-top: 1px dashed var(--rule-2); font-size: .76rem; }
.sources b { font-family: "Spline Sans Mono", monospace; font-size: .62rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.sources a { display: block; color: var(--gold); text-decoration: none; margin-top: .25rem; word-break: break-all; }
.sources a:hover { color: var(--ink); text-decoration: underline; }

/* composer */
.composer { display: flex; gap: .7rem; align-items: stretch; }
.composer textarea {
  flex: 1; font-family: "Hanken Grotesk", sans-serif; font-size: .94rem; color: var(--ink);
  padding: .8rem .9rem; resize: vertical; min-height: 52px;
  background: var(--paper-2); border: 1px solid var(--rule-2); border-radius: var(--radius);
}
.composer button { align-self: stretch; padding-inline: 1.5rem; }

/* ---------- quiz ---------- */
.scoreboard {
  font-family: "Spline Sans Mono", monospace; font-size: .72rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--gold); margin-bottom: 1.3rem;
}
.qcard {
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.3rem 1.5rem; margin-bottom: 1.1rem; box-shadow: var(--shadow-sm);
  position: relative;
}
.qtopic {
  font-family: "Spline Sans Mono", monospace; font-size: .6rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-3);
}
.qtext {
  font-family: "Fraunces", serif; font-size: 1.18rem; line-height: 1.34; font-weight: 400;
  margin: .35rem 0 1rem; color: var(--ink);
}
.opt {
  display: block; padding: .65rem .85rem; margin-bottom: .5rem; font-size: .92rem;
  background: var(--paper); border: 1px solid var(--rule-2); border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s, background .15s, transform .1s;
}
.opt:hover { border-color: var(--ink-3); transform: translateX(2px); }
.opt.sel { border-color: var(--ink); background: #fbf3df; }
.opt.correct { border-color: var(--good); background: var(--good-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.qcard textarea {
  width: 100%; font-family: "Hanken Grotesk", sans-serif; font-size: .92rem;
  padding: .7rem .85rem; resize: vertical; min-height: 70px;
  background: var(--paper); border: 1px solid var(--rule-2); border-radius: var(--radius);
}
.qactions { margin-top: .85rem; display: flex; gap: .7rem; align-items: center; }
.feedback {
  margin-top: 1rem; padding: .9rem 1.05rem; font-size: .9rem;
  background: var(--paper); border: 1px solid var(--rule); border-left: 2px solid var(--gold);
  border-radius: var(--radius);
}
.feedback hr { border: none; border-top: 1px solid var(--rule); margin: .6rem 0; }
.feedback .score { font-family: "Spline Sans Mono", monospace; font-weight: 600; letter-spacing: .04em; }
.verdict-Correct { color: var(--good); }
.verdict-Partially { color: var(--warn); }
.verdict-Incorrect { color: var(--bad); }

/* ---------- markdown (study plan) ---------- */
.markdown {
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 2rem 2.4rem; box-shadow: var(--shadow-sm); max-width: 74ch;
}
.markdown h1, .markdown h2, .markdown h3 {
  font-family: "Fraunces", serif; font-weight: 400; letter-spacing: -.01em; color: var(--ink);
  line-height: 1.15;
}
.markdown h1 { font-size: 1.9rem; margin: 0 0 1rem; }
.markdown h2 { font-size: 1.45rem; margin: 1.8rem 0 .7rem; padding-bottom: .35rem; border-bottom: 1px solid var(--rule); }
.markdown h3 { font-size: 1.15rem; margin: 1.3rem 0 .5rem; color: var(--gold); }
.markdown p { margin: .6rem 0; color: var(--ink-2); }
.markdown ul, .markdown ol { padding-left: 1.4rem; }
.markdown li { margin: .32rem 0; }
.markdown li::marker { color: var(--gold); }
.markdown strong { color: var(--ink); }
.markdown code { font-family: "Spline Sans Mono", monospace; font-size: .82em; background: var(--paper-3); padding: .08rem .35rem; border-radius: 3px; }

/* ---------- misc ---------- */
.spinner {
  font-family: "Spline Sans Mono", monospace; font-size: .76rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3); padding: .5rem 0;
}
.spinner::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.errorbox {
  background: var(--bad-bg); border: 1px solid #d9b3a8; border-left: 2px solid var(--bad);
  color: var(--bad); padding: .9rem 1.1rem; border-radius: var(--radius); font-size: .9rem;
}

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login-wrap { width: 100%; min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2.6rem 2.4rem 2rem;
  display: flex; flex-direction: column;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.login-logo { width: 168px; height: auto; margin: 0 auto 1.6rem; display: block; }
.login-title {
  font-family: "Fraunces", serif; font-weight: 500; font-size: 2.1rem;
  letter-spacing: -.02em; margin: 0; color: var(--ink);
}
.login-sub {
  font-family: "Spline Sans Mono", monospace; font-size: .66rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--gold); margin: .35rem 0 0;
}
.login-card::after { content: ""; width: 46px; height: 2px; background: var(--gold-2); margin: 1.5rem auto 1.7rem; }
.login-field { text-align: left; display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.login-field span {
  font-family: "Spline Sans Mono", monospace; font-size: .6rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3);
}
.login-field input {
  font-family: "Hanken Grotesk", sans-serif; font-size: .95rem; color: var(--ink);
  padding: .65rem .75rem; width: 100%;
  background: var(--paper); border: 1px solid var(--rule-2); border-radius: var(--radius);
  transition: border-color .2s, box-shadow .2s;
}
.login-field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(156,115,32,.14); }
#login-btn { margin-top: .4rem; padding: .72rem; font-size: .92rem; }
.login-err { color: var(--bad); font-size: .82rem; min-height: 1.1em; margin: .7rem 0 0; }
.login-foot {
  margin: 1.4rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--rule);
  font-size: .72rem; color: var(--ink-3);
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: .5rem 1rem; padding: 1.1rem 1.3rem;
    border-right: none; border-bottom: 1px solid var(--rule);
  }
  .mark-sub, .sidefoot { display: none; }
  .logo-img { max-width: 132px; }
  .nav { flex-direction: row; flex-wrap: wrap; margin: 0 0 0 auto; gap: .2rem; }
  .tab { width: auto; padding: .45rem .7rem; border-left: none; border-bottom: 2px solid transparent; border-radius: var(--radius); }
  .tab.active { border-left: none; border-bottom-color: var(--gold-2); }
  .tab i { display: none; }
  main { padding: 1.8rem 1.3rem 4rem; }
}
