/* =====================================================================
   Engy - app v0.1
   Neutral near-black canvas (like the 099 reference). No gradients.
   Blue is reserved for text, the logo, and the problem diagrams.
   Everything else stays grayscale and quiet.
   ===================================================================== */

:root {
  --bg:        #0b0b0b;
  --panel:     #121212;
  --panel-2:   #171717;
  --line:      #262626;
  --line-2:    #383838;
  --line-3:    #4a4a4a;

  --ink:       #a6c3e6;
  --ink-hi:    #d8e8fc;
  --ink-dim:   #7f92aa;
  --ink-faint: #59657a;
  --blue:      #5c9dff;
  --hot:       #ff5d4a;

  --btn-fill:  #e9e9e9;
  --btn-fill-h:#ffffff;
  --btn-ink:   #0a0a0a;

  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --disp: "Space Grotesk", var(--sans);
  --serif: "IBM Plex Serif", Georgia, serif;

  --rail: 60px;
  --r: 4px;
}

/* softer dark */
[data-theme="dim"] {
  --bg: #15171b; --panel: #1b1e23; --panel-2: #21252b;
  --line: #2d323a; --line-2: #3b414a; --line-3: #4d545e;
  --ink: #b4c8e4; --ink-hi: #dcebfd; --ink-dim: #8496ac; --ink-faint: #616d7e;
  --btn-fill: #e4e6ea; --btn-fill-h: #f4f5f7; --btn-ink: #14171b;
}

/* light */
[data-theme="light"] {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #eef1f5;
  --line: #e2e6ec; --line-2: #cfd6e0; --line-3: #aab4c2;
  --ink: #2b4a70; --ink-hi: #142f52; --ink-dim: #5d6d82; --ink-faint: #93a0b2;
  --blue: #2f6fdb; --hot: #d6432f;
  --btn-fill: #142f52; --btn-fill-h: #0d244a; --btn-ink: #f5f6f8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* the hidden attribute must win over component display rules */
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  transition: background .2s, color .2s;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 2px; }

.var { font-family: var(--disp); font-style: italic; color: var(--ink-hi); }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.02em;
  padding: 0.62rem 1.05rem; border: 1px solid var(--line-2); border-radius: var(--r);
  background: transparent; color: var(--ink);
  display: inline-flex; align-items: center; gap: 0.5ch;
  transition: border-color .15s, background .15s, color .15s, opacity .15s;
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--line-3); color: var(--ink-hi); }
.btn-solid { background: var(--btn-fill); color: var(--btn-ink); border-color: var(--btn-fill); font-weight: 500; }
.btn-solid:hover { background: var(--btn-fill-h); border-color: var(--btn-fill-h); }
.btn-solid:disabled { background: var(--panel-2); color: var(--ink-faint); border-color: var(--line); cursor: not-allowed; }
.btn-danger { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 34%, transparent); }
.btn-danger:hover { border-color: var(--hot); background: color-mix(in srgb, var(--hot) 12%, transparent); }
.btn:disabled { cursor: not-allowed; }

/* =====================================================================
   APP FRAME
   ===================================================================== */
.app { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail); flex: none;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0; position: sticky; top: 0; height: 100vh; background: var(--bg);
}
.rail-logo { display: block; width: 32px; height: 32px; }
.logo-mark { width: 100%; height: 100%; }
.logo-mark rect { fill: var(--blue); }

.rail-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.rail-btn {
  width: 38px; height: 38px; border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--ink-dim);
  display: grid; place-items: center; transition: .15s;
}
.rail-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { color: var(--ink-hi); border-color: var(--line); }

/* signed-in account avatar in the rail - unmistakable at a glance */
#rail-account { margin-bottom: 6px; }
.rail-acct { padding: 0; }
.acct-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--blue) 24%, var(--panel));
  border: 1.5px solid var(--blue); color: var(--ink-hi);
  font-family: var(--mono); font-size: 0.9rem; font-weight: 600;
}
.rail-acct:hover .acct-avatar { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 34%, var(--panel)); }

