:root {
  --bg: #14151c;
  --glass: rgba(18, 19, 27, 0.58);
  --glass-strong: rgba(18, 19, 27, 0.78);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #ece8e1;
  --muted: #a29d96;
  --dim: #6f6b66;
  --accent: #f2b880;
  --accent-soft: rgba(242, 184, 128, 0.16);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --panel-w: 304px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--sans); }
button { font: inherit; color: inherit; }

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl:active { cursor: grabbing; }

.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.38) 100%);
}

/* ---------- caption */
#caption {
  position: fixed; left: clamp(16px, 3.5vw, 44px); bottom: clamp(56px, 7vh, 84px);
  max-width: min(520px, calc(100vw - var(--panel-w) - 80px));
  pointer-events: none;
  text-shadow: 0 1px 18px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}
#caption.show { opacity: 1; transform: none; }
#caption .latin { font-family: var(--serif); font-style: italic; font-size: 14px; color: rgba(255, 255, 255, 0.72); letter-spacing: 0.02em; }
#caption h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(34px, 5vw, 58px); line-height: 1.02; margin: 4px 0 10px; letter-spacing: -0.01em; }
#caption p { margin: 0; font-size: 14.5px; line-height: 1.55; color: rgba(255, 255, 255, 0.82); max-width: 44ch; }

#hint {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 999px; font-size: 12px; color: rgba(255, 255, 255, 0.78);
  background: rgba(10, 10, 16, 0.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line); white-space: nowrap; pointer-events: none;
  max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
body:not(.panel-hidden) #hint { left: calc(50% - var(--panel-w) / 2); }

#toast {
  position: fixed; left: 50%; top: 22px; transform: translate(-50%, -8px);
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--glass-strong); border: 1px solid var(--line-strong); color: var(--accent);
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- panel */
#panel {
  position: fixed; top: 14px; right: 14px; bottom: 14px; width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--glass); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  transition: transform 0.4s cubic-bezier(.2, .8, .2, 1), opacity 0.3s;
  z-index: 5;
}
body.panel-hidden #panel { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--line); }
.logo { width: 30px; height: 30px; color: var(--accent); flex: none; }
.brand-text { flex: 1; min-width: 0; }
.brand .name { font-family: var(--serif); font-size: 21px; line-height: 1; letter-spacing: 0.01em; }
.brand .tag { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 3px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 9px; width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn svg, .fab svg { width: 18px; height: 18px; }

.scroll { flex: 1; overflow-y: auto; padding: 4px 14px 10px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
section { padding: 12px 2px; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }
h2 { font-size: 10.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin: 0 0 10px; }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 9px 10px 10px; border-radius: 12px; cursor: pointer;
  background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.preset:hover { background: rgba(255, 255, 255, 0.07); }
.preset:active { transform: scale(0.98); }
.preset.active { background: var(--accent-soft); border-color: rgba(242, 184, 128, 0.5); }
.preset-icon { width: 48px; height: 26px; color: var(--muted); margin-bottom: 2px; }
.preset.active .preset-icon { color: var(--accent); }
.preset-icon svg { width: 100%; height: 100%; display: block; }
.preset-name { font-size: 13.5px; font-weight: 600; }
.preset-blurb { font-size: 11px; color: var(--muted); line-height: 1.3; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.actions button, .seg button {
  padding: 7px 6px; border-radius: 9px; font-size: 12px; cursor: pointer;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); color: var(--text);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.actions button:hover, .seg button:hover { background: rgba(255, 255, 255, 0.1); }
.actions button.on { color: var(--accent); border-color: rgba(242, 184, 128, 0.5); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 12px; }
.seg button { font-size: 11.5px; padding: 6px 4px; }
.seg button.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(242, 184, 128, 0.45); }

.ctl { display: block; margin: 0 0 11px; }
.ctl[hidden] { display: none; }
.ctl-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; margin-bottom: 5px; }
.ctl-label { color: var(--text); opacity: 0.88; }
.ctl output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer; --p: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) 0 var(--p), rgba(255, 255, 255, 0.13) var(--p) 100%);
}
input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.13); }
input[type=range]::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; margin-top: -5.5px;
  background: #fff; border: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4); transition: transform 0.15s;
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4); }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }

.toggles { display: grid; gap: 4px; }
.tog { display: flex; align-items: center; gap: 10px; font-size: 12.5px; padding: 5px 2px; cursor: pointer; }
.tog[hidden] { display: none; }
.tog input { position: absolute; opacity: 0; pointer-events: none; }
.tog .sw { width: 30px; height: 17px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); position: relative; transition: background 0.2s; flex: none; }
.tog .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.tog input:checked + .sw { background: var(--accent); }
.tog input:checked + .sw::after { transform: translateX(13px); }
.tog input:focus-visible + .sw { box-shadow: 0 0 0 3px var(--accent-soft); }
.tog-label { flex: 1; opacity: 0.88; }
kbd {
  font-family: var(--sans); font-size: 10px; color: var(--muted); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.04);
}
.keys { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11px; color: var(--muted); }

.stats { display: flex; justify-content: space-between; padding: 10px 16px 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.fab {
  position: fixed; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 4;
}
body.panel-hidden .fab { opacity: 1; pointer-events: auto; }

#fallback { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--bg); }
#fallback[hidden] { display: none; }
#fallback h2 { font-family: var(--serif); font-size: 28px; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 400; }
#fallback p { color: var(--muted); }

@media (max-width: 720px) {
  :root { --panel-w: 100vw; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62vh; }
  body.panel-hidden #panel { transform: translateY(calc(100% + 24px)); }
  #caption { max-width: calc(100vw - 32px); bottom: 64px; }
  #caption p { display: none; }
  body:not(.panel-hidden) #hint { display: none; }
  #hint { left: 50% !important; font-size: 11px; }
}
