:root {
  --bg: #000;
  --glass: rgba(14, 17, 26, 0.72);
  --glass-strong: rgba(14, 17, 26, 0.9);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf6;
  --muted: #8d96ab;
  --accent: #f2b84b;
  --accent-ink: #1a1203;
  --accent-soft: rgba(242, 184, 75, 0.16);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --top: 64px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased;
  overscroll-behavior: none; touch-action: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }

#gl, #overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#gl { cursor: grab; touch-action: none; }
#gl.grabbing { cursor: grabbing; }
#overlay { pointer-events: none; }

body.hide-ui .ui { opacity: 0; pointer-events: none; }
.exit-full {
  display: none; position: fixed; z-index: 40; width: 40px; height: 40px; border-radius: 50%;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  border: 1px solid var(--line-strong); background: rgba(10,12,18,0.55); color: var(--text); opacity: 0.7;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.exit-full svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.exit-full:hover { opacity: 1; }
body.hide-ui .exit-full { display: grid; place-items: center; }
.ui { transition: opacity 0.25s ease, transform 0.25s ease; }

/* ---------- Loading ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center; background: #000; z-index: 50; transition: opacity 0.6s; }
.loading.done { opacity: 0; pointer-events: none; }
.loading p { color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; font-size: 11px; text-align: center; margin-top: 18px; }
.hexes { position: relative; width: 64px; height: 56px; margin: auto; }
.hexes i { position: absolute; width: 18px; height: 20px; background: var(--accent); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); animation: pulse 1.4s infinite ease-in-out; }
.hexes i:nth-child(1) { left: 23px; top: 0; }
.hexes i:nth-child(2) { left: 4px; top: 11px; animation-delay: .1s; }
.hexes i:nth-child(3) { left: 42px; top: 11px; animation-delay: .2s; }
.hexes i:nth-child(4) { left: 23px; top: 22px; animation-delay: .3s; }
.hexes i:nth-child(5) { left: 4px; top: 33px; animation-delay: .4s; }
.hexes i:nth-child(6) { left: 42px; top: 33px; animation-delay: .5s; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); height: 48px; z-index: 10;
  display: flex; align-items: center; gap: 12px; padding: 0 8px 0 14px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
}
.brand-wrap { position: relative; }
.brand {
  display: flex; align-items: center; gap: 8px; font-size: 15px; letter-spacing: 0.01em; white-space: nowrap;
  border: 0; background: transparent; padding: 6px 8px; margin-left: -8px; border-radius: 10px;
}
.brand:hover, .brand[aria-expanded=true] { background: rgba(255,255,255,0.07); }
.brand .caret { width: 12px; height: 12px; color: var(--muted); transition: transform .15s; }
.brand[aria-expanded=true] .caret { transform: rotate(180deg); }
.mission-menu {
  position: absolute; top: 46px; left: -8px; z-index: 20; width: 320px; padding: 6px;
  background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 14px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: 0 20px 50px rgba(0,0,0,.55);
}
.mission { display: grid; grid-template-columns: 1fr auto; gap: 1px 10px; padding: 9px 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.mission:hover { background: rgba(255,255,255,0.07); }
.mission.current { background: var(--accent-soft); }
.mission .m-title { font-size: 14px; font-weight: 600; }
.mission .m-title b { color: var(--accent); }
.mission .m-count { grid-row: 1; grid-column: 2; align-self: center; font: 11px var(--mono); color: var(--muted); }
.mission .m-blurb { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); }
.brand svg { width: 20px; height: 20px; color: var(--accent); }
.brand b { color: var(--accent); font-weight: 700; }

.seg { display: flex; background: rgba(255,255,255,0.06); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.seg button:not(.active):hover { color: var(--text); }

.search { position: relative; flex: 1; max-width: 460px; min-width: 120px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 34px; padding: 0 12px 0 32px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.05); outline: none;
}
.search input:focus { border-color: var(--accent); background: rgba(255,255,255,0.08); }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 60vh; overflow: auto; padding: 6px;
  background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 12px;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.result { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; }
.result:hover, .result.sel { background: rgba(255,255,255,0.08); }
.result img { width: 48px; height: 36px; object-fit: cover; border-radius: 5px; background: #111; flex: none; }
.result .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .s { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result > div { min-width: 0; }

.tools { display: flex; gap: 2px; margin-left: auto; }
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 52px; height: 40px; border: 0; background: transparent; border-radius: 10px; color: var(--muted);
}
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool span { font-size: 10px; letter-spacing: .02em; }
.tool:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.tool.on { color: var(--accent); background: var(--accent-soft); }

/* ---------- Drawers ---------- */
.drawer {
  position: fixed; top: calc(var(--top) + 8px); bottom: 12px; width: 340px; z-index: 9;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer.left { left: 12px; }
.drawer.right { right: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.head-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { border: 0; background: transparent; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; }
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line-strong); background: rgba(255,255,255,0.04);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; color: var(--text); text-decoration: none; white-space: nowrap;
}
.chip:hover { background: rgba(255,255,255,0.09); }
.chip.on, .chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip:disabled { opacity: .4; cursor: default; }
.btn { border: 1px solid var(--line-strong); background: rgba(255,255,255,0.06); padding: 9px 14px; border-radius: 10px; font-weight: 600; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.field, select {
  height: 32px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); padding: 0 10px; outline: none;
}
.field:focus, select:focus { border-color: var(--accent); }
select option { background: #151925; }
.link { border: 0; background: transparent; color: var(--muted); font-size: 11px; padding: 2px 4px; }
.link:hover { color: var(--accent); }

/* Gallery */
.filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
#gallery-search { margin: 0 14px 10px; }
.gallery-list { flex: 1; overflow: auto; padding: 0 10px 14px; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: max-content; gap: 8px; align-content: start; }
.card { border: 0; padding: 0; background: rgba(255,255,255,0.04); border-radius: 10px; overflow: hidden; text-align: left; display: flex; flex-direction: column; }
.card:hover { background: rgba(255,255,255,0.09); }
.card.current { outline: 2px solid var(--accent); }
.card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #0b0d12; display: block; }
.card .t { padding: 6px 8px 0; font-size: 11.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { padding: 2px 8px 7px; font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sky-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #6fa8ff; margin-right: 4px; vertical-align: 1px; }

/* Adjust panel */
#adjust { width: 320px; }
.hist-wrap { margin: 0 14px 8px; position: relative; background: rgba(0,0,0,0.35); border-radius: 10px; border: 1px solid var(--line); }
.hist { display: block; width: 100%; height: 90px; }
.hist-legend { display: flex; justify-content: space-between; padding: 0 8px 4px; font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.preset-row { display: flex; gap: 8px; padding: 0 14px 6px; align-items: center; }
.preset-row select { flex: 1; }
.sections { flex: 1; overflow: auto; padding: 0 6px 6px; }
.section { border-top: 1px solid var(--line); }
.section summary { list-style: none; display: flex; justify-content: space-between; align-items: center; padding: 10px 8px; cursor: pointer; font-weight: 650; user-select: none; }
.section summary::-webkit-details-marker { display: none; }
.section summary span::before { content: '▸'; display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; }
.section[open] summary span::before { transform: rotate(90deg); }
.section .body { padding: 0 8px 10px; }
.panel-foot { padding: 10px 14px 14px; border-top: 1px solid var(--line); }

.slider { margin-bottom: 7px; }
.slider-top { display: flex; justify-content: space-between; align-items: center; }
.slider label { color: #c3c9d8; font-size: 12px; cursor: default; user-select: none; }
.slider.changed label { color: var(--text); }
.slider .val {
  width: 66px; text-align: right; background: transparent; border: 1px solid transparent; border-radius: 6px;
  font: 11.5px var(--mono); color: var(--muted); padding: 1px 4px; outline: none;
}
.slider.changed .val { color: var(--accent); }
.slider .val:focus { border-color: var(--line-strong); color: var(--text); }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer;
  --a: 50%; --b: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,.14) var(--a), var(--accent) var(--a), var(--accent) var(--b), rgba(255,255,255,.14) var(--b));
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.14); }
input[type=range]::-moz-range-progress { height: 4px; background: transparent; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; margin-top: -5px;
  background: #f4f6fb; border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.6);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #f4f6fb; border: 0; }
input[type=range].track-temp::-webkit-slider-runnable-track { background: linear-gradient(90deg, #4c8dff, #d7dbe6, #ffb347); }
input[type=range].track-tint::-webkit-slider-runnable-track { background: linear-gradient(90deg, #3fd37c, #d7dbe6, #e05ad2); }
input[type=range].track-hue::-webkit-slider-runnable-track { background: linear-gradient(90deg, #0ff, #00f, #f0f, #f00, #ff0, #0f0, #0ff); }

.toggles { display: flex; gap: 14px; padding-top: 4px; }
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.curves { margin-bottom: 4px; }
.curve-tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.curve-tabs button { flex: 1; border: 1px solid var(--line); background: rgba(255,255,255,0.04); border-radius: 7px; padding: 3px 0; font-weight: 700; font-size: 11px; }
.curve-tabs button.active { border-color: currentColor; background: rgba(255,255,255,0.1); }
.curve-tabs .ch-r { color: #ff7a7a; } .curve-tabs .ch-g { color: #63e39a; } .curve-tabs .ch-b { color: #7fb0ff; }
canvas.curve { width: 100%; aspect-ratio: 1; display: block; border-radius: 8px; border: 1px solid var(--line); touch-action: none; cursor: crosshair; }
.hint { margin: 6px 0 0; font-size: 10.5px; color: var(--muted); }

/* ---------- Info card ---------- */
.info {
  position: fixed; left: calc(12px + env(safe-area-inset-left)); bottom: calc(12px + env(safe-area-inset-bottom)); width: min(400px, calc(100vw - 24px)); z-index: 8; padding: 12px 14px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
}
body.gallery-open .info { left: 364px; width: min(400px, calc(100vw - 388px)); }
.info-head { display: flex; justify-content: space-between; gap: 8px; }
.kicker { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.info h3 { margin: 2px 0 8px; font-size: 14.5px; line-height: 1.3; font-weight: 650; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 8px; font-size: 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
#info-desc-wrap summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
#info-desc { margin: 0 0 8px; max-height: 26vh; overflow: auto; color: #c7cddb; font-size: 12.5px; white-space: pre-line; }
.info-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; right: calc(12px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 8; display: flex; gap: 14px; align-items: center;
  padding: 7px 12px; border-radius: 10px; background: var(--glass); border: 1px solid var(--line);
  font: 11.5px var(--mono); color: #b9c1d3; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
body.adjust-open .hud { right: 344px; }
.hud span:empty { display: none; }
.busy { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); }
.busy i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 300px; padding: 6px 9px; border-radius: 8px;
  background: rgba(8,10,16,0.92); border: 1px solid var(--line-strong); font-size: 12px; line-height: 1.35;
}
.tooltip .s { color: var(--muted); font-size: 11px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0,0,0,0.55); padding: 16px; }
.modal-card { width: min(760px, 100%); max-height: 90vh; overflow: auto; background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 18px; backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; padding: 4px 20px 20px; }
.help-grid h4 { margin: 12px 0 6px; color: var(--accent); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.help-grid ul { margin: 0; padding-left: 18px; color: #c7cddb; }
.help-grid li { margin: 3px 0; }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 3px 0; color: #c7cddb; }
.keys td:first-child { width: 120px; }
kbd { font: 11px var(--mono); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: rgba(255,255,255,.06); margin-right: 2px; }
.field-row { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%); z-index: 25; padding: 8px 14px; border-radius: 10px;
  background: var(--glass-strong); border: 1px solid var(--line-strong); font-size: 12.5px; transition: opacity .3s;
}

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .tool span { display: none; }
  .tool { width: 38px; }
  #brand-name { display: none; }
  .help-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  /* Row 1: mission switcher + tools. Row 2: Mosaic/Sky + search. */
  .topbar { flex-wrap: wrap; height: auto; padding: 8px; gap: 8px; }
  .brand-wrap { order: 1; }
  .tools { order: 2; margin-left: auto; }
  .seg { order: 3; }
  .search { order: 4; max-width: none; flex: 1 1 160px; }
  .tool[data-act=home], .tool[data-act=help] { display: none; }
  .mission-menu { width: min(320px, calc(100vw - 32px)); }
  .tool { width: 34px; }
  :root { --top: calc(104px + env(safe-area-inset-top)); }
  .info { padding: 10px 12px; }
  .info .meta, #info-desc-wrap { display: none; }
  .info h3 { font-size: 13.5px; margin-bottom: 6px; }
  .drawer { left: 8px !important; right: 8px !important; width: auto !important; top: auto; height: 62vh; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .hud { display: none; }
  body.gallery-open .info, body.adjust-open .info { display: none; }
}