/* transient top-center toast */

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- topics (borderless; a floating rule below does the dividing) ---------- */
.topics {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  /* top padding balances the stage's top padding below, so the tab row sits
     centered between the top of the screen and the floating divider */
  padding: clamp(1rem, 2.5vw, 1.6rem) clamp(1rem, 3vw, 2rem) 0;
}
.topics-track {
  display: flex; gap: 0.1rem; overflow-x: auto; scrollbar-width: none;
  max-width: 1180px; margin: 0 auto; justify-content: safe center;
}
.topics-track::-webkit-scrollbar { display: none; }
.topic {
  flex: 0 1 auto; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: 0.7rem 0.6rem 0.6rem;
  font-family: var(--mono); font-size: 0.73rem; letter-spacing: 0.003em;
  color: var(--ink-dim); transition: color .15s, border-color .15s; white-space: nowrap;
}
.topic-main { display: inline-flex; align-items: center; gap: 0.5ch; }
.t-ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; }
.topic:hover { color: var(--ink); }
.topic.is-active { color: var(--ink-hi); border-bottom-color: var(--blue); }
.topic.is-active .t-ico { stroke: var(--blue); opacity: 1; }

/* =====================================================================
   STAGE
   ===================================================================== */
.stage {
  flex: 1; width: 100%; max-width: 1180px; margin: 0 auto;
  padding: clamp(1.1rem, 2.5vw, 1.7rem) clamp(1rem, 3vw, 2rem) 4rem;
}
/* item 3 - floating divider under the categories */
.stage-rule { height: 1px; background: var(--line); margin: 0 0 clamp(1.6rem, 3.6vw, 2.6rem); }

/* ---------- question head ---------- */
.q-head { display: flex; align-items: flex-start; gap: 1.1rem; margin-bottom: clamp(1.4rem, 3vw, 2.2rem); }
.difficulty {
  flex: none; margin-top: 0.25rem;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-dim); display: inline-flex; align-items: center; gap: 0.55ch;
}
.diff-meter { display: inline-flex; gap: 2px; }
.diff-meter i { width: 4px; height: 11px; background: var(--line-2); border-radius: 1px; }
.difficulty[data-level="2"] .diff-meter i:nth-child(-n+2) { background: var(--blue); }
.difficulty[data-level="3"] .diff-meter i { background: var(--blue); }
.q-divider { flex: none; width: 1px; align-self: stretch; background: var(--line); }
.q-text {
  margin: 0; font-family: var(--disp); font-weight: 500;
  font-size: clamp(1.15rem, 2.1vw, 1.6rem); line-height: 1.32; letter-spacing: -0.01em;
  color: var(--ink-hi); max-width: 62ch;
}

/* ---------- body: figure + response (item 4: equal heights) ---------- */
.q-body { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: clamp(1rem, 2.5vw, 1.6rem); align-items: stretch; }

.q-figure { margin: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; display: flex; flex-direction: column; }
.fig-cap {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; color: var(--ink-dim);
  padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); min-height: 38px;
}
.fig-stage { padding: 0.4rem; }
#setup-svg, #sol-svg { width: 100%; height: auto; display: block; }

