/* SPDX-License-Identifier: GPL-3.0-or-later */
:root {
  --bg: #080b14;
  --bg2: #0d1220;
  --panel: #111829;
  --panel2: #161f35;
  --line: #222d48;
  --text: #e8ecf5;
  --muted: #8a96b3;
  --dim: #5a6684;
  --yellow: #ffc93c;
  --yellow-glow: rgba(255, 201, 60, .35);
  --blue: #4f8cff;
  --pink: #ff5c8a;
  --green: #3ddc97;
  --circle: rgba(190, 200, 225, .32);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 60% -10%, #121a33 0%, var(--bg) 60%);
  background-color: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  /* every digit the same width, so changing numbers do not move the layout */
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; }
i { font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", Georgia, serif; }

/* ------------------------------------------------------------ top bar */
.top {
  height: 64px; display: flex; align-items: center; gap: 14px;
  padding: 0 20px; border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 20, .7); backdrop-filter: blur(8px);
}
.lang { position: relative; flex: none; }
.lang-btn {
  display: flex; align-items: center; gap: 7px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 0 10px; height: 36px; cursor: pointer; font-size: 13px;
}
.lang-btn:hover { border-color: var(--muted); }
.flag { width: 22px; height: 15px; border-radius: 3px; object-fit: cover; display: block; box-shadow: 0 0 0 1px rgba(255,255,255,.12); }
.caret { color: var(--muted); font-size: 10px; }
.lang-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; list-style: none; margin: 0; padding: 5px;
  min-width: 200px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}
.lang-menu li {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px; cursor: pointer;
}
.lang-menu li:hover, .lang-menu li[aria-selected="true"] { background: rgba(255, 201, 60, .1); color: var(--yellow); }
.brand { display: flex; align-items: center; gap: 10px; flex: none; color: inherit; text-decoration: none; }
a.brand:hover .logo { border-color: var(--yellow); }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #1c2847, #0d1324); border: 1px solid var(--line);
  color: var(--yellow); font-size: 26px; text-shadow: 0 0 12px var(--yellow-glow);
}
.kicker { font: 10px/1 var(--mono); letter-spacing: .16em; color: var(--muted); }
.brand h1 { font-size: 20px; letter-spacing: -.01em; }
.brand h1 em { font-style: normal; color: var(--yellow); }

.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
/* Tabs show only their icon; the label slides out on hover and stays open on
   the active tab. */
.tab {
  display: inline-flex; align-items: center; flex: none;
  background: none; border: 0; padding: 7px 10px; border-radius: 10px; cursor: pointer;
  color: var(--muted); white-space: nowrap; transition: background .2s, color .2s;
}
.tab .ti { font-size: 17px; line-height: 1; width: 20px; text-align: center; }
.tab .tl {
  max-width: 0; opacity: 0; overflow: hidden; margin-left: 0;
  transition: max-width .3s ease, opacity .2s ease, margin-left .3s ease;
}
.tab:hover .tl, .tab:focus-visible .tl, .tab.active .tl { max-width: 220px; opacity: 1; margin-left: 7px; }
.tab:hover { color: var(--yellow); background: rgba(255, 201, 60, .12); }
.tab.active { color: var(--bg); background: var(--yellow); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions .btn { height: 36px; padding-top: 0; padding-bottom: 0; }

/* author credit (right of the top bar), stage watermark and About card */
.credit { display: flex; align-items: center; gap: 6px; flex: none; }
.credit-item {
  height: 36px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); text-decoration: none; transition: .15s;
}
.credit-item:hover { border-color: var(--yellow); color: var(--yellow); }
.credit-photo { width: 36px; padding: 0; overflow: hidden; position: relative; }
.credit-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.credit-photo::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--yellow); }
.credit-apliant { gap: 6px; padding: 0 10px 0 8px; font-size: 13px; font-weight: 600; }
.credit-apliant img { width: 20px; height: 20px; }
.credit-icon { width: 36px; }
.credit-icon svg { width: 18px; height: 18px; }
.credit-name {
  font-size: 12px; font-weight: 700; line-height: 1.15; color: var(--text); text-decoration: none;
  padding-left: 2px;
}
.credit-name:hover { color: var(--yellow); }
.credit-icons { display: inline-flex; gap: 3px; margin-left: 4px; }
.ico {
  width: 16px; height: 16px; border-radius: 4px; display: inline-grid; place-items: center;
  color: var(--muted); transition: .15s;
}
.ico:hover { color: var(--yellow); }
.ico svg { width: 12px; height: 12px; }
.ico img { width: 13px; height: 13px; }
.about-items { margin-top: 8px; }
.stage-credit {
  position: absolute; left: 14px; bottom: 16px; font: 600 11px var(--mono); color: var(--dim);
  text-decoration: none; letter-spacing: .03em;
}
.stage-credit:hover { color: var(--yellow); }
.about { display: flex; gap: 16px; align-items: center; }
.about-photo { width: 84px; height: 84px; border-radius: 16px; object-fit: cover; display: block; border-bottom: 4px solid var(--yellow); }
.about p { color: #c3cbe0; margin: 6px 0; }
.about p a { color: var(--yellow); font-weight: 700; }
.about-items .privacy-link { margin-left: 8px; }
.copyright { color: var(--dim); font-size: 12px; margin-left: 4px; }
.embed-title { display: none; color: var(--muted); }

/* ------------------------------------------------------------ buttons */
.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.accent { background: var(--yellow); color: #1a1405; border-color: var(--yellow); font-weight: 600; }
.btn.accent:hover { filter: brightness(1.08); box-shadow: 0 0 18px var(--yellow-glow); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }

/* ------------------------------------------------------------ layout */
.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100% - var(--top-h, 64px)); }
.side {
  overflow-y: auto; padding: 14px; border-right: 1px solid var(--line);
  background: rgba(13, 18, 32, .6); scrollbar-width: thin;
}
main { position: relative; overflow: hidden; }
.view { display: none; height: 100%; overflow-y: auto; padding: 16px; }
.view.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 14px; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.step {
  width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); color: var(--bg);
  display: inline-grid; place-items: center; font-size: 12px;
}
.credits { color: var(--dim); font-size: 12px; text-align: center; }

