/* Tokens, reset, and the shared pieces: matrices, fractions, buttons, cards. */

:root {
  --bg: #0b0d12;
  --bg2: #0f1218;
  --card: #151a23;
  --card2: #1a202b;
  --line: #262e3c;
  --ink: #e9edf4;
  --dim: #8e9aad;
  --gold: #f2b544;
  --gold-2: #ffd27a;
  --good: #4fd39c;
  --bad: #ff6f6f;
  --a: #6aa9ff;
  --b: #f2b544;
  --c: #b78bff;
  --d: #4fd39c;
  --e: #ff8fab;
  --shadow: 0 12px 34px rgba(0, 0, 0, .45);
  --r: 16px;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-dis: "Space Grotesk", var(--font-ui);
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --bg2: #eceff6;
  --card: #ffffff;
  --card2: #f5f7fb;
  --line: #dde3ed;
  --ink: #121722;
  --dim: #5d6879;
  --gold: #c98a00;
  --gold-2: #a97400;
  --good: #12996a;
  --bad: #d9453f;
  --a: #2f6fd0;
  --b: #c98a00;
  --c: #7a4fd6;
  --d: #12996a;
  --e: #d4527a;
  --shadow: 0 10px 26px rgba(20, 30, 50, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background:
    radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--gold) 9%, transparent), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-dis); font-weight: 600; letter-spacing: -.015em; margin: 0; }
p { margin: 0 0 10px; }
b { font-weight: 650; }
sup { font-size: .72em; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--card2); padding: 1px 5px; border-radius: 5px; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.tiny { font-size: 13px; line-height: 1.5; }
.dim { color: var(--dim); }
.foot { color: var(--dim); font-size: 12px; margin: 26px 0 0; text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.sechead { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--dim); margin: 24px 0 10px; font-family: var(--font-ui); font-weight: 600; }

/* --- top bar ----------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 17px; text-align: center; }
.icon {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 17px; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.icon:active { transform: scale(.94); }

/* --- cards and buttons -------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin: 14px 0; box-shadow: var(--shadow);
}
.card.soft { background: var(--card2); box-shadow: none; }
.card h3 { font-size: 15px; margin-bottom: 8px; }

.btn {
  appearance: none; border: 1px solid var(--line); border-radius: 13px;
  background: var(--card2); color: var(--ink);
  font: 600 15px/1 var(--font-ui); padding: 15px 18px; cursor: pointer; width: 100%;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #201704; border-color: transparent; font-weight: 700;
}
:root[data-theme="light"] .btn.primary { color: #fff; background: linear-gradient(180deg, #d99a12, #b57a00); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); background: transparent; }
.btn.small { padding: 11px 14px; font-size: 14px; width: auto; }
.btn.big { padding: 20px; font-size: 17px; }
.mini {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  border-radius: 9px; padding: 5px 10px; font: 600 12px/1 var(--font-ui); cursor: pointer;
}

/* --- matrices ----------------------------------------------------------- */
.matrix, .minput { display: inline-flex; align-items: stretch; margin: 8px 10px 8px 0; vertical-align: middle; }
.mlabel { align-self: center; margin-right: 8px; font-family: var(--font-dis); font-size: 15px; color: var(--dim); white-space: nowrap; }
.mlabel.big { font-size: 16px; color: var(--ink); }
.brk {
  width: 9px; border: 2px solid color-mix(in srgb, var(--dim) 60%, transparent);
  border-right: 0; border-radius: 4px 0 0 4px;
}
.brk.r { border: 2px solid color-mix(in srgb, var(--dim) 60%, transparent); border-left: 0; border-radius: 0 4px 4px 0; }
.grid {
  display: grid; grid-template-columns: repeat(var(--c), minmax(30px, auto));
  gap: 6px 14px; padding: 8px 10px; align-items: center; justify-items: center;
}
.cell { font-family: var(--font-mono); font-size: 15px; font-weight: 500; white-space: nowrap; }
.cell.hi { color: var(--gold); }
.cell.bar { border-left: 1px dashed var(--line); padding-left: 14px; margin-left: -6px; }

.num { font-variant-numeric: tabular-nums; }
.num.frac { display: inline-flex; align-items: center; gap: 1px; }
.frac .sgn { margin-right: 1px; }
.frac .stack { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.05; font-size: .8em; }
.frac .stack b, .frac .stack i { font-weight: 500; font-style: normal; }
.frac .stack u { display: block; width: 100%; min-width: 9px; height: 1px; background: currentColor; text-decoration: none; margin: 1px 0; }

/* --- matrix input ------------------------------------------------------- */
.grid.in { gap: 8px; }
.cin {
  width: 100%; min-width: 0; background: var(--bg2); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 6px;
  font: 500 16px/1 var(--font-mono); text-align: center; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.grid.in .cin { width: 66px; }
.cin:focus, .cin.active { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 20%, transparent); }
.cin.bad { border-color: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }
.cin[disabled] { opacity: .7; }

.fields { display: flex; flex-wrap: wrap; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 130px; }
.field-sm { flex: 0 1 118px; }
.field-lg { flex: 1 1 100%; }
.flab { font-size: 13px; color: var(--dim); font-weight: 600; }
.flab i { font-style: normal; opacity: .7; margin-left: 6px; font-weight: 400; }
.field .cin { text-align: left; padding-left: 12px; }

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