/* SVG diagram classes */
.hatch-line { stroke: var(--ink-faint); stroke-width: 1; }
.wall-edge  { stroke: var(--ink-hi); stroke-width: 1.5; }
.datum      { stroke: var(--line-3); stroke-width: 1; stroke-dasharray: 3 4; }
.beam-box   { stroke: var(--blue); stroke-width: 1.6; fill: none; stroke-linejoin: round; }
.beam-fill  { stroke: none; }
.load-shaft { stroke: var(--ink-hi); stroke-width: 1.6; }
.load-head  { stroke: var(--ink-hi); stroke-width: 1.6; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.dim-line   { stroke: var(--ink-faint); stroke-width: 1; }
.dim-tick   { stroke: var(--ink-faint); stroke-width: 1; }
.annot-lead { stroke: var(--hot); stroke-width: 1.1; }
.annot-dash { stroke: var(--blue); stroke-width: 1; stroke-dasharray: 2 3; }
.node-hot   { fill: var(--hot); }
.svg-label  { font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; fill: var(--ink-dim); }
.svg-label.hi   { fill: var(--ink-hi); }
.svg-label.blue { fill: var(--blue); }
.svg-label.hot  { fill: var(--hot); }
.crack { stroke: var(--hot); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }

/* ---------- response ---------- */
.q-response { display: flex; flex-direction: column; gap: 0.85rem; }
.resp-wrap { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 220px; }
.resp-wrap:focus-within { border-color: var(--line-3); }
#answer {
  width: 100%; border: 0; background: transparent; resize: vertical; flex: 1 1 auto; min-height: 150px;
  color: var(--ink); font-family: var(--sans); font-size: 0.98rem; line-height: 1.6;
  padding: 0.95rem 1rem 0.6rem;
}
#answer:focus { outline: none; }
#answer::placeholder { color: var(--ink-faint); }
.resp-foot { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0.7rem 0.55rem; border-top: 1px solid var(--line); flex: none; }
.counter { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-dim); }
.counter.ok { color: var(--blue); }
.icon-btn {
  display: inline-flex; align-items: center; gap: 0.5ch;
  background: transparent; border: 1px solid transparent; border-radius: var(--r);
  color: var(--ink-dim); font-family: var(--mono); font-size: 0.74rem; padding: 0.3rem 0.5rem; transition: .15s;
}
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--ink-hi); border-color: var(--line); }
.icon-btn.rec { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 40%, transparent); }
.icon-btn.rec svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.resp-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; flex: none; }
.resp-actions-right { display: flex; gap: 0.6rem; }

/* ---------- feedback ---------- */
.feedback { margin-top: clamp(1.6rem, 3.5vw, 2.6rem); border-top: 1px solid var(--line); padding-top: clamp(1.4rem, 3vw, 2rem); scroll-margin-top: 96px; }
.fb-head { display: flex; align-items: baseline; gap: 0.8rem; margin-bottom: 1.2rem; }
.fb-head h2 { margin: 0; font-family: var(--disp); font-weight: 500; font-size: 1.2rem; color: var(--ink-hi); }
.fb-score { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-dim); border: 1px solid var(--line-2); border-radius: 999px; padding: 0.15rem 0.6rem; }
.fb-score.good { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 45%, transparent); }

