@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #fff8f1; --card: #fff; --panel: #f8f9fa; --line: #e2e7ee;
  --ink: #212529; --title: #1f2937; --muted: #566372; --blue: #0d6efd;
  --soft-blue: #e8f0ff; --shadow: #5f432b0d;
}
:root.dark {
  color-scheme: dark;
  --bg: #171a20; --card: #222831; --panel: #1d222a; --line: #424c5b;
  --ink: #f1f4f8; --title: #fff; --muted: #bec8d5; --blue: #80afff;
  --soft-blue: #283e60; --shadow: #0003;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 Prompt, "Thonburi", system-ui, sans-serif; }
main { width: min(1080px, calc(100% - 32px)); margin: auto; padding-bottom: 48px; }
.topbar { max-width: 1320px; margin: auto; padding: 13px 12px; display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; gap: 12px; align-items: center; color: var(--title); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-weight: 700; }
.brand small { color: var(--muted); font-size: 13px; }
.brand-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 13px; color: white; background: #ed8727; font: 700 30px/1 system-ui; }
.home-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); color: var(--ink); background: var(--card); text-decoration: none; border-radius: 13px; font-size: 25px; line-height: 1; }
.hero { text-align: center; margin: 6px 0 8px; color: var(--title); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.3; font-weight: 700; }
.hero p { padding-top: 7px; font-size: 16px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 15px; }
.searchbox { position: relative; flex: 1; min-width: 0; }
.searchbox span { position: absolute; left: 13px; top: 6px; color: var(--muted); font-size: 23px; pointer-events: none; }
.searchbox input[type=search] { padding-left: 40px; }
input, select, button { font: inherit; border-radius: 11px; }
input:not([type=checkbox]), select { width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 7px 13px; }
#settings-button { border-color: var(--muted); background: transparent; color: var(--muted); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.settings { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 12px; margin-bottom: 15px; display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; }
.settings label, .fields label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.settings .check { display: flex; align-items: center; min-height: 46px; }
#categories, #siblings { display: flex; gap: 8px; }
#categories { flex-wrap: wrap; margin: 0 0 30px; }
.chip { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 13px; font-weight: 600; padding: 7px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); text-decoration: none; }
.chip small { color: var(--muted); }
.chip[aria-pressed=true] { background: #0d6efd; border-color: #0d6efd; color: white; }
.chip[aria-pressed=true] small { color: #e9f0ff; }
.group { margin-bottom: 21px; --accent: #0d6efd; }
.group h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 17px; font-weight: 700; }
.icon { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: white; font: 500 21px/1 system-ui; }
.group h2 .icon { width: 30px; height: 30px; border-radius: 9px; font-size: 17px; }
.card-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; padding: 0; margin: 0; list-style: none; }
.card a { display: flex; align-items: flex-start; gap: 12px; height: 100%; min-height: 89px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: inherit; text-decoration: none; }
.card a:hover { border-color: var(--accent); box-shadow: 0 5px 16px var(--shadow); }
.card strong { display: block; line-height: 1.32; font-size: 15px; font-weight: 700; }
.card small { color: var(--muted); font-size: 12.5px; line-height: 1.42; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.breadcrumb { display: flex; gap: 8px; margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.breadcrumb a { color: var(--blue); font-weight: 600; text-decoration: none; }
#siblings { overflow-x: auto; padding: 0 1px 9px; margin-bottom: 0; }
.chip[aria-current=page] { color: var(--blue); background: var(--soft-blue); border-color: var(--blue); }
.tool-card { background: var(--card); padding: 22px; border-radius: 20px; box-shadow: 0 8px 28px var(--shadow); }
.tool-heading { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.tool-heading .icon { width: 48px; height: 48px; }
.tool-heading h2 { font-size: 20px; font-weight: 700; line-height: 1.3; }
.tool-title { flex: 1 1 13rem; min-width: 0; }
.tool-title p { font-size: 13px; color: var(--muted); margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { padding: 4px 9px; font-size: 12.5px; }
.actions button:first-child { color: var(--blue); border-color: var(--blue); }
.formula-chip { display: inline-block; margin: 11px 0 17px; padding: 5px 10px; border-radius: 8px; background: var(--soft-blue); color: var(--blue); font-size: 13px; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 14px; align-items: start; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 15px; }
.panel + .panel { margin-top: 12px; }
.panel h3 { font-size: 14px; margin-bottom: 10px; font-weight: 700; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin: 0 0 12px; }
.panel button[type=submit] { color: white; background: #0d6efd; border-color: #0d6efd; }
.panel-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.panel-title h3 { margin: 0; }
.panel-title button { padding: 4px 9px; font-size: 12px; }
output { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,125px),1fr)); gap: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.result-tile { padding: 9px 11px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; }
.result-tile small, .result-tile strong { display: block; }
.result-tile small { color: var(--muted); font-size: 12px; }
.result-tile:first-child { border-color: var(--blue); }
.result-message { grid-column: 1/-1; }
canvas { display: block; width: 100%; height: auto; background: #f8f9fa; border-radius: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
@media(max-width: 980px) { .card-grid { grid-template-columns: repeat(3,minmax(0,1fr)); } }
@media(max-width: 740px) { .card-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } .tool-grid { grid-template-columns: minmax(0,1fr); } }
@media(max-width: 440px) { .card-grid { grid-template-columns: 1fr; } .tool-card { padding: 13px; } .hero p { font-size: 13px; } }
#settings-button { min-width: 94px; }
#categories .chip { font-size: 14px; padding-inline: 15px; }
output { grid-template-columns: repeat(auto-fit,minmax(min(100%,150px),1fr)); }
.tool-heading h2:focus-visible { width: fit-content; }
@media(max-width:440px) { #settings-button { min-width: 0; } }
.ratio-modes, .ratio-fields .full-field { grid-column: 1 / -1; }
.ratio-modes { display:flex; flex-wrap:wrap; gap:3px; margin:0; border:0; padding:4px; background:color-mix(in srgb,var(--line) 55%,var(--panel)); border-radius:12px; }
.ratio-modes label { position:relative; flex:1 0 auto; color:var(--muted); text-align:center; cursor:pointer; }
.ratio-modes input { position:absolute; opacity:0; inset:0; width:100%; margin:0; cursor:pointer; }
.ratio-modes span { padding:7px 9px; border-radius:9px; }
.ratio-modes input:checked + span { background:var(--card); color:var(--blue); box-shadow:0 1px 5px var(--shadow); }
.ratio-modes input:focus-visible + span { outline:2px solid var(--blue); }
.ratio-steps:empty { display:none; }
#ratio-form .tool-grid > div .panel:last-child { margin-top:14px; }
.mode-values { grid-column:1/-1; margin:0; }
.fields > .full-field { grid-column:1/-1; }
.visual-caption { padding: 7px 2px 0; color: var(--muted); font-size: 12px; }
.visual-panel canvas { aspect-ratio: auto; max-height: none; }
.media-scroll { max-width: 100%; overflow: auto; }
.media-title { font-weight: 650; margin: 0 0 8px; }
.reference-media:has(canvas),canvas + .reference-media:not([hidden]) { margin-top: 10px; }
.reference-media button { font-size: .88rem; }
.media-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.media-table caption { text-align: left; padding: 0 0 8px; font-weight: 650; }
.media-table th,.media-table td { border: 1px solid var(--line); padding: .32rem .5rem; text-align: center; }
.media-table thead th,.media-table tbody th { background: var(--soft-blue); }
.media-table button { background: transparent; border: 0; padding: .2rem .32rem; white-space: nowrap; }
.media-table td.media-mark,.media-table th.media-mark,.media-mark { background: #a8c7fa; color: #12305b; }
.media-table button[aria-current] { color: var(--blue); font-weight: 700; }
.pascal-media { max-height: 430px; }
.pascal-row { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; min-width: max-content; }
.pascal-row button { min-width: 34px; padding: 3px 5px; }
.formula-cards { display: grid; gap: 8px; }
.formula-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 5px; }
.formula-card h4 { margin: 0; }
.formula-card code { white-space: normal; overflow-wrap: anywhere; font-size: 1rem; color: var(--blue); }
.formula-card button { justify-self: start; }
.calc-history { display: grid; gap: 6px; }
.calc-history button { text-align: start; overflow-wrap:anywhere; }
.calculator-keys { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 5px; margin-bottom: 12px; }
.calculator-keys button { padding: 5px 2px; }
.calendar-media-nav { margin-bottom: 8px; }
.bit-strip { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.bit { display: grid; text-align: center; min-width: 26px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.bit.on { background: var(--soft-blue); color: var(--blue); }
.bit small { font-size: .75rem; }
.prime-grid { display: grid; grid-template-columns: repeat(10,minmax(0,1fr)); gap: 3px; }
.prime-cell { border: 1px solid var(--line); border-radius: 3px; text-align: center; padding: 2px; background: var(--card); font-size: .8rem; overflow: hidden; }
.prime-cell.on { background: #d8f0e2; color: #175b3e; }
.prime-cell.selected { outline: 2px solid var(--blue); z-index:1; }

.tool-grid > div, .reference-media { min-width: 0; }

.lesson-picker { display: grid; grid-template-columns: 150px minmax(0,1fr); align-items: start; gap: 14px; padding: 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.lesson-picker label { display: grid; gap: 7px; font-weight: 650; }
#lesson-start h2 { font-size: 15px; margin-bottom: 8px; }
.lesson-links { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
.lesson-links a { display: grid; gap: 3px; align-content: start; min-height: 58px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); text-decoration: none; }
.lesson-links a:hover { border-color: var(--blue); }
.lesson-links small { color: var(--muted); line-height: 1.4; }
.lesson-example { background: var(--soft-blue); padding: 10px 12px; border-radius: 9px; font-size: 14px; }
.lesson-change,.lesson-hint { font-size: 13px; color: var(--muted); line-height: 1.55; }
.lesson-hint { margin-top: 8px; }
.lesson-try { justify-self: start; grid-column: 1/-1; color: var(--blue); border-color: var(--blue); font-weight: 600; text-align: left; }
.lesson-outcome { display: grid; gap: 3px; padding: 12px 15px; margin-bottom: 12px; border-radius: 13px; background: var(--soft-blue); color: var(--ink); overflow-wrap: anywhere; }
.lesson-outcome > span { font-size: 13px; font-weight: 650; }
.lesson-outcome > strong { font-size: clamp(18px,3.3vw,28px); line-height: 1.25; }
.tool-card:has(.lesson-outcome) > .tool-grid { margin-top: 15px; }
.lesson-details summary { cursor: pointer; font-weight: 650; }
.lesson-details[open] summary { margin-bottom: 10px; }
.lesson-details > .panel { background: var(--card); }
.lesson-error { color: #ad1d45; font-weight: 500; }
.dark .lesson-error { color: #ffa8bf; }
.mode-values [aria-invalid=true] { border-color: #c22d54; }
.mode-values [data-side=a] input { border-inline-start: 4px solid #bb3453; }
.mode-values [data-side=b] input { border-inline-start: 4px solid #148357; }
.mode-values [data-side=c] input { border-inline-start: 4px solid #2563eb; }
@media(max-width:820px){ .lesson-links { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media(max-width:535px){ .lesson-picker { grid-template-columns: minmax(0,1fr); } }
