:root {
  --bg: #eef0f5;
  --surface: #ffffff;
  --ink: #12151f;
  --muted: #586074;
  --line: #d7dbe5;
  --accent: #2b32d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3e5fb;
  --stage: #e6e8f0;
  --warn: #b42318;
  --radius: 10px;
}
:root:not([data-theme="light"]) {
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f16;
    --surface: #161a24;
    --ink: #e9ecf4;
    --muted: #98a1b6;
    --line: #2a3040;
    --accent: #8f98ff;
    --accent-ink: #0d0f16;
    --accent-soft: #232846;
    --stage: #0f121b;
    --warn: #ff9b8f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  line-height: 1.55;
  font-size: 16px;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- page shell + ad slots ---------- */
.page { display: grid; grid-template-columns: minmax(0, 1fr); justify-content: center; gap: 24px; padding: 0 16px; }
.ad { display: none; }
body.ads-on .ad {
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px dashed var(--line); color: var(--muted);
  font-size: 12px; min-height: 60px; border-radius: 6px; overflow: hidden;
}
.ad-side { display: none !important; }
@media (min-width: 1280px) {
  body.ads-on .page { grid-template-columns: 160px minmax(0, 940px) 160px; }
  body.ads-on .ad-side { display: flex !important; min-height: 600px; position: sticky; top: 16px; align-self: start; }
}
.ad-banner { margin: 16px auto; width: 100%; max-width: 940px; }
body.ads-on .ad-banner { min-height: 90px; }
@media (max-width: 600px) { body.ads-on .ad-banner { min-height: 60px; } }

.main { width: 100%; max-width: 940px; margin: 0 auto; }

/* ---------- header ---------- */
.site-head { max-width: 940px; margin: 0 auto; padding: 20px 16px 0; display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -0.01em; }
.logo svg { display: block; }

h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); line-height: 1.1; letter-spacing: -0.025em; margin: 28px 0 8px; }
.lede { color: var(--muted); margin: 0 0 24px; max-width: 60ch; }

/* ---------- calculator ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.calc { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .calc { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; } }

.row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.field label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; font: inherit; font-size: 1.25rem; font-variant-numeric: tabular-nums;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
}
.field input:focus-visible { outline-offset: 0; border-color: var(--accent); }
.swap {
  height: 48px; width: 44px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 8px; cursor: pointer; font-size: 1.1rem;
}
.swap:hover { background: var(--accent-soft); }

.result { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.result-label { color: var(--muted); font-size: 0.875rem; margin: 0 0 2px; }
.ratio-out { font-size: clamp(2.6rem, 9vw, 3.6rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; margin: 0; word-break: break-all; }
.ratio-out.long { font-size: clamp(1.7rem, 6vw, 2.2rem); }
.ratio-meta { color: var(--muted); margin: 6px 0 0; font-size: 0.95rem; min-height: 3em; }
.ratio-meta strong { color: var(--ink); font-weight: 600; }
.error { color: var(--warn); font-size: 0.9rem; min-height: 1.4em; margin: 10px 0 0; }
.btn {
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:hover { filter: brightness(1.08); }

.presets-title { font-size: 0.875rem; font-weight: 600; margin: 20px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 0.85rem; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip small { color: var(--muted); }

/* preview */
.stage { height: 240px; display: grid; place-items: center; background: var(--stage); border-radius: 8px; padding: 20px; }
.frame {
  --r: 1.7778;
  aspect-ratio: var(--r);
  width: min(100%, calc(196px * var(--r)));
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: 4px;
  display: grid; place-items: center; overflow: hidden;
  color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.85rem; text-align: center;
}
@media (prefers-reduced-motion: no-preference) { .frame { transition: width .2s ease; } }
.preview-cap { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }

.resize { margin-top: 20px; }
.resize h2 { font-size: 1.05rem; margin: 0 0 4px; }
.resize p { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 0.9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- article ---------- */
.prose { margin: 40px 0 24px; max-width: 70ch; }
.prose h2 { font-size: 1.4rem; letter-spacing: -0.015em; margin: 32px 0 8px; }
.prose h3 { font-size: 1.05rem; margin: 20px 0 4px; }
.prose p { margin: 0 0 12px; }
.prose code, .formula { background: var(--accent-soft); padding: 2px 6px; border-radius: 4px; font-size: 0.92em; }
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 0.93rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 700; background: var(--bg); }
tr:last-child td { border-bottom: 0; }
td:first-child { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

footer { max-width: 940px; margin: 32px auto 0; padding: 24px 16px 40px; color: var(--muted); font-size: 0.875rem; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 20px; }
footer a { color: var(--muted); }

/* ---------- shared nav + guide pages ---------- */
.site-head { flex-wrap: wrap; gap: 8px 18px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.9rem; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 4px 0; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.crumbs { font-size: 0.85rem; color: var(--muted); margin: 20px 0 0; }
.crumbs a { color: var(--muted); }
.guide-link { margin: 10px 0 0; font-size: 0.95rem; }
.guide-link:empty { display: none; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); margin: 12px 0 0; padding: 0; list-style: none; }
.cards a { display: block; height: 100%; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.cards a:hover { border-color: var(--accent); background: var(--accent-soft); }
.cards strong { display: block; margin-bottom: 2px; }
.cards span { color: var(--muted); font-size: 0.88rem; }
.section-title { font-size: 1.25rem; letter-spacing: -0.015em; margin: 36px 0 0; }
.updated { color: var(--muted); font-size: 0.85rem; margin: 0 0 16px; }
.note-box { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 6px; margin: 16px 0; font-size: 0.93rem; }
.ratio-calc { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ratio-calc .out { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 0.95rem; min-height: 1.5em; }
.field select, .field input[type="text"] { width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.tool-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .tool-grid { grid-template-columns: minmax(0, 300px) minmax(0, 1fr); align-items: start; } }
.tool-controls { display: grid; gap: 12px; }
.tool-controls .field label { margin-bottom: 4px; }
.hint, .tool-info, .tool-note, .legend { color: var(--muted); font-size: 0.85rem; margin: 0; }
.tool-warn { color: var(--warn); font-size: 0.88rem; margin: 0; }
.tool-warn:empty { display: none; }
.file-btn { display: inline-block; text-align: center; cursor: pointer; }
.tool-controls .check { margin-top: 0; }
.tool-stage { display: grid; gap: 8px; justify-items: start; background: var(--stage); padding: 16px; border-radius: 8px; }
.tool-stage canvas { width: 100%; height: auto; max-height: 70vh; border-radius: 4px; background: #000; display: block; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; }
.sw.red { background: rgba(220,38,38,.55); }
.sw.dark { background: rgba(0,0,0,.7); border: 1px solid #7dd3fc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.conv-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.unit-field select { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.unit-row { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: .9rem; }
.unit-row select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }

.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.take-row { display: flex; flex-wrap: wrap; gap: 10px; }
.take-row .btn { text-decoration: none; display: inline-block; }
.tree-frame { background: #080b1f; border-radius: 8px; overflow: hidden; display: flex; justify-content: center; }
.tree-frame iframe { border: 0; width: 100%; max-width: 520px; aspect-ratio: 10 / 17; display: block; }
.snippet, .src-box pre { background: var(--stage); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 0.82rem; margin: 0 0 12px; }
.snippet code, .src-box code { background: none; padding: 0; white-space: pre; }
.src-box pre { max-height: 320px; overflow: auto; margin-top: 10px; }
.src-box summary { cursor: pointer; font-weight: 600; }
.src-box { margin: 0 0 16px; }
@media (max-width: 600px) { .tree-frame iframe { aspect-ratio: 1 / 2; } }

.season-grid { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.season-grid a { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.season-grid a:hover { border-color: var(--accent); }
.season-grid img { width: 100%; height: auto; aspect-ratio: 240 / 270; image-rendering: pixelated; border-radius: 6px; background: #080b1f; }
.season-grid span { color: var(--muted); font-size: 0.9rem; }
.season-grid em { font-style: normal; font-size: 0.8rem; color: var(--muted); margin-top: auto; }

.tree-frame.wide iframe { max-width: 100%; aspect-ratio: 900 / 930; }
@media (max-width: 600px) { .tree-frame.wide iframe { aspect-ratio: 1 / 2; } }
.season-grid.wide { grid-template-columns: minmax(0, 480px); }
.season-grid.wide img { aspect-ratio: 3 / 2; image-rendering: auto; }

.tree-frame.ascii iframe { max-width: 100%; aspect-ratio: 860 / 830; }
@media (max-width: 600px) { .tree-frame.ascii iframe { aspect-ratio: 1 / 1.75; } }

.tree-frame.cat iframe { max-width: 560px; aspect-ratio: 1 / 2.2; }
@media (max-width: 600px) { .tree-frame.cat iframe { aspect-ratio: 1 / 3.7; } }

.tree-frame.doodle iframe { max-width: 760px; aspect-ratio: 760 / 1090; }
@media (max-width: 600px) { .tree-frame.doodle iframe { aspect-ratio: 1 / 3.45; } }

/* tall ASCII scene (imugi tower) */
.tree-frame.tower iframe { max-width: 660px; aspect-ratio: 660 / 1010; }
@media (max-width: 600px) { .tree-frame.tower iframe { aspect-ratio: 1 / 2.35; } }

/* calculator: copy-as-code lines */
.code-card { margin-top: 20px; }
.code-card h2 { font-size: 1.1rem; margin: 0 0 4px; }
.code-list { display: grid; gap: 8px; margin-top: 12px; }
.code-line { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr) auto; gap: 12px; align-items: center; text-align: left; width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.code-line:hover, .code-line:focus-visible { border-color: var(--accent); }
.code-line.ok { border-color: var(--accent); background: var(--accent-soft); }
.code-line code { font-size: 0.85rem; background: none; padding: 0; overflow-wrap: anywhere; min-width: 0; }
.code-tag { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.code-state { font-size: 0.78rem; font-weight: 600; color: var(--accent); }
@media (max-width: 600px) { .code-line { grid-template-columns: minmax(0, 1fr) auto; } .code-tag { grid-column: 1 / -1; } }
.prose ol { padding-left: 1.3em; } .prose ol li { margin: 0 0 6px; }

/* 16:9 typed scene */
.tree-frame.video iframe { max-width: 100%; aspect-ratio: 16 / 12; }
@media (max-width: 600px) { .tree-frame.video iframe { aspect-ratio: 1 / 1.62; } }

/* 3:2 print-shaped scene */
.tree-frame.print iframe { max-width: 100%; aspect-ratio: 16 / 14; }
@media (max-width: 600px) { .tree-frame.print iframe { aspect-ratio: 1 / 1.7; } }

/* search box on the animations page */
.anim-search { margin: 4px 0 8px; display: grid; gap: 6px; max-width: 460px; }
.anim-search label { font-size: 0.875rem; font-weight: 600; }
.anim-search input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; box-sizing: border-box; }
.anim-search input:focus-visible { outline-offset: 0; border-color: var(--accent); }
[hidden] { display: none !important; }

/* logo */
.logo { font-size: 1.12rem; letter-spacing: -0.02em; }
.logo-dot { color: #f59a2e; }

/* ===== sidebar navigation with search ===== */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.menu-btn { margin-left: auto; font: inherit; font-size: 0.9rem; font-weight: 600; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
.side-panel { display: none; width: 100%; padding: 8px 0 6px; }
.site-head.open .side-panel { display: block; }
.site-search { margin: 4px 0 6px; }
.site-search input { width: 100%; font: inherit; font-size: 0.95rem; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); box-sizing: border-box; }
.site-search input:focus-visible { border-color: var(--accent); outline-offset: 0; }
.search-results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.search-results a { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 0.92rem; }
.search-results a:hover, .search-results a:focus-visible { background: var(--accent-soft); }
.search-results small { display: block; color: var(--muted); font-size: 0.76rem; font-weight: 400; margin-top: 2px; }
.search-results .none { padding: 8px 10px; color: var(--muted); font-size: 0.85rem; }
.side-panel .nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 2px 12px; margin: 0; font-size: 0.93rem; }
.nav-title { grid-column: 1 / -1; margin: 14px 0 2px 10px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.side-panel .nav a { padding: 7px 10px; border-radius: 8px; }
.side-panel .nav a:hover { background: var(--accent-soft); color: var(--ink); text-decoration: none; }
.side-panel .nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; text-decoration: none; }
.site-head.searching .nav { display: none; }
@media (min-width: 1000px) {
  body { padding-left: 252px; }
  .site-head { position: fixed; top: 0; left: 0; bottom: 0; width: 252px; max-width: none; margin: 0; padding: 22px 14px 24px; flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 14px; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); box-sizing: border-box; z-index: 5; }
  .site-head .logo { padding-left: 8px; }
  .menu-btn { display: none; }
  .side-panel { display: block; padding: 0; }
  .side-panel .nav { grid-template-columns: 1fr; }
  .main { padding-top: 20px; }
}

/* 16:9 scene with a taller control row */
.tree-frame.video.more iframe { aspect-ratio: 16 / 13.3; }
@media (max-width: 600px) { .tree-frame.video.more iframe { aspect-ratio: 1 / 1.86; } }

/* 3:2 toy with sliders */
.tree-frame.jelly iframe { max-width: 100%; aspect-ratio: 16 / 17.4; }
@media (max-width: 600px) { .tree-frame.jelly iframe { aspect-ratio: 1 / 2.42; } }

/* games tab, empty for now */
.games-empty { text-align: center; padding: 40px 24px; }
.games-empty h2 { margin: 6px 0 10px; }
.games-empty p { max-width: 52ch; margin-left: auto; margin-right: auto; }
.games-badge { display: inline-block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 4px 10px; border-radius: 999px; margin: 0; }

/* playable game preview */
.tree-frame.game iframe { max-width: 100%; aspect-ratio: 16 / 12.5; }
@media (max-width: 600px) { .tree-frame.game iframe { aspect-ratio: 1 / 1.7; } }

/* Dragon over Blackridge preview */
.tree-frame.ridge iframe { max-width: 100%; aspect-ratio: 16 / 14.6; }
@media (max-width: 600px) { .tree-frame.ridge iframe { aspect-ratio: 1 / 1.52; } }
@media (max-width: 440px) { .tree-frame.ridge iframe { aspect-ratio: 1 / 2.52; } }

/* Sekigahara from the Ridge preview */
.tree-frame.seki iframe { max-width: 100%; aspect-ratio: auto; height: 960px; }
@media (max-width: 600px) { .tree-frame.seki iframe { aspect-ratio: auto; height: 900px; } }
@media (max-width: 440px) { .tree-frame.seki iframe { aspect-ratio: auto; height: 1000px; } }

/* ---------- language switcher ---------- */
.lang-switch { float: right; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; max-width: 55%; margin: 32px 0 0 12px; font-size: 0.82rem; line-height: 1.4; }
.lang-switch a { color: var(--muted); text-decoration: none; }
.lang-switch a:hover { color: var(--ink); text-decoration: underline; }
.lang-switch [aria-current] { color: var(--ink); font-weight: 700; }
@media (max-width: 600px) { .lang-switch { float: none; justify-content: flex-start; max-width: none; margin: 14px 0 -6px; } }

/* GIF studio: tall tool frame, height is set by the tool through guide.js */
.tree-frame.studio { background: #fff; }
.tree-frame.studio iframe { max-width: 100%; aspect-ratio: auto; height: 1400px; }
@media (max-width: 600px) { .tree-frame.studio iframe { aspect-ratio: auto; height: 2400px; } }

/* Pixel Studio: fixed-height tool frame (the tool fills its own viewport) */
.tree-frame.pixel { background: #101217; }
.tree-frame.pixel iframe { max-width: 100%; aspect-ratio: auto; height: 880px; }
@media (max-width: 600px) { .tree-frame.pixel iframe { aspect-ratio: auto; height: 900px; } }

/* Hindi (Devanagari): fonts that carry the script on Windows, Android and Apple devices */
html[lang="hi"] body { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Nirmala UI", "Noto Sans Devanagari", "Kohinoor Devanagari", Mangal, Roboto, Arial, sans-serif; line-height: 1.7; }

.nav-group { grid-column: 1 / -1; }
.nav-group > summary.nav-title { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; margin: 10px 0 2px; padding: 8px 10px; border-radius: 8px; user-select: none; }
.nav-group > summary.nav-title::-webkit-details-marker { display: none; }
.nav-group > summary.nav-title::after { content: "\25B8"; font-size: 0.8rem; transition: transform .15s; }
.nav-group[open] > summary.nav-title::after { transform: rotate(90deg); }
.nav-group > summary.nav-title:hover, .nav-group > summary.nav-title:focus-visible { background: var(--accent-soft); color: var(--ink); }
.nav-group > a { display: block; }
@media (prefers-reduced-motion: reduce) { .nav-group > summary.nav-title::after { transition: none; } }