.fb-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: clamp(1rem, 2.5vw, 1.6rem); align-items: start; }
.checks { list-style: none; margin: 0 0 0.4rem; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.check { display: grid; grid-template-columns: 22px 1fr; gap: 0.7rem; padding: 0.85rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
/* item 5 - SVG marks, perfectly centered */
.check-mark { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px; }
.check-mark svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; display: block; }
.check.pass .check-mark { color: var(--blue); border: 1px solid color-mix(in srgb, var(--blue) 55%, transparent); }
.check.miss .check-mark { color: var(--hot); border: 1px solid color-mix(in srgb, var(--hot) 55%, transparent); }
.check.note .check-mark { color: var(--ink-dim); border: 1px solid var(--line-2); }
.check b { display: block; color: var(--ink-hi); font-family: var(--disp); font-weight: 500; font-size: 0.95rem; margin-bottom: 0.15rem; }
.check .c-body { color: var(--ink-dim); font-size: 0.87rem; }
.fb-prose { margin: 1.1rem 0 0; color: var(--ink); font-size: 0.95rem; max-width: 52ch; }
.fb-prose b { color: var(--ink-hi); font-weight: 500; }

.fb-figure { margin: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.fig-toggle { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; }
.figv { background: transparent; border: 0; border-right: 1px solid var(--line-2); color: var(--ink-dim); font-family: var(--mono); font-size: 0.68rem; padding: 0.3rem 0.7rem; transition: .15s; }
.figv:last-child { border-right: 0; }
.figv.is-on { background: var(--btn-fill); color: var(--btn-ink); }

/* item 7 - legend + equations */
.legend { border-top: 1px solid var(--line); padding: 0.85rem 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; }
.leg-scale { display: flex; align-items: center; gap: 0.6rem; font-family: var(--mono); font-size: 0.68rem; color: var(--ink-dim); }
.leg-bar { flex: 1; height: 8px; border-radius: 2px; }
.leg-bar.stress { background: linear-gradient(90deg, #5c9dff, #5ec8ff 35%, #ffb03a 72%, #ff5d4a); }
.leg-bar.defl   { background: linear-gradient(90deg, #22334c, #5ec8ff); }
.leg-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.leg-note { font-family: var(--mono); font-size: 0.68rem; color: var(--ink-dim); }
.eq { font-family: var(--serif); font-style: italic; font-size: 1.06rem; color: var(--ink-hi); display: inline-flex; align-items: center; gap: 0.32ch; white-space: nowrap; }
.eq sub { font-style: normal; font-size: 0.64em; align-self: flex-end; margin: 0 0.05ch 0.15em -0.1ch; }
.eq sup { font-size: 0.66em; }
.frac { display: inline-flex; flex-direction: column; text-align: center; margin: 0 0.18ch; }
.frac .fr-n { padding: 0 0.4ch 0.06em; }
.frac .fr-d { padding: 0.06em 0.4ch 0; border-top: 1px solid currentColor; }

/* ---------- empty state ---------- */
.empty { max-width: 44ch; margin: clamp(3rem, 8vw, 6rem) auto; text-align: center; }
.empty-glyph { width: 46px; height: 46px; fill: none; stroke: var(--line-3); stroke-width: 2; stroke-linecap: round; margin-bottom: 1.2rem; }
.empty h2 { font-family: var(--disp); font-weight: 500; color: var(--ink-hi); font-size: 1.4rem; margin: 0 0 0.7rem; }
.empty p { color: var(--ink-dim); margin: 0 0 1.6rem; }

/* =====================================================================
   MODALS
   ===================================================================== */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1.2rem; }
.modal[hidden] { display: none; }
.modal-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.62); }
.modal-card {
  position: relative; width: 100%; max-width: 460px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 1.5rem; max-height: 88vh; overflow-y: auto; animation: modal-in .18s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.3rem; }
.modal-head h2 { margin: 0; font-family: var(--disp); font-weight: 500; font-size: 1.25rem; color: var(--ink-hi); }
.modal-x { background: transparent; border: 0; color: var(--ink-dim); font-size: 1rem; padding: 0.3rem 0.5rem; border-radius: var(--r); }
.modal-x:hover { color: var(--ink-hi); }
.modal-sub { color: var(--ink-dim); font-size: 0.9rem; margin: -0.6rem 0 1.2rem; }

.set-row { padding: 1rem 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; padding-top: 0; }
.set-row label, .set-label, .field label { display: block; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 0.6rem; }
.field { margin-bottom: 0.9rem; }
#username, #note, #note-email, #su-email, #su-pass, #su-pass2, #su-user {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r);
  color: var(--ink); font-family: var(--mono); font-size: 0.88rem; padding: 0.65rem 0.75rem;
}
#note { font-family: var(--sans); font-size: 0.95rem; resize: vertical; }
#username:focus, #note:focus, #su-email:focus, #su-pass:focus, #su-pass2:focus, #su-user:focus { outline: none; border-color: var(--blue); }

.account { display: flex; align-items: flex-start; gap: 0.8rem; }
.account-badge { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--line-2); display: grid; place-items: center; font-family: var(--mono); font-size: 0.9rem; color: var(--ink-hi); }
.account-info b { color: var(--ink-hi); font-family: var(--disp); font-weight: 500; display: block; }
.account-info span { color: var(--ink-dim); font-size: 0.82rem; }
.account-info .btn { margin-top: 0.7rem; }

.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; }
.seg { background: transparent; border: 0; border-right: 1px solid var(--line-2); color: var(--ink-dim); font-family: var(--mono); font-size: 0.76rem; padding: 0.42rem 0.85rem; transition: .15s; }
.seg:last-child { border-right: 0; }
.seg.is-on { background: var(--btn-fill); color: var(--btn-ink); }

