/* Saddle: a Poincaré disk on periwinkle paper, with a desk calculator */
@font-face { font-family: "Young Serif"; font-display: swap; src: url(../fonts/young-serif-latin-400-normal.woff2) format("woff2"); }

:root {
  --bg: #ECEEF6;
  --card: #FFFFFF;
  --ink: #1F2A55;
  --muted: #5E6789;
  --line: #CED3E6;
  --edge: #2F3E8F;
  --fill: #7C9EF2;
  --gold: #E3A02B;
  --good: #2B8A3E;
  --bad: #C2353B;
  --key: #F4F5FA;
  --display: "Young Serif", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12162A; --card: #1C2240; --ink: #E4E8F7; --muted: #9BA3C4; --line: #2E3560; --edge: #9DB2FF; --fill: #5C7BD6; --key: #252C50; --good: #5BC07A; --bad: #FF7A7F; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); line-height: 1.45; min-height: 100vh; }
a { color: inherit; }
button, input { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 14px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: 0.95rem; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.icon-btn:hover { background: var(--card); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 10px; }
h1 { font-family: var(--display); font-weight: 400; font-size: 2.2rem; margin: 0; line-height: 1; }
.sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.cols { display: grid; grid-template-columns: 1fr; grid-template-areas: "q" "c" "a"; gap: 14px; }
.main { grid-area: q; min-width: 0; }
.calc { grid-area: c; }
.below { grid-area: a; min-width: 0; }
.below .answer { margin-top: 0; }
@media (min-width: 820px) {
  .cols { grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "q c" "a c"; align-items: start; }
  .calc { position: sticky; top: 12px; }
}
.question { font-family: var(--display); font-size: 1.35rem; line-height: 1.35; margin: 0 0 12px; }
.disk-wrap { display: flex; justify-content: center; background: var(--card); border-radius: 18px; padding: 10px; box-shadow: 0 1px 0 var(--line); }
.disk { width: min(100%, 360px); aspect-ratio: 1; }
.disk .rim { fill: var(--bg); stroke: var(--edge); stroke-width: 1.6; }
.disk .bgline { fill: none; stroke: var(--line); stroke-width: 0.8; }
.disk .tri { fill: var(--fill); fill-opacity: .18; stroke: none; }
.disk .tri.shade { fill-opacity: .4; }
.disk .side { fill: none; stroke: var(--edge); stroke-width: 2.2; stroke-linejoin: round; }
.disk .side.dash { stroke-dasharray: 4 3; }
.disk .vtx { fill: var(--edge); }
.disk .lbl { fill: var(--ink); font: 600 9px var(--ui); text-anchor: middle; dominant-baseline: middle; }
.disk .lbl.q { fill: var(--gold); font-weight: 800; font-size: 11px; }
.disk .rt { fill: none; stroke: var(--edge); stroke-width: 1.2; }

.answer { margin-top: 14px; background: var(--card); border-radius: 18px; padding: 14px; box-shadow: 0 1px 0 var(--line); }
.ans-label { display: block; font-weight: 700; margin-bottom: 8px; }
.ans-label span { color: var(--muted); font-weight: 400; font-size: 0.9rem; }
.ans-row { display: flex; gap: 8px; align-items: center; }
.ans-row input { flex: 1; min-width: 0; font-size: 1.4rem; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); font-variant-numeric: tabular-nums; }
.unit { font-size: 1.3rem; color: var(--muted); min-width: 0.6em; }
.go { border: 0; border-radius: 14px; padding: 13px 18px; background: var(--ink); color: var(--card); font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.go.wide { width: 100%; }
.go:disabled { opacity: .45; cursor: default; }
.tries { display: flex; gap: 6px; margin: 10px 0 0; }
.tries i { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); display: inline-block; }
.tries i.used { background: var(--bad); }
.tries i.won { background: var(--good); }
.feedback { margin: 8px 0 0; min-height: 1.3em; }
.feedback.bad { color: var(--bad); } .feedback.good { color: var(--good); font-weight: 700; }
.tool { margin-top: 10px; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 9px 16px; font-weight: 700; cursor: pointer; }
.tool.small { margin: 0; padding: 7px 12px; font-size: 0.9rem; }

/* calculator */
.calc { background: var(--card); border-radius: 18px; padding: 12px; box-shadow: 0 1px 0 var(--line); }
.calc-top { background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.calc-in { width: 100%; border: 0; background: transparent; font: 1rem ui-monospace, Menlo, Consolas, monospace; padding: 2px 0; }
.calc-in:focus { outline: none; }
.calc-out { margin: 2px 0 0; text-align: right; font: 600 1.5rem ui-monospace, Menlo, Consolas, monospace; min-height: 1.4em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.calc-out.err { color: var(--bad); font-size: 1rem; font-family: var(--ui); }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-top: 10px; }
.keys button { border: 0; border-radius: 9px; background: var(--key); padding: 9px 0; font-size: 0.9rem; font-weight: 600; cursor: pointer; touch-action: manipulation; }
.keys button.fn { font-size: 0.78rem; color: var(--edge); }
.keys button.num { font-size: 1.05rem; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); }
.keys button.eq { background: var(--ink); color: var(--card); }
.keys button.op { color: var(--gold); font-size: 1.1rem; }
.calc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.mode { border: 0; border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 0.8rem; background: var(--key); cursor: pointer; letter-spacing: .04em; }

.card { background: var(--card); border-radius: 20px; padding: 20px 18px; box-shadow: 0 1px 0 var(--line); }
.done { margin-top: 14px; }
.kicker { margin: 0; color: var(--muted); font-weight: 600; }
.big { font-family: var(--display); font-size: 2.2rem; line-height: 1.1; margin: 6px 0 6px; }
.res-line { margin: 0 0 14px; }
.fine { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 10px 0 0; }

/* ads */
.ad-inline { margin-top: 26px; }
.ad-slot { display: block; margin: 0 auto; overflow: hidden; }
.ad-banner { width: 100%; max-width: 728px; min-height: 100px; }
.ad-slot.placeholder { border: 1.5px dashed var(--line); border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; }
.ad-slot.placeholder::before { content: "Ad space " attr(data-size); }
.ad-slot.collapsed { min-height: 0; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-label { font-size: 11px; color: var(--muted); text-align: center; margin: 0 0 4px; }

.foot { display: flex; justify-content: center; gap: 22px; padding: 26px 0 40px; color: var(--muted); font-size: 0.9rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dlg { border: 0; border-radius: 16px; padding: 22px; width: min(460px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
.dlg::backdrop { background: rgba(10, 14, 30, .5); }
.dlg h2 { font-family: var(--display); font-weight: 400; margin: 0 0 10px; font-size: 1.6rem; }
.dlg p { color: var(--muted); }
.dlg .x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--muted); width: 40px; height: 40px; }
.sheet { margin: 0; display: grid; gap: 8px; }
.sheet dt { font-weight: 700; font-size: 0.9rem; }
.sheet dd { margin: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88rem; background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; background: var(--bg); border-radius: 10px; padding: 10px; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
