/* Fractal Atlas — the UI re-themes itself from the active palette. */
@property --accent  { syntax: '<color>'; inherits: true; initial-value: #c47bff; }
@property --accent2 { syntax: '<color>'; inherits: true; initial-value: #5ee0ff; }

:root {
  --accent: #c47bff;
  --accent2: #5ee0ff;
  --ink: #eceaf7;
  --ink-dim: #a29fba;
  --ink-faint: #8683a3;
  --glass: rgba(12, 10, 26, 0.62);
  --glass-strong: rgba(14, 12, 30, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --panel-w: 348px;
  --gap: 14px;
  --r: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;
  transition: --accent 0.9s ease, --accent2 0.9s ease;
  color-scheme: dark;
}
.lite:root { transition: none; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #07060f; color: var(--ink); font: 14px/1.4 var(--font); overflow: hidden; overscroll-behavior: none; }

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
body.dragging #gl { cursor: grabbing; }
#shade { position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(5,4,14,.55), transparent 16%, transparent 80%, rgba(5,4,14,.6)); }

[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- glass surfaces ---------- */
#panel, #dock, #toolbar, #hud, #brand, .toast, dialog {
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 10px 40px -14px rgba(0,0,0,.7), 0 0 36px -16px color-mix(in srgb, var(--accent) 70%, transparent);
}
.lite #panel, .lite #dock, .lite #toolbar, .lite #hud, .lite #brand, .lite .toast, .lite dialog {
  -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--glass-strong); box-shadow: 0 6px 20px -8px rgba(0,0,0,.8);
}

/* ---------- brand + toolbar ---------- */
#brand { position: fixed; top: var(--gap); left: var(--gap); display: flex; gap: 10px; align-items: center; padding: 8px 16px 8px 10px; border-radius: 999px; z-index: 5; }
#brand .logo { width: 32px; height: 32px; color: var(--accent); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 70%, transparent)); }
.lite #brand .logo { filter: none; }
#brand h1 { margin: 0; font-size: 14px; letter-spacing: .2em; text-transform: uppercase; font-weight: 700; }
#brand p { margin: 0; font-size: 11.5px; color: var(--ink-dim); }
#subtitle b { color: var(--accent2); font-weight: 600; }

#toolbar { position: fixed; top: var(--gap); right: var(--gap); display: flex; gap: 4px; padding: 5px; border-radius: 999px; z-index: 6; transition: right .35s cubic-bezier(.2,.8,.2,1); }
body.panel-open #toolbar { right: calc(var(--panel-w) + var(--gap) * 2); }
.ibtn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--ink-dim); display: grid; place-items: center; transition: background .2s, color .2s, transform .2s; }
.ibtn svg { width: 20px; height: 20px; }
.ibtn:hover { background: rgba(255,255,255,.09); color: #fff; }
.ibtn:active { transform: scale(.92); }
.ibtn.accent { color: #0a0814; background: var(--accent); }
.ibtn.accent:hover { background: color-mix(in srgb, var(--accent) 80%, #fff); color: #0a0814; }
body.touring #b-tour { background: color-mix(in srgb, var(--accent2) 30%, transparent); color: #fff; }
#b-tour .i-pause { display: none; } body.touring #b-tour .i-pause { display: block; } body.touring #b-tour .i-play { display: none; }
#b-tour .i-play { fill: currentColor; }

/* ---------- panel ---------- */
#panel { position: fixed; top: calc(var(--gap) * 2 + 48px); right: var(--gap); bottom: calc(var(--gap) * 2 + 108px); width: var(--panel-w); border-radius: 22px; z-index: 4;
  display: flex; flex-direction: column; overflow: hidden; transform-origin: right center; transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .25s; }
body:not(.panel-open) #panel { transform: translateX(calc(100% + 30px)); opacity: 0; pointer-events: none; }

.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: transparent; padding: 9px 2px 10px; border-radius: 10px 10px 0 0; color: var(--ink-faint); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; transition: color .2s, background .2s; }
.tab svg { width: 18px; height: 18px; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: #fff; background: rgba(255,255,255,.05); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 14%; right: 14%; bottom: -1px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2)); box-shadow: 0 0 12px var(--accent); }

.tabbody { flex: 1; overflow-y: auto; padding: 14px 16px 18px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.tabbody::-webkit-scrollbar { width: 8px; } .tabbody::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 8px; }
.pane { animation: paneIn .28s ease both; }
.lite .pane { animation: none; }
@keyframes paneIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h2.sec { margin: 18px 0 10px; font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-faint); font-weight: 700; display: flex; align-items: center; gap: 8px; }
h2.sec:first-child { margin-top: 2px; }
h2.sec::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line), transparent); }

.hero { padding: 12px 14px; border-radius: 14px; background: linear-gradient(135deg, rgba(10,8,22,.55), rgba(10,8,22,.55)), linear-gradient(135deg, color-mix(in srgb, var(--accent) 20%, transparent), color-mix(in srgb, var(--accent2) 12%, transparent)); border: 1px solid var(--line); margin-bottom: 4px; }
.hero h3 { margin: 0 0 3px; font-size: 17px; letter-spacing: .02em; }
.hero p { margin: 0; color: var(--ink-dim); font-size: 12.5px; }