.plan { border: 1px solid var(--line); border-radius: var(--r); padding: 0.9rem; background: var(--bg); }
.plan-opts { display: flex; flex-direction: column; gap: 0.5rem; }
.plan-opts .plan-btn, .plan-opts .btn { width: 100%; justify-content: center; }
.plan-note { font-family: var(--mono); font-size: 0.74rem; margin: 0.6rem 0 0; }
.plan-note:empty { display: none; }
.plan-tag { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; color: var(--blue); border: 1px solid color-mix(in srgb, var(--blue) 45%, transparent); border-radius: 999px; padding: 0.1rem 0.55rem; }
.plan p { color: var(--ink-dim); font-size: 0.85rem; margin: 0.7rem 0 0.9rem; }

.set-actions { display: flex; gap: 0.6rem; margin-top: 1.3rem; padding-top: 1.3rem; border-top: 1px solid var(--line); }
.set-actions:empty { display: none; }

.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-top: 0.9rem; }
.note-status { font-family: var(--mono); font-size: 0.75rem; color: var(--blue); }

/* sign-in gate - covers the app when auth is on and nobody is logged in (below modals) */
.auth-gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1.4rem; background: var(--bg); }
.auth-gate[hidden] { display: none; }
.auth-gate-card { max-width: 600px; text-align: center; }
.gate-brand { display: inline-flex; align-items: center; gap: 0.55rem; margin-bottom: 2rem; }
.gate-brand svg { width: 30px; height: 30px; }
.gate-brand svg rect { fill: var(--blue); }
.gate-brand b { font-family: var(--disp); font-weight: 700; font-size: 1.2rem; color: var(--ink-hi); letter-spacing: -0.02em; }
.auth-gate-card h1 { font-family: var(--disp); font-weight: 600; font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.02em; color: var(--ink-hi); margin: 0 0 0.7rem; }
.auth-gate-card > p { color: var(--ink-dim); margin: 0 0 1.8rem; }
.gate-actions { display: flex; gap: 0.7rem; justify-content: center; }
.gate-back { display: inline-block; margin-top: 1.7rem; font-family: var(--mono); font-size: 0.78rem; color: var(--ink-faint); }
.gate-back:hover { color: var(--ink-dim); }

/* full-screen, must-dismiss overlay (email-confirmation outcomes) */
.fs-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 1.4rem; background: color-mix(in srgb, var(--bg) 82%, #000); backdrop-filter: blur(4px); }
.fs-overlay[hidden] { display: none; }
.fs-card { width: 100%; max-width: 440px; text-align: center; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 2.4rem 2rem; box-shadow: 0 24px 70px rgba(0,0,0,0.5); animation: modal-in .2s ease; }
.fs-mark { width: 46px; height: 46px; margin: 0 auto 1.1rem; border-radius: 50%; background: color-mix(in srgb, var(--blue) 20%, var(--panel)); border: 1.5px solid var(--blue); position: relative; }
.fs-mark::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--blue); font-size: 1.25rem; }
.fs-mark.is-warn { background: color-mix(in srgb, var(--hot) 16%, var(--panel)); border-color: var(--hot); }
.fs-mark.is-warn::after { content: "!"; color: var(--hot); font-weight: 700; }
.fs-title { margin: 0 0 0.55rem; font-family: var(--disp); font-weight: 500; font-size: 1.35rem; line-height: 1.25; color: var(--ink-hi); }
.fs-msg { margin: 0 0 1.7rem; color: var(--ink-dim); font-size: 0.95rem; line-height: 1.5; }
.fs-msg:empty { display: none; }
.fs-btn { min-width: 170px; justify-content: center; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 820px) {
  .q-body, .fb-grid { grid-template-columns: 1fr; }
  .q-body { align-items: start; }
  .fb-grid { gap: 1.2rem; }
  .resp-wrap { min-height: 200px; }
}

