:root {
  --ink: #e8e4d8;
  --muted: #9a9486;
  --dim: #6b665c;
  --line: rgba(232, 228, 216, 0.14);
  --glass: rgba(8, 10, 14, 0.55);
  --glass-strong: rgba(6, 8, 12, 0.78);
  --accent: #c9b48a;
  --danger: #d4a574;
  --ui: "IBM Plex Mono", ui-monospace, monospace;
  --serif: "Cormorant Garamond", "Times New Roman", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #05060a; color: var(--ink); font-family: var(--ui); }
button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }

#sky {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
}

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  background:
    radial-gradient(ellipse at center, transparent 46%, rgba(0,0,0,0.55) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.28), transparent 18%, transparent 78%, rgba(0,0,0,0.45));
  transition: opacity 1.2s ease;
}
body.deep #vignette { opacity: 0.35; }

#grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 3; opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.hud {
  position: fixed; z-index: 8;
  backdrop-filter: blur(16px) saturate(120%);
  background: var(--glass);
  border: 1px solid var(--line);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
body.deep .hud { opacity: 0; pointer-events: none; transform: translateY(8px); }
body.deep #topbar { opacity: 0.0; }

#topbar {
  top: 22px; left: 22px; right: 22px;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-radius: 16px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.glyph { color: var(--accent); font-size: 20px; }
.brand strong { display: block; font-family: var(--serif); font-size: 20px; font-weight: 500; letter-spacing: 0.02em; }
.brand em { display: block; font-style: normal; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.top-meta { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }
.sep { margin: 0 10px; opacity: 0.4; }

#port, #starboard {
  position: fixed; z-index: 8;
  top: 96px; bottom: 96px;
  display: flex; flex-direction: column; gap: 12px;
  pointer-events: none;
}
#port { left: 22px; width: min(340px, calc(100vw - 44px)); }
#starboard { right: 22px; width: min(320px, calc(100vw - 44px)); }
#port > .hud, #starboard > .hud {
  position: relative; top: auto; right: auto; bottom: auto; left: auto;
  width: auto; pointer-events: auto;
}

#lore {
  padding: 22px 22px 18px; border-radius: 18px;
  flex: 0 1 auto; overflow: auto; min-height: 0;
}
.panel-kicker {
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 8px;
}
#chamberTitle {
  font-family: var(--serif); font-weight: 500; font-size: 34px; line-height: 0.95;
  margin-bottom: 14px;
}
.lore-text {
  font-family: var(--serif); font-size: 17px; line-height: 1.45; color: #d7d1c4;
  font-style: italic; margin-bottom: 18px;
}
.lore-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px;
  border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 14px;
}
.lore-stats label { display: block; font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
.lore-stats span { font-size: 11px; color: var(--ink); }

.ghost, #controls button, #enterBtn, .modal-card button {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  padding: 8px 12px; border-radius: 999px; font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ghost:hover, #controls button:hover, #enterBtn:hover, .modal-card button:hover {
  border-color: var(--accent); color: var(--accent);
}
.ghost.pinned { border-color: var(--accent); color: var(--accent); }

