:root {
  --glass: rgba(12, 16, 36, 0.66);
  --glass-strong: rgba(14, 18, 42, 0.9);
  --border: rgba(150, 175, 255, 0.16);
  --border-strong: rgba(150, 190, 255, 0.35);
  --text: #eaf0ff;
  --muted: #98a3c7;
  --accent: #6ee7ff;
  --accent-2: #b28cff;
  --good: #4dff9a;
  --warm: #ffb84d;
  --danger: #ff5d7a;
  --radius: 18px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --head: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #02030a; color: var(--text); font-family: var(--body); -webkit-font-smoothing: antialiased; }
body { user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

#gl, #overlay { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { touch-action: none; }
#overlay { pointer-events: none; }

.panel {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------ top bar */
#topbar { position: fixed; top: 12px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; z-index: 5; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--head); font-size: 24px; font-weight: 600; letter-spacing: 0.3px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.brand b { font-weight: 700; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { width: 38px; height: 38px; overflow: visible; }
.logo-planet { transform-origin: 20px 20px; animation: logo-orbit 6s linear infinite; }
@keyframes logo-orbit { to { transform: rotate(360deg); } }
.top-actions { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 999px; background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-weight: 800; font-size: 14px; transition: transform .15s, border-color .15s, background .15s; box-shadow: var(--shadow); }
.pill:hover { transform: translateY(-1px); border-color: var(--border-strong); background: rgba(30, 40, 80, 0.7); }
.pill.round { width: 40px; padding: 0; justify-content: center; font-size: 17px; }

/* ------------------------------------------------------------------ toolbar */
#toolbar { position: fixed; left: 14px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 4px; padding: 7px; z-index: 4; }
.tool { width: 66px; padding: 8px 2px 7px; border-radius: 13px; display: flex; flex-direction: column; align-items: center; gap: 3px; transition: background .15s, transform .15s; position: relative; }
.tool .ti { font-size: 25px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5)); transition: transform .2s; }
.tool .tl { font-size: 11px; font-weight: 800; color: var(--muted); letter-spacing: .2px; }
.tool:hover { background: rgba(110, 160, 255, 0.1); }
.tool:hover .ti { transform: scale(1.12) rotate(-6deg); }
.tool.active { background: linear-gradient(160deg, rgba(110, 231, 255, 0.22), rgba(178, 140, 255, 0.22)); box-shadow: inset 0 0 0 1.5px rgba(140, 220, 255, 0.55), 0 0 18px rgba(110, 200, 255, 0.25); }
.tool.active .tl { color: var(--text); }

/* ------------------------------------------------------------------ tool panel */
#tool-panel { position: fixed; left: 96px; top: 50%; transform: translateY(-50%); width: 290px; padding: 16px; z-index: 4; max-height: calc(100vh - 200px); overflow-y: auto; animation: pop-in .18s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-50%) translateX(-8px); } }
.tp-title { font-family: var(--head); font-size: 19px; font-weight: 600; margin: 0 0 2px; }
.tp-sub { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; line-height: 1.4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); font-size: 12px; font-weight: 800; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: rgba(110, 231, 255, 0.18); border-color: rgba(110, 231, 255, 0.6); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.preset-desc { font-size: 12.5px; color: #c9d3f5; background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 8px 10px; margin: -4px 0 12px; line-height: 1.4; }

.field { margin-bottom: 12px; }
.field-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; font-weight: 800; margin-bottom: 5px; }
.field-top .val { color: var(--accent); font-variant-numeric: tabular-nums; }
.field-note { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, rgba(110, 231, 255, .55), rgba(178, 140, 255, .55)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, rgba(110, 231, 255, .55), rgba(178, 140, 255, .55)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(110, 231, 255, .25), 0 2px 8px rgba(0, 0, 0, .5); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(110, 231, 255, .25), 0 2px 8px rgba(0, 0, 0, .5); }
.colors { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch-btn { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .15); transition: transform .12s; }
.swatch-btn:hover { transform: scale(1.15); }
.swatch-btn.active { border-color: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, .4); }
.swatch-btn.auto { background: conic-gradient(#ff6b6b, #ffd93d, #6bff95, #6ee7ff, #b28cff, #ff6b6b); }
input[type=color] { width: 28px; height: 28px; border: 0; padding: 0; background: none; border-radius: 50%; cursor: pointer; }
.result { display: flex; gap: 10px; align-items: center; background: rgba(110, 231, 255, 0.07); border: 1px solid rgba(110, 231, 255, 0.18); border-radius: 12px; padding: 9px 11px; font-size: 12.5px; line-height: 1.35; }
.result .big { font-size: 22px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; font-size: 13px; font-weight: 700; cursor: pointer; }
.switch-row small { display: block; font-weight: 600; color: var(--muted); font-size: 11.5px; }

/* ------------------------------------------------------------------ toggles */
.sw { width: 36px; height: 21px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); position: relative; flex: none; transition: background .2s; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #cfd6ef; transition: transform .2s, background .2s; }
.on > .sw, .sw.on { background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.on > .sw::after, .sw.on::after { transform: translateX(15px); background: #fff; }

#views { position: fixed; right: 14px; top: 64px; width: 252px; z-index: 4; overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 160px); }
.panel-head { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-family: var(--head); font-weight: 600; font-size: 16px; }
.panel-head .chev { transition: transform .2s; color: var(--muted); }
#views.collapsed .chev { transform: rotate(-90deg); }
#views.collapsed .panel-body { display: none; }
.panel-body { padding: 0 8px 10px; overflow-y: auto; }
.view-toggle { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 11px; text-align: left; transition: background .15s; }
.view-toggle:hover { background: rgba(255, 255, 255, 0.05); }
.view-toggle .vi { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; flex: none; background: color-mix(in srgb, var(--c) 18%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 45%, transparent); }
.view-toggle .vt { flex: 1; font-size: 13px; font-weight: 800; line-height: 1.15; }
.view-toggle .vt small { display: block; color: var(--muted); font-weight: 600; font-size: 11px; }
.views-sep { font-size: 10.5px; font-weight: 800; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; padding: 10px 8px 4px; }

/* ------------------------------------------------------------------ info card */
#info { position: fixed; right: 14px; bottom: 96px; width: 300px; padding: 14px 16px; z-index: 4; max-height: calc(100vh - 190px); overflow-y: auto; animation: pop-up .2s ease-out; }
@keyframes pop-up { from { opacity: 0; transform: translateY(8px); } }
.info-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.info-orb { width: 38px; height: 38px; border-radius: 50%; flex: none; box-shadow: 0 0 18px var(--orb, #fff); }
.info-name { flex: 1; min-width: 0; }
.info-name input { width: 100%; background: transparent; border: 0; border-bottom: 1px dashed transparent; color: var(--text); font-family: var(--head); font-size: 20px; font-weight: 600; padding: 0; outline: none; }
.info-name input:hover, .info-name input:focus { border-bottom-color: var(--border-strong); }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: #cfd8f7; margin-top: 2px; }
.x-btn { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); font-size: 16px; }
.x-btn:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.stat { background: rgba(255, 255, 255, .045); border-radius: 10px; padding: 7px 9px; }
.stat .k { font-size: 10.5px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 1px; }
.stat .n { font-size: 11px; color: #b8c3ea; margin-top: 1px; line-height: 1.25; }
.stat.wide { grid-column: span 2; }
.info-fact { font-size: 12.5px; line-height: 1.45; color: #d4dcfa; background: linear-gradient(135deg, rgba(110, 231, 255, .08), rgba(178, 140, 255, .08)); border-radius: 12px; padding: 9px 11px; margin: 8px 0 10px; }
.info-actions { display: flex; gap: 8px; }
.btn { flex: 1; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, .07); border: 1px solid var(--border); font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all .15s; }
.btn:hover { border-color: var(--border-strong); background: rgba(255, 255, 255, .1); }
.btn.primary { background: linear-gradient(135deg, #36c6ff, #8f6bff); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(80, 140, 255, .35); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger:hover { border-color: var(--danger); color: #ffc1cc; }
.btn.on { border-color: rgba(110, 231, 255, .7); background: rgba(110, 231, 255, .15); }
select { width: 100%; height: 34px; border-radius: 10px; background: rgba(255, 255, 255, .07); border: 1px solid var(--border); color: var(--text); font: inherit; font-weight: 700; font-size: 13px; padding: 0 8px; }
select option { background: #121630; }

/* ------------------------------------------------------------------ time bar */
#timebar { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 7px 10px; z-index: 4; border-radius: 999px; }
.tb { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; transition: background .15s, transform .1s; }
.tb:hover { background: rgba(255, 255, 255, .08); }
.tb:active { transform: scale(.92); }
.tb.play { width: 52px; height: 52px; font-size: 20px; background: linear-gradient(135deg, #36c6ff, #8f6bff); box-shadow: 0 6px 22px rgba(80, 140, 255, .45); color: #fff; }
.tb.play:hover { filter: brightness(1.1); background: linear-gradient(135deg, #36c6ff, #8f6bff); }
.tb.play.paused { background: linear-gradient(135deg, #ffb84d, #ff6b8b); box-shadow: 0 6px 22px rgba(255, 120, 120, .4); }
.readout { min-width: 150px; text-align: center; padding: 0 6px; line-height: 1.25; }
#speed-label { font-size: 12px; font-weight: 800; color: var(--muted); }
#time-label { font-family: var(--head); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

#stats { position: fixed; left: 16px; bottom: 18px; font-size: 11.5px; font-weight: 700; color: rgba(200, 210, 240, .65); z-index: 3; line-height: 1.5; pointer-events: none; font-variant-numeric: tabular-nums; }
#limited { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); font-size: 12px; font-weight: 800; color: #ffd9a0; background: rgba(60, 35, 10, .7); border: 1px solid rgba(255, 184, 77, .35); padding: 5px 12px; border-radius: 999px; z-index: 3; pointer-events: none; }
#hint { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); font-size: 13px; font-weight: 700; color: #dfe7ff; background: rgba(10, 14, 34, .72); border: 1px solid var(--border); padding: 7px 14px; border-radius: 999px; z-index: 3; pointer-events: none; white-space: nowrap; transition: opacity .3s; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#hint:empty { opacity: 0; }
#limited:not(.hidden) ~ #hint, #hint.up { bottom: 118px; }
kbd { font-family: var(--body); font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 5px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .15); }

/* ------------------------------------------------------------------ toasts */
#toasts { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 6; pointer-events: none; width: min(560px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--glass-strong); border: 1px solid var(--border-strong); border-radius: 14px; padding: 10px 14px; font-size: 13.5px; font-weight: 600; line-height: 1.4; box-shadow: var(--shadow); animation: toast-in .35s cubic-bezier(.2, 1.4, .4, 1); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.toast .te { font-size: 22px; line-height: 1.1; }
.toast.out { animation: toast-out .4s forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ------------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(2, 4, 14, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-card { position: relative; width: min(920px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: linear-gradient(160deg, rgba(20, 26, 58, .94), rgba(10, 12, 30, .96)); border: 1px solid var(--border-strong); border-radius: 24px; padding: 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: card-in .3s cubic-bezier(.2, 1.2, .4, 1); }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-card h2 { font-family: var(--head); font-size: 30px; font-weight: 600; margin: 0 0 6px; }
.modal-card .lead { color: #c3cdf0; font-size: 15px; margin: 0 0 20px; line-height: 1.5; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%; font-size: 18px; color: var(--muted); }
.modal-close:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
.scenario-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.scenario { text-align: left; padding: 16px; border-radius: 16px; background: rgba(255, 255, 255, .045); border: 1px solid var(--border); transition: transform .15s, border-color .15s, background .15s; display: flex; gap: 12px; align-items: flex-start; }
.scenario:hover { transform: translateY(-2px); border-color: rgba(110, 231, 255, .55); background: rgba(110, 231, 255, .08); }
.scenario .se { font-size: 34px; line-height: 1; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5)); }
.scenario .sn { font-family: var(--head); font-size: 17px; font-weight: 600; margin-bottom: 3px; }
.scenario .sd { font-size: 12.5px; color: #b6c1e6; line-height: 1.4; }
.welcome-hero { display: flex; gap: 22px; align-items: center; margin-bottom: 18px; }
.welcome-hero .big { font-size: 64px; filter: drop-shadow(0 6px 20px rgba(255, 180, 80, .4)); }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 0 0 22px; }
.how div { background: rgba(255, 255, 255, .045); border-radius: 14px; padding: 12px 14px; font-size: 13px; line-height: 1.45; color: #cfd8f7; }
.how b { display: block; color: var(--text); font-size: 14px; margin-bottom: 2px; }
.section-label { font-size: 12px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }

.lesson { display: grid; grid-template-columns: 120px 1fr; gap: 24px; align-items: center; min-height: 220px; }
.lesson .li { font-size: 88px; text-align: center; filter: drop-shadow(0 8px 24px rgba(110, 200, 255, .35)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.lesson h3 { font-family: var(--head); font-size: 26px; font-weight: 600; margin: 0 0 8px; }
.lesson p { font-size: 15.5px; line-height: 1.6; color: #d6defa; margin: 0 0 16px; }
.lesson p b { color: var(--accent); }
.lesson-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; gap: 12px; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.dots button { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .2); padding: 0; }
.dots button.active { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.lesson-nav .btn { flex: none; padding: 0 16px; }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-top: 18px; }
.lesson-list button { text-align: left; font-size: 13px; font-weight: 700; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .04); display: flex; gap: 8px; align-items: center; }
.lesson-list button:hover, .lesson-list button.active { background: rgba(110, 231, 255, .12); }

#nogl { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 900px), (max-height: 640px) {
  .brand { font-size: 20px; }
  .pill .pl { display: none; }
  .pill { padding: 0 12px; }
  #toolbar { top: auto; bottom: 86px; left: 10px; transform: none; flex-direction: row; overflow-x: auto; max-width: calc(100vw - 20px); padding: 5px; }
  .tool { width: 58px; padding: 6px 2px; }
  .tool .ti { font-size: 21px; }
  #tool-panel { left: 10px; right: 10px; width: auto; top: auto; bottom: 166px; transform: none; max-height: 36vh; animation: none; padding: 12px 14px; }
  #views { top: 60px; right: 10px; width: 230px; max-height: calc(100vh - 260px); }
  #info { left: 10px; right: 10px; width: auto; bottom: 166px; max-height: 38vh; padding: 12px 14px; }
  .stats-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stat.wide { grid-column: span 3; }
  .stat:not(.wide) .n { display: none; }
  .tp-sub, .preset-desc { display: none; }
  #timebar { bottom: 12px; padding: 5px 8px; gap: 2px; }
  .readout { min-width: 110px; }
  #stats { display: none; }
  #hint { bottom: 156px; white-space: normal; text-align: center; max-width: calc(100vw - 30px); }
  #limited { bottom: 74px; }
  .lesson { grid-template-columns: 1fr; gap: 6px; text-align: center; }
  .lesson .li { font-size: 64px; }
  .modal-card { padding: 22px 18px; }
  .welcome-hero .big { font-size: 48px; }
}