@media (max-width: 640px) {
  .rail {
    position: sticky; width: 100%; height: auto; flex-direction: row;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; top: 0; z-index: 30;
  }
  .rail-logo { width: 28px; height: 28px; }
  .rail-bottom { margin-top: 0; margin-left: auto; flex-direction: row; }
  .app { flex-direction: column; }
  .topics { top: 45px; }
  .q-head { flex-direction: column; gap: 0.7rem; }
  .q-divider { display: none; }
  .resp-actions { flex-direction: column; align-items: stretch; }
  .resp-actions-right { justify-content: space-between; }
  .resp-actions .btn { flex: 1; justify-content: center; }
}

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

/* ===================== v0.2 data-driven additions ===================== */
.difficulty[data-level="1"] .diff-meter i:nth-child(1) { background: var(--blue); }

.topic-n { font-size: 0.62rem; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 999px; padding: 0.02rem 0.36rem; }
.topic.is-active .topic-n { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 40%, transparent); }

.qnav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: clamp(1.2rem, 3vw, 2rem); }
.qnav-loc { font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.04em; color: var(--ink-dim); text-transform: uppercase; }
.qnav-ctrl { display: flex; align-items: center; gap: 0.7rem; }
.qcount { font-family: var(--mono); font-size: 0.74rem; color: var(--ink-dim); min-width: 4ch; text-align: center; }
.navbtn { font-family: var(--mono); font-size: 0.74rem; color: var(--ink); background: transparent; border: 1px solid var(--line-2); border-radius: var(--r); padding: 0.4rem 0.7rem; transition: border-color .15s, color .15s; }
.navbtn:hover { border-color: var(--line-3); color: var(--ink-hi); }

.fig-cap-note { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; color: var(--ink-dim); }

