:root {
  --bg: #02030a;
  --glass: rgba(10, 13, 26, .72);
  --line: rgba(255, 255, 255, .09);
  --txt: #e8ecf8;
  --dim: #8b94b3;
  --accent: #ff9a3c;
  --accent2: #5fd4ff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); overflow: hidden;
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
canvas#gl.drag { cursor: grabbing; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; background: rgba(255,255,255,.06); color: var(--dim); }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(255,255,255,.07); padding: 1px 5px; border-radius: 4px; color: #ffd9a8; }

.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.45); }

#ui { position: fixed; inset: 0; pointer-events: none; transition: opacity .3s; }
#ui > * { pointer-events: auto; }
#ui.hidden > :not(#btnShow) { opacity: 0; pointer-events: none; }

/* top bar */
#top { position: absolute; top: 12px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
#top > * { pointer-events: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 8px 14px 8px 10px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); }
.brand b { display: block; font-size: 14px; letter-spacing: .04em; }
.brand small { color: var(--dim); font-size: 11px; }
.logo { width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 50%, #000 0 38%, #ffb25c 42%, #ff5d1a 55%, rgba(255,93,26,0) 72%);
  box-shadow: 0 0 14px rgba(255,140,50,.6); }
.top-btns { display: flex; gap: 8px; }
.ghost, .primary { border-radius: 999px; padding: 8px 14px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(14px); transition: .15s; }
.ghost:hover { border-color: rgba(255,255,255,.3); }
.primary { background: linear-gradient(135deg, #ff9a3c, #ff5d3c); border-color: transparent; color: #1a0b00; font-weight: 650; }
.primary:hover { filter: brightness(1.1); }
.primary.wide { flex: 1; }
.only-narrow { display: none; }

/* control panel */
#panel { position: absolute; top: 64px; left: 14px; bottom: 54px; width: 316px; overflow-y: auto; padding: 6px 14px 14px; scrollbar-width: thin; scrollbar-color: #3a4160 transparent; }
details { border-bottom: 1px solid var(--line); padding: 4px 0 10px; }
details:last-child { border-bottom: 0; }
summary { cursor: pointer; list-style: none; padding: 9px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); font-weight: 700; user-select: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "–"; float: right; color: var(--dim); }
details:not([open]) summary::after { content: "+"; }

.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 8px 0; }
.row span { color: var(--dim); }
.row small { opacity: .7; }
.row output { font: 12px ui-monospace, monospace; color: var(--txt); text-align: right; }
.row input { grid-column: 1 / -1; }
.row.sel { grid-template-columns: 1fr; }
select { width: 100%; background: #10152a; color: var(--txt); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 7px 0; color: #cdd3ea; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, rgba(255,154,60,.9), rgba(255,255,255,.14) 0); background: rgba(255,255,255,.14); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.14); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -5.5px; border-radius: 50%; background: var(--accent); border: 2px solid #1a0b00; box-shadow: 0 0 8px rgba(255,154,60,.6); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid #1a0b00; }
input[type=range]:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; border-radius: 4px; }
input[type=range]:disabled { opacity: .35; }

.facts { margin: 8px 0 2px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 12px; }
.facts dt { color: var(--dim); } .facts dt i { font-style: normal; opacity: .6; font-size: 11px; margin-left: 2px; }
.facts dd { margin: 0; font-family: ui-monospace, monospace; text-align: right; color: var(--accent2); }

.btn-row { display: flex; gap: 8px; margin: 10px 0 4px; }
.btn-row .ghost { flex: 1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 6px 0 4px; }
.seg button { background: transparent; border: 0; padding: 8px 6px; color: var(--dim); }
.seg button.on { background: rgba(95,212,255,.16); color: var(--accent2); font-weight: 650; }
.seg button[data-kind="2"].on { background: rgba(255,214,120,.16); color: #ffd678; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chips button { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: #cdd3ea; transition: .15s; }
.chips button:hover { border-color: var(--accent); color: #fff; background: rgba(255,154,60,.12); }
.preview { margin: 8px 0 0; padding: 7px 10px; border-radius: 9px; font-size: 12px; background: rgba(255,255,255,.05); border-left: 3px solid var(--accent2); color: #cdd3ea; min-height: 34px; }
.preview.bad { border-color: #ff5d5d; } .preview.ok { border-color: #6bff9c; } .preview.mid { border-color: var(--accent); }

/* stats / hint */
#stats { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 14px; padding: 7px 14px; font-size: 12px; color: var(--dim); border-radius: 999px; }
#stats b { color: var(--txt); font-family: ui-monospace, monospace; font-weight: 600; }
#hint { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); padding: 8px 16px; border-radius: 999px; font-size: 12px; color: var(--dim); white-space: nowrap; transition: opacity 1s; pointer-events: none !important; }
#hint.gone { opacity: 0; }
#btnShow { position: absolute; top: 12px; right: 14px; }
#panel ~ #hint { max-width: calc(100vw - 720px); overflow: hidden; text-overflow: ellipsis; }

/* learn modal */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0,0,8,.55); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.sheet { width: min(900px, 100%); max-height: 100%; display: flex; flex-direction: column; background: rgba(12, 15, 30, .94); }
.sheet header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px 6px; }
.sheet h2 { margin: 0; font-size: 20px; }
.x { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--dim); padding: 0 6px; }
.x:hover { color: #fff; }
.tabs { display: flex; gap: 4px; padding: 6px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--dim); white-space: nowrap; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }
.tabbody { overflow-y: auto; padding: 4px 22px 22px; }
.tabbody section { display: none; } .tabbody section.on { display: block; }
.tabbody h3 { font-size: 18px; margin: 16px 0 6px; }
.tabbody p { color: #c3c9e0; font-size: 14px; line-height: 1.6; }
.tabbody b { color: #fff; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 14px 0; }
.card { padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,.045); border: 1px solid var(--line); }
.card h4 { margin: 0 0 4px; color: var(--accent2); font-size: 13px; }
.card p { margin: 0; font-size: 13px; }
.note { padding: 10px 14px; border-left: 3px solid var(--accent); background: rgba(255,154,60,.08); border-radius: 0 10px 10px 0; }
.try { padding-left: 20px; color: #c3c9e0; font-size: 14px; line-height: 1.6; } .try li { margin: 8px 0; }

#noGL { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--bg); padding: 24px; }
#noGL[hidden] { display: none; }

@media (max-width: 880px) {
  .only-narrow { display: inline-block; }
  .brand div { display: none; }
  .brand { padding: 8px; }
  .top-btns { gap: 6px; }
  .top-btns .ghost, .top-btns .primary { padding: 7px 10px; font-size: 12px; white-space: nowrap; }
  #panel { top: 62px; bottom: 56px; width: min(330px, calc(100vw - 28px)); transform: translateX(calc(-100% - 20px)); transition: transform .25s; z-index: 5; }
  #panel.open { transform: none; }
  #hint { display: none; }
  #stats { left: 14px; right: 14px; justify-content: space-between; gap: 6px; padding: 6px 12px; font-size: 11px; }
  #stats span:nth-child(n+4):not(:last-child) { display: none; }
  .tabbody { padding: 4px 16px 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