#dock {
  padding: 14px; border-radius: 18px;
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
}
body.optics-on #dock {
  flex: 0 0 50%;
  max-height: 50%;
}
.dock-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip, .text-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 4px 9px; border-radius: 999px; font-size: 10px; letter-spacing: 0.08em;
  text-transform: uppercase; cursor: pointer;
}
.chip.active, .chip:hover, .text-btn:hover { border-color: var(--accent); color: var(--accent); }
#optics {
  padding: 14px; border-radius: 18px;
  flex: 1 1 50%; max-height: 50%; overflow: auto; min-height: 0;
}
body.optics-off #optics { display: none; }
body.optics-on #opticsBtn { border-color: var(--accent); color: var(--accent); }
#prism {
  padding: 14px; border-radius: 18px;
  flex: 0 1 auto; overflow: auto; min-height: 0;
}
body:not(.prism-on) #prism { display: none; }
body.prism-on #prismBtn { border-color: var(--accent); color: var(--accent); }
body.prism-on #lore { flex: 0 0 auto; max-height: 22%; }
body.prism-on #prism { flex: 1 1 auto; }
.group-label {
  margin: 10px 0 6px;
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim);
}
.group-label:first-of-type { margin-top: 2px; }
.mode-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.julia-pane { display: none; }
body.prism-julia2 #julia2Pane, body.prism-mandel #julia2Pane { display: block; }
body.prism-mandel3 #mandel3Pane { display: block; }
#prismLooks { margin: 8px 0 6px; }
body[data-prism="off"] #prismLooks { display: none; }
#prism .ctrl label, #optics .ctrl label { font-size: 9px; }
.optics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
#optics .ctrl label { font-size: 8px; }
.text-btn { padding: 0; border: 0; letter-spacing: 0.04em; text-transform: none; color: var(--dim); }
.life-head { margin-top: 10px; align-items: center; }
.life-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.dock-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px; white-space: nowrap;
}
.dock-head .hint { letter-spacing: 0.04em; text-transform: none; font-size: 9px; color: var(--dim); max-width: 58%; overflow: hidden; text-overflow: ellipsis; }
.dock-cards { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-right: 4px; flex: 1; min-height: 140px; }
.dock-cards::-webkit-scrollbar { width: 4px; }
.dock-cards::-webkit-scrollbar-thumb { background: rgba(201,180,138,0.28); border-radius: 4px; }
.card.hidden { display: none; }
.card {
  display: grid; grid-template-columns: 84px 1fr; gap: 10px; align-items: center;
  padding: 6px; border-radius: 12px; border: 1px solid transparent; cursor: pointer;
  background: rgba(255,255,255,0.03);
}
.card img { width: 84px; height: 48px; object-fit: cover; border-radius: 8px; display: block; }
.card b { display: block; font-family: var(--serif); font-weight: 500; font-size: 16px; }
.card small { color: var(--muted); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.card:hover { border-color: var(--line); }
.card.active { border-color: var(--accent); background: rgba(201,180,138,0.08); }
.card .pin { color: var(--accent); font-size: 11px; }

#controls {
  left: 22px; right: 22px; bottom: 22px;
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  padding: 14px 18px; border-radius: 16px;
}
#controls .ctrl { min-width: 150px; flex: 1 1 180px; }
.ctrl { min-width: 140px; flex: 1; }
#controls .ctrl-actions { flex: 0 0 auto; margin-left: auto; }
.ctrl label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.ctrl label .val { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; color: var(--text, #e8eefc); opacity: 0.8; text-transform: none; }
.ctrl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctrl-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#help {
  left: 50%; bottom: 96px; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; font-size: 11px; color: var(--muted);
  opacity: 0; animation: fadeHelp 6s ease forwards;
}
@keyframes fadeHelp {
  0%, 12% { opacity: 0; }
  20%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

#boot {
  position: fixed; inset: 0; z-index: 20;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(90,110,130,0.18), transparent 40%),
    #05060a;
  display: grid; place-items: center; text-align: center;
  transition: opacity 0.9s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }
.boot-kicker { letter-spacing: 0.28em; text-transform: uppercase; font-size: 11px; color: var(--accent); margin-bottom: 16px; }
#boot h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(42px, 8vw, 84px); line-height: 0.9; }
.boot-sub { margin-top: 14px; font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--muted); }
.boot-bar { width: min(320px, 70vw); height: 1px; background: var(--line); margin: 28px auto 12px; overflow: hidden; }
.boot-bar span { display: block; height: 100%; width: 0; background: var(--accent); animation: load 2.4s ease forwards; }
@keyframes load { to { width: 100%; } }
.boot-status { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); min-height: 16px; }
.boot-status.fail { color: #d4a574; letter-spacing: 0.08em; text-transform: none; }
.boot-help {
  margin: 16px auto 0; width: min(520px, 84vw); text-align: left;
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font-size: 12px; line-height: 1.55;
  color: #d7d1c4; white-space: pre-wrap;
}
.boot-help.hidden { display: none; }
#enterBtn { margin-top: 22px; padding: 12px 22px; opacity: 0.4; }
#enterBtn:not(:disabled) { opacity: 1; }

body.guest-mode #optics input[type=range],
body.guest-mode #prism input[type=range],
body.guest-mode #prismLooks,
body.guest-mode #resetLook,
body.guest-mode #shotBtn {
  pointer-events: none;
  opacity: 0.38;
  filter: grayscale(0.35);
}
body.guest-mode #shotBtn { cursor: not-allowed; }
.gate-card { text-align: center; max-width: 420px; }
.gate-card h3 { font-family: var(--serif); font-weight: 500; font-size: 32px; margin: 6px 0 10px; }
.gate-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.gate-actions button { min-width: 140px; padding: 12px 18px; }
.gate-primary { border-color: var(--accent); color: var(--accent); }
#gateNote:empty { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,0.55); display: grid; place-items: center;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(520px, calc(100vw - 40px));
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px; backdrop-filter: blur(20px);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-card h3 { font-family: var(--serif); font-size: 28px; font-weight: 500; }
.modal-note { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
textarea {
  width: 100%; min-height: 160px; resize: vertical; background: rgba(0,0,0,0.35);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; line-height: 1.5;
}
.modal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 11px; color: var(--muted); }

#flash {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; background: #fff;
  opacity: 0; transition: opacity 0.12s linear;
}
#flash.pop { opacity: 0.55; }

body.ui-hidden .hud { opacity: 0; pointer-events: none; }

@media (max-width: 900px) {
  #port { display: none; }
  #starboard { left: 12px; right: 12px; width: auto; top: auto; bottom: 118px; height: 168px; }
  #optics { display: none; }
  #dock { max-height: none; }
  .dock-cards { flex-direction: row; overflow-x: auto; min-height: 0; }
  .card { min-width: 210px; }
  #controls { gap: 12px; }
  #topbar { left: 12px; right: 12px; top: 12px; }
}


#row3d { display: none; }
body.prism-tab-3d #row2d { display: none; }
body.prism-tab-3d #row3d { display: flex; }
#prismLooks { position: relative; z-index: 5; pointer-events: auto; display: flex; flex-wrap: wrap; gap: 6px; }
body[data-prism="off"] #prismLooks { display: none; }
#prismLooks .chip { min-width: 34px; pointer-events: auto; position: relative; z-index: 6; }
#tab2d, #tab3d { pointer-events: auto; }
body.prism-tab-3d #tab3d, body:not(.prism-tab-3d) #tab2d { border-color: var(--accent); color: var(--accent); }
body.prism-3d #mandel3Pane { display: block; }

body.prism-3d .only-2d { display: none !important; }

.tumble-only { display: none; }
body.tumble-on .tumble-only { display: grid; }

.brand-mark {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin: 0 auto 18px;
  mix-blend-mode: screen;
}
.brand-mark-sm {
  width: 36px;
  height: 36px;
  margin: 0 10px 0 0;
  flex: 0 0 36px;
}
.brand { display: flex; align-items: center; }
#gate { z-index: 40; }
#gate .brand-mark { width: 84px; height: 84px; margin-bottom: 14px; }

#tipjarBtn.tipjar,
#paypalBtn.tipjar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 12;
  pointer-events: auto;
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid rgba(201,180,138,0.45);
  background: rgba(201,180,138,0.10);
  color: #e8d7b0;
  border-radius: 999px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
}
#tipjarBtn.tipjar:hover,
#paypalBtn.tipjar:hover {
  border-color: rgba(201,180,138,0.85);
  background: rgba(201,180,138,0.18);
  color: #f3ead6;
}
#tipjarBtn.tipjar svg,
#paypalBtn.tipjar svg { opacity: 0.95; flex: 0 0 14px; }
.ctrl-actions { position: relative; z-index: 12; pointer-events: auto; }

#igBtn.tipjar.ig {
  border-color: rgba(140, 190, 220, 0.5);
  background: rgba(120, 176, 214, 0.12);
  color: #c8dff0;
}
#igBtn.tipjar.ig:hover {
  border-color: rgba(170, 214, 240, 0.9);
  background: rgba(120, 176, 214, 0.22);
  color: #e7f4fb;
}