.leg-item { display: inline-flex; align-items: center; gap: 0.5ch; font-family: var(--mono); font-size: 0.68rem; color: var(--ink-dim); margin-right: 1rem; }
.leg-sw { width: 22px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---- jump-to-number ---- */
.qcount { display: inline-flex; align-items: baseline; gap: 0; }
.qjump { font: inherit; color: var(--ink-hi); background: transparent; border: none; padding: 0 .15ch; cursor: pointer; border-bottom: 1px dashed var(--line-3); }
.qjump:hover { color: var(--blue); border-bottom-color: var(--blue); }
.qsep { color: var(--ink-dim); }
.qjump-in { font: inherit; width: 4.5ch; text-align: center; color: var(--ink-hi); background: var(--panel-2); border: 1px solid var(--blue); border-radius: 3px; padding: 0 .2ch; -moz-appearance: textfield; }
.qjump-in::-webkit-outer-spin-button, .qjump-in::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.navbtn-grid { display: inline-flex; align-items: center; gap: 0.55ch; }
.navbtn-grid svg { width: 13px; height: 13px; fill: currentColor; opacity: .75; }

/* ---- persistent key-relations panel below the solution figure ---- */
.fig-relations { margin-top: 0.7rem; border-top: 1px solid var(--line); padding: 0.7rem 0.9rem 0.35rem; }
.rel-cap { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.14em; color: var(--ink-dim); display: block; margin-bottom: 0.25rem; }
.rel-stage { max-width: 460px; margin: 0 auto; }
.rel-stage svg { width: 100%; height: auto; display: block; }

/* ---- view-all grid ---- */
.gridview { padding: clamp(1rem, 3vw, 2rem) 0 4rem; }
.grid-head { display: flex; align-items: center; gap: 0.8rem 1.4rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.grid-title { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; }
.grid-title h2 { font-size: 1.1rem; color: var(--ink-hi); margin: 0; letter-spacing: -0.01em; }
.grid-sub { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-dim); }
.grid-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-left: auto; }
.gleg { display: inline-flex; align-items: center; gap: 0.45ch; font-family: var(--mono); font-size: 0.7rem; color: var(--ink-dim); }
.gsw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; background: var(--tint, var(--line-2)); }
.grid-close { flex: none; }
.grid-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(188px, 1fr)); gap: 0.8rem; }
.gcard { text-align: left; cursor: pointer; border: 1px solid var(--line); border-left: 3px solid var(--tint, var(--line-2)); border-radius: 10px; overflow: hidden; padding: 0; display: flex; flex-direction: column; color: inherit; font: inherit; background: var(--panel); background: color-mix(in srgb, var(--tint, transparent) 9%, var(--panel)); transition: border-color .15s, transform .1s; }
.gcard:hover { border-color: var(--line-3); transform: translateY(-1px); }
.gcard-fig { background: var(--panel-2); border-bottom: 1px solid var(--line); min-height: 104px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gcard-fig svg { width: 100%; height: auto; display: block; }
.gcard-meta { padding: 0.5rem 0.6rem 0.62rem; display: flex; gap: 0.55ch; align-items: baseline; }
.gcard-n { font-family: var(--mono); font-size: 0.68rem; color: var(--ink-faint); flex: none; }
.gcard-desc { font-size: 0.8rem; line-height: 1.28; color: var(--ink); }
.t-none { --tint: #3d434c; }
.t-zero { --tint: var(--hot); }
.t-partial { --tint: #ffb03a; }
.t-full { --tint: #4fc98f; }

/* ---- subscription / auth ---- */
.upsell {
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  border: 1px solid color-mix(in srgb, var(--blue) 34%, var(--line));
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
  border-radius: 10px; padding: 0.7rem 0.9rem; margin: 0 0 clamp(1rem, 2.5vw, 1.7rem);
}
.upsell-text { font-size: 0.9rem; color: var(--ink); }
.upsell-cta { margin-left: auto; }
.btn-sm { padding: 0.42rem 0.85rem; font-size: 0.8rem; }
.plan-tag.on { color: #4fc98f; border-color: color-mix(in srgb, #4fc98f 45%, transparent); }
.auth-switch { margin: 0.95rem 0 0; font-size: 0.82rem; color: var(--ink-dim); }
.auth-resend { margin: 0.95rem 0 0; font-size: 0.82rem; color: var(--ink-dim); }
.linkbtn { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.linkbtn:hover { color: var(--ink-hi); }
.linkbtn:disabled { color: var(--ink-faint); cursor: not-allowed; text-decoration: none; }

/* ---- site footer (legal links) ---- */
.site-footer {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  margin-top: auto; padding: 20px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint);
}
.site-footer nav { display: flex; gap: 16px; }
.site-footer a { color: var(--ink-dim); }
.site-footer a:hover { color: var(--blue); }

/* ---- locked grid cards (free users) ---- */
.gcard-locked { border-left-color: var(--line-2); }
.gcard-locked:hover { border-color: color-mix(in srgb, var(--blue) 45%, var(--line-3)); }
.gcard-fig-lock { background: repeating-linear-gradient(45deg, var(--panel-2), var(--panel-2) 7px, var(--panel) 7px, var(--panel) 14px); }
.gcard-locked .gcard-desc { color: var(--ink-dim); }
.lock-ico { width: 24px; height: 24px; fill: none; stroke: var(--ink-faint); stroke-width: 1.7; stroke-linecap: round; }
.gsw-lock { width: auto; background: none; display: inline-flex; align-items: center; }
.gsw-lock .lock-ico { width: 12px; height: 12px; stroke-width: 2.2; }