/* ---------- controls ---------- */
.ctl { margin: 0 0 13px; }
.ctl[hidden] { display: none; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1px; gap: 8px; }
.ctl-head label { font-size: 12.5px; color: var(--ink-dim); cursor: default; user-select: none; }
.ctl-head output { font: 12px var(--mono); color: var(--accent2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ctl small { display: block; color: var(--ink-faint); font-size: 11.5px; margin-top: 3px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: transparent; --p: 50%; cursor: pointer; }
input[type=range]:disabled { opacity: .4; cursor: not-allowed; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--accent) var(--p), rgba(255,255,255,.13) var(--p)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent), 0 2px 8px rgba(0,0,0,.5); transition: transform .15s, box-shadow .15s; }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.3); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 40%, transparent), 0 2px 8px rgba(0,0,0,.5); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.13); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
input[type=range]:focus-visible { outline: 2px solid var(--accent2); outline-offset: 3px; border-radius: 6px; }

.seg { display: flex; padding: 3px; border-radius: 11px; background: rgba(255,255,255,.06); gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 4px; font-size: 12px; border-radius: 8px; color: var(--ink-dim); transition: background .2s, color .2s; white-space: nowrap; }
.seg button:hover { color: #fff; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #0a0814; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: rgba(255,255,255,.05); border-radius: 999px; padding: 5px 11px; font-size: 12px; color: var(--ink); transition: background .2s, border-color .2s, transform .15s; }
.chip:hover { background: color-mix(in srgb, var(--accent) 28%, transparent); border-color: color-mix(in srgb, var(--accent) 60%, transparent); transform: translateY(-1px); }
.chip:active { transform: scale(.96); }

.btn { border: 1px solid var(--line); background: rgba(255,255,255,.07); border-radius: 11px; padding: 8px 12px; font-size: 12.5px; font-weight: 600; transition: background .2s, transform .15s; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn:hover { background: rgba(255,255,255,.14); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #0a0814; border: 0; }
.btn.primary:hover { filter: brightness(1.1); }
.btn svg { width: 16px; height: 16px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 13px; }
.btn-row.one { grid-template-columns: 1fr; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
.switch-row span { font-size: 12.5px; color: var(--ink-dim); }
.switch { position: relative; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.14); transition: background .25s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .25s cubic-bezier(.3,1.4,.5,1); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(17px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent2); outline-offset: 2px; }

select { width: 100%; appearance: none; -webkit-appearance: none; background: rgba(255,255,255,.07) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23aaa' stroke-width='2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 32px 8px 11px; font-size: 13px; }
select option { background: #15122a; color: var(--ink); }
.field-label { display: block; font-size: 12.5px; color: var(--ink-dim); margin-bottom: 6px; }

.pals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.pal { height: 34px; border-radius: 9px; border: 2px solid transparent; padding: 0; position: relative; overflow: hidden; transition: transform .15s, border-color .2s, box-shadow .2s; }
.pal:hover { transform: translateY(-2px); }
.pal[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent), 0 6px 18px -6px var(--accent); }
.pal span { position: absolute; inset: auto 0 0 0; font-size: 9.5px; text-transform: uppercase; letter-spacing: .1em; text-align: center; background: rgba(0,0,0,.45); padding: 1px 0; opacity: 0; transition: opacity .2s; }
.pal:hover span, .pal[aria-pressed="true"] span { opacity: 1; }
.pal.dice { grid-column: 1 / -1; height: 32px; background: rgba(255,255,255,.07); display: flex; gap: 8px; align-items: center; justify-content: center; border: 2px dashed var(--line); font-size: 12px; font-weight: 600; color: var(--ink-dim); }
.pal.dice span { position: static; opacity: 1; background: none; font-size: 12px; text-transform: none; letter-spacing: 0; padding: 0; }
.pal.dice:hover { color: #fff; border-color: var(--accent); }
.pal.dice svg { width: 18px; height: 18px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; color: var(--ink-dim); margin: 0 0 12px; }
.kv b { color: var(--ink); font-weight: 600; text-align: right; font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; }
.note { font-size: 12px; color: var(--ink-faint); margin: 0 0 12px; }

/* ---------- dock ---------- */
#dock { position: fixed; left: var(--gap); bottom: var(--gap); right: var(--gap); display: flex; gap: 8px; padding: 8px; border-radius: 22px; z-index: 4; overflow-x: auto; scrollbar-width: none; transition: right .35s cubic-bezier(.2,.8,.2,1); }
#dock::-webkit-scrollbar { display: none; }
body.panel-open #dock { right: calc(var(--panel-w) + var(--gap) * 2); }
.card { flex: 1 0 84px; max-width: 150px; height: 84px; border: 2px solid transparent; border-radius: 14px; position: relative; overflow: hidden; padding: 0; background: #120f26; transition: transform .2s, border-color .25s, box-shadow .25s; }
.card:hover { transform: translateY(-3px); }
.card .thumb { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; font-weight: 800; color: rgba(255,255,255,.55); background: linear-gradient(135deg, var(--c1, #2a1a5a), var(--c2, #0c0a1c)); }
.card .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; animation: fadeIn .6s both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.card .name { position: absolute; inset: auto 0 0 0; padding: 14px 8px 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; text-align: left; background: linear-gradient(0deg, rgba(5,4,14,.92), transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .key { position: absolute; top: 5px; right: 6px; font: 600 10px var(--mono); color: rgba(255,255,255,.65); background: rgba(0,0,0,.4); padding: 1px 5px; border-radius: 5px; }
.card[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 26px -8px var(--accent); }

/* ---------- HUD, toasts ---------- */
#hud { position: fixed; top: calc(var(--gap) * 2 + 48px); left: var(--gap); padding: 9px 13px; border-radius: 14px; font: 11.5px/1.55 var(--mono); color: var(--ink-dim); z-index: 3; pointer-events: none; min-width: 240px; }
#hud b { color: var(--ink); font-weight: 600; }
#hud .zoom { font-size: 20px; font-weight: 700; color: var(--accent2); letter-spacing: .02em; line-height: 1.2; display: block; }
#hud .state { color: var(--accent); }
#hud.off { display: none; }

#toasts { position: fixed; left: 50%; top: calc(var(--gap) * 2 + 48px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 20; pointer-events: none; }
.toast { padding: 9px 16px; border-radius: 999px; font-size: 13px; animation: toastIn .35s cubic-bezier(.2,1.2,.3,1) both; max-width: 86vw; text-align: center; }
.toast.out { animation: toastOut .35s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

#unhide { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); display: none; z-index: 8; border: 0; border-radius: 999px; padding: 7px 14px; font-size: 12px; background: rgba(10,8,22,.55); color: var(--ink-dim); opacity: .0; transition: opacity .3s; }
body.ui-hidden #unhide { display: block; }
body.ui-hidden #unhide:hover, body.ui-hidden #unhide:focus-visible { opacity: 1; }
body.ui-hidden #panel, body.ui-hidden #dock, body.ui-hidden #toolbar, body.ui-hidden #hud, body.ui-hidden #brand, body.ui-hidden #shade { display: none; }

/* ---------- splash / errors / dialog ---------- */
#splash { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 18px; background: radial-gradient(circle at 50% 45%, #1a1038, #07060f 70%); transition: opacity .8s ease, visibility .8s; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; color: var(--ink-dim); }
body.ready #splash { opacity: 0; visibility: hidden; }
.orb { width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(from 0deg, var(--accent), var(--accent2), var(--accent)); -webkit-mask: radial-gradient(circle, transparent 56%, #000 58%); mask: radial-gradient(circle, transparent 56%, #000 58%); animation: spin 1.2s linear infinite; filter: drop-shadow(0 0 14px var(--accent)); }
@keyframes spin { to { transform: rotate(360deg); } }
#nogl { position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; padding: 30px; text-align: center; background: #07060f; max-width: none; }
#nogl[hidden] { display: none; }
#nogl p { max-width: 520px; color: var(--ink-dim); }

dialog { color: var(--ink); border-radius: 22px; padding: 22px 26px; max-width: min(560px, 92vw); }
dialog::backdrop { background: rgba(4,3,10,.6); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 14px; letter-spacing: .04em; }
.help-grid { display: grid; gap: 7px; }
.help-grid div { display: flex; justify-content: space-between; gap: 18px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.help-grid b { color: var(--accent2); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.help-grid span { color: var(--ink-dim); text-align: right; }
.help-note { color: var(--ink-dim); font-size: 12.5px; margin: 14px 0 18px; }

/* ---------- small screens: panel becomes a sheet, dock goes on top ---------- */
@media (max-width: 760px) {
  :root { --gap: 10px; }
  #brand { padding: 5px 12px 5px 7px; } #brand .logo { width: 26px; height: 26px; } #brand > div { display: none; } #brand { padding: 5px; }
  #toolbar { top: var(--gap); padding: 3px; } .ibtn { width: 34px; height: 34px; } #b-help, #b-hide { display: none; }
  body.panel-open #toolbar { right: var(--gap); }
  #dock { top: calc(var(--gap) + 52px); bottom: auto; left: var(--gap); right: var(--gap) !important; padding: 5px; border-radius: 16px; }
  .card { flex: 0 0 82px; height: 58px; } .card .key { display: none; } .card .name { font-size: 10px; padding: 8px 5px 3px; } .card .thumb { font-size: 20px; }
  #panel { top: auto; left: var(--gap); right: var(--gap); bottom: var(--gap); width: auto; height: min(52vh, 460px); border-radius: 22px; transform-origin: bottom center; }
  body:not(.panel-open) #panel { transform: translateY(calc(100% + 30px)); }
  #hud { top: calc(var(--gap) + 52px + 70px); font-size: 10.5px; min-width: 0; padding: 6px 10px; } #hud .zoom { font-size: 15px; }
  #toasts { top: auto; bottom: calc(var(--gap) + 12px); }
  body.panel-open #toasts { bottom: calc(min(52vh, 460px) + 20px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