.busy:not(:empty)::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--yellow); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: block; margin-top: 10px; font-size: 12px; color: var(--muted); }
.field output { float: right; color: var(--text); font-family: var(--mono); }
.field select { width: 100%; margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row input[type=range] { flex: 1; }
.big-out { font-size: 16px; color: var(--yellow) !important; font-weight: 700; }
select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
input[type=range] { width: 100%; accent-color: var(--yellow); margin: 6px 0 0; }
input[type=range]:disabled { opacity: .35; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); cursor: pointer; }
.chk input { accent-color: var(--yellow); margin: 0; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 12px; }

.quick { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.quick button {
  flex: 1; min-width: 36px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 7px; padding: 3px 0; cursor: pointer; font: 12px var(--mono);
}
.quick button:hover { border-color: var(--yellow); color: var(--yellow); }

.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; margin-top: 4px; }
.seg button { flex: 1; background: none; border: 0; border-radius: 7px; padding: 5px 6px; cursor: pointer; color: var(--muted); font-size: 12px; }
.seg button.on { background: var(--panel2); color: var(--yellow); box-shadow: inset 0 0 0 1px var(--line); }
.seg.small { margin: 0; }

/* ------------------------------------------------------------ stage */
.stage {
  position: relative; border-radius: var(--radius); overflow: hidden; min-height: 0;
  background: radial-gradient(circle at 50% 45%, #0f1628 0%, #070a12 75%);
  border: 1px solid var(--line);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.stage canvas.dragging { cursor: grabbing; }
.stage-ctrl {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; background: rgba(13, 18, 32, .8); border: 1px solid var(--line);
  border-radius: 12px; padding: 5px; backdrop-filter: blur(6px);
}
.stage-ctrl button {
  min-width: 36px; height: 32px; border-radius: 8px; border: 0; background: var(--panel2);
  cursor: pointer; font-size: 15px;
}
.stage-ctrl button:hover { background: #22305a; }
.stage-ctrl button.on { box-shadow: inset 0 0 0 1px var(--yellow); }
.stage-ctrl .show { padding: 0 12px; font-size: 13px; font-weight: 600; }
.stage-ctrl .show.on { background: var(--yellow); color: var(--bg); }
.hint { position: absolute; top: 12px; right: 14px; max-width: min(420px, 55%); text-align: right; line-height: 1.7; font-size: 11px; color: var(--dim); pointer-events: none; }

.sub { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.legend { display: flex; gap: 12px; align-items: center; font-size: 11px; color: var(--muted); margin: 6px 0 14px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: -8px; }
.dot.y { background: var(--yellow); } .dot.p { background: var(--pink); } .dot.g { background: var(--dim); }
.dot.b { background: var(--blue); } .dot.w { background: #fff; }

/* ------------------------------------------------------------ other tabs */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.panel h2 { font-size: 16px; }
.panel h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.grid2 .panel { margin-bottom: 0; }
.grid2 + .panel { margin-top: 14px; }
.explain { margin-top: 14px; color: var(--muted); font-size: 13px; }
.explain math { color: var(--text); }


/* how it works */
.learn { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
.lesson { position: relative; padding-left: 58px; margin: 0; }
.lesson .num {
  position: absolute; left: 16px; top: 16px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--yellow); color: var(--bg); display: grid; place-items: center; font-weight: 800;
}
.lesson p, .lesson li { color: #c3cbe0; }
.lesson .formula { font-size: 19px; }
.challenges ol { padding-left: 18px; margin: 8px 0 0; }
.challenges li { margin: 4px 0; }
kbd {
  font: 11px var(--mono); background: var(--panel2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; margin: 0 1px;
}

/* freehand dialog */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; max-width: 95vw;
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(3px); }
.dlg-actions { display: flex; gap: 8px; margin-top: 12px; }
.spacer { flex: 1; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 30px); opacity: 0;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px;
  transition: .25s; pointer-events: none; z-index: 10; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--pink); }

.embed-foot { display: none; }

/* ------------------------------------------------------------ exported (offline) mode */
body.embed [data-online] { display: none !important; }
body.embed .embed-title { display: inline; }
body.embed .step { display: none; }
body.embed .embed-foot {
  display: block; position: fixed; bottom: 6px; left: 14px; font-size: 11px; color: var(--dim);
}

/* ------------------------------------------------------------ responsive */
/* Top bar compaction, applied step by step by fitHeader() in core.js only
   while the tabs do not fit (works for any font and language). */
.top.fit-1 { gap: 10px; padding: 0 14px; }
.top.fit-1 .kicker { display: none; }
.top.fit-2 .credit { gap: 4px; }
.top.fit-2 .credit-name { display: none; }   /* the photo still links to the author page */
.top.fit-3 #langName { display: none; }      /* flag only; the menu still shows names */
.top.fit-4 { gap: 6px; padding: 0 10px; }
.top.fit-4 .tab { padding: 7px 6px; }
.top.fit-4 .tabs { gap: 0; }
.top.fit-5 { height: auto; flex-wrap: wrap; padding: 8px 14px; row-gap: 6px; }
.top.fit-5 .tabs { order: 3; flex-basis: 100%; }
.top.fit-5 .top-actions { margin-left: auto; }


/* hide/show the sidebar (H) */
.side-toggle {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%); z-index: 6;
  width: 16px; height: 56px; padding: 0; border: 1px solid var(--line); border-left: 0;
  border-radius: 0 9px 9px 0; background: var(--panel2); color: var(--muted); cursor: pointer;
  font-size: 14px; line-height: 1; transition: .15s;
}
.side-toggle:hover { width: 22px; color: var(--yellow); border-color: var(--yellow); }
body.side-hidden .layout { grid-template-columns: 1fr; }
body.side-hidden .side { display: none; }
@media (max-width: 860px) { .side-toggle { display: none; } }

/* ------------------------------------------------------------ lab panels: controls + big readout */
.lab-controls { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(240px, 1fr) auto; gap: 20px; align-items: center; }
.lab-controls h2 { margin-bottom: 4px; }
.lab-sliders .field:first-child { margin-top: 0; }
.lab-sliders .row { margin-top: 10px; gap: 14px; flex-wrap: wrap; }
.lab-readout { text-align: center; min-width: 150px; }
.lab-big { font-size: 40px; font-weight: 800; color: var(--yellow); font-family: var(--mono); line-height: 1.1; }
.lab-big.good { color: var(--green); }
.lab-big.bad { color: var(--pink); }
canvas.lab-wide { width: 100%; height: 300px; display: block; }
canvas.lab-square { width: 100%; height: 340px; display: block; }
.before-after { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.before-after canvas { border-radius: 10px; background: var(--bg2); }
.filter-go { justify-content: center; margin-top: 10px; gap: 6px; }
.lab-sliders .field.off { opacity: .35; pointer-events: none; }

/* visit notice (bottom right, small) */
.consent {
  position: fixed; right: 14px; bottom: 14px; z-index: 40; max-width: min(440px, calc(100vw - 28px));
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  background: rgba(17, 24, 41, .96); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px 8px 14px; font-size: 12px; color: var(--muted);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); backdrop-filter: blur(6px);
}
.consent[hidden] { display: none; }
.consent span { flex: 1 1 220px; }
.consent a { color: var(--muted); }
.consent a:hover { color: var(--yellow); }
.privacy-link { color: var(--dim); font-size: 12px; }
.privacy-link:hover { color: var(--yellow); }

/* ------------------------------------------------------------ small screens */
@media (max-width: 1200px) {
  .grid2 { grid-template-columns: 1fr; }
  .lab-controls { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .layout main { order: -1; }
  .side { border-right: 0; }
  .view { height: auto; overflow: visible; padding: 16px; }
  .hint { display: none; }
  .learn { grid-template-columns: 1fr; }
}
