/* style.css — dark glassy UI for the black hole simulator */
:root {
  --bg: #05060a;
  --panel: rgba(14, 18, 28, 0.72);
  --panel-solid: #0c0f17;
  --edge: rgba(120, 160, 220, 0.14);
  --edge-bright: rgba(140, 190, 255, 0.35);
  --txt: #d7e2f3;
  --txt-dim: #8595ad;
  --accent: #ff8a3c;     /* accretion orange */
  --accent2: #5db4ff;    /* relativistic blue */
  --accent-grad: linear-gradient(90deg, #ff7a2c, #ffd07a);
  --good: #6ee7a8;
  --warn: #ffce5a;
  font-size: 13px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--txt); overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
#glcanvas { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; cursor: grab; touch-action: none; }
#glcanvas:active { cursor: grabbing; }

/* ---------- loading / error ---------- */
#boot {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 50;
  background: radial-gradient(circle at 50% 40%, #0a0e18, #05060a 70%);
  transition: opacity 0.8s ease; gap: 18px;
}
#boot.hidden { opacity: 0; pointer-events: none; }
#boot .ring {
  width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent); border-right-color: var(--accent2);
  animation: spin 1.1s linear infinite;
}
#boot .title { font-size: 20px; letter-spacing: 3px; font-weight: 300; color: #cfe0f5; }
#boot .sub { font-size: 12px; color: var(--txt-dim); letter-spacing: 1px; }
#boot .err { color: #ff7676; max-width: 560px; text-align: center; line-height: 1.5; font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- control panel ---------- */
#panel {
  position: fixed; top: 14px; right: 14px; width: 320px;
  max-height: calc(100vh - 28px); overflow-y: auto; z-index: 20;
  background: var(--panel); backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--edge); border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.04);
  padding: 6px;
  scrollbar-width: thin; scrollbar-color: rgba(140,180,255,0.25) transparent;
}
#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb { background: rgba(140,180,255,0.22); border-radius: 8px; }
/* show/hide driven by body.nav-open (docked on desktop, drawer on mobile) */
#panel { transition: transform 0.3s cubic-bezier(0.4,0,0.2,1); transform: translateX(0); }
body:not(.nav-open) #panel { transform: translateX(calc(100% + 30px)); pointer-events: none; }

.panel-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 10px;
}
.panel-head .logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #000 30%, #ff8a3c 38%, #ffd07a 50%, transparent 62%);
  box-shadow: 0 0 14px rgba(255,150,70,0.6);
  flex: 0 0 auto;
}
.panel-head h1 { font-size: 14px; font-weight: 600; letter-spacing: 0.5px; margin: 0; flex: 1; }
.panel-head .mini { font-size: 15px; color: var(--txt-dim); background: none; border: none; cursor: pointer; padding: 4px 8px; border-radius: 7px; line-height: 1; font-family: inherit; }
.panel-head .mini:hover { color: #fff; background: rgba(255,255,255,0.08); }
.panel-sub { font-size: 10.5px; color: var(--txt-dim); padding: 0 10px 8px; line-height: 1.5; }

.section { border-top: 1px solid var(--edge); }
.section > .sec-head {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.4px;
  color: #c2d2ea;
}
.section > .sec-head:hover { color: #fff; }
.section > .sec-head .chev { margin-left: auto; transition: transform 0.2s; opacity: 0.6; font-size: 10px; }
.section.open > .sec-head .chev { transform: rotate(90deg); }
.section > .sec-head .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex:0 0 auto; }
.section .sec-body { display: none; padding: 2px 10px 12px; }
.section.open .sec-body { display: block; }

/* control rows */
.ctrl { margin: 9px 0; }
.ctrl .lbl { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.ctrl .lbl span:first-child { font-size: 11px; color: var(--txt-dim); }
.ctrl .lbl .val { font-size: 11px; color: var(--txt); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.ctrl .lbl .val b { color: var(--accent2); font-weight: 600; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent2) 0%, var(--accent2) var(--fill,50%), rgba(255,255,255,0.10) var(--fill,50%));
  outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #eaf1fb; border: 2px solid var(--accent2);
  box-shadow: 0 0 8px rgba(93,180,255,0.7); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #eaf1fb;
  border: 2px solid var(--accent2); box-shadow: 0 0 8px rgba(93,180,255,0.7); cursor: pointer;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; margin: 9px 0; }
.toggle-row span { font-size: 11px; color: var(--txt-dim); }
.switch { position: relative; width: 38px; height: 20px; flex: 0 0 auto; }
.switch input { display: none; }
.switch .track {
  position: absolute; inset: 0; border-radius: 20px; background: rgba(255,255,255,0.12);
  transition: background 0.2s; cursor: pointer;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #cdd8e8; transition: transform 0.2s;
}
.switch input:checked + .track { background: linear-gradient(90deg, #ff7a2c, #ffb05a); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }

select, button.btn {
  width: 100%; background: rgba(255,255,255,0.05); color: var(--txt);
  border: 1px solid var(--edge); border-radius: 8px; padding: 7px 9px; font-size: 11.5px;
  cursor: pointer; font-family: inherit;
}
select:hover, button.btn:hover { border-color: var(--edge-bright); background: rgba(255,255,255,0.08); }
button.btn.accent { background: linear-gradient(90deg, rgba(255,122,44,0.22), rgba(255,176,90,0.12)); border-color: rgba(255,150,70,0.5); color: #ffd9b3; }
button.btn.accent:hover { background: linear-gradient(90deg, rgba(255,122,44,0.34), rgba(255,176,90,0.2)); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* segmented band picker */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.seg-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--edge); border-radius: 7px;
  color: var(--txt-dim); padding: 6px 2px; font-size: 10px; cursor: pointer; font-family: inherit;
  transition: all 0.14s; text-align: center; letter-spacing: 0.2px;
}
.seg-btn:hover { border-color: var(--edge-bright); color: var(--txt); }
.seg-btn.active {
  background: linear-gradient(180deg, rgba(93,180,255,0.28), rgba(93,180,255,0.10));
  border-color: var(--accent2); color: #eaf3ff; box-shadow: 0 0 10px rgba(93,180,255,0.3);
}

/* spectral legend (bottom-left, above fps) */
#legend {
  position: fixed; left: 14px; bottom: 38px; z-index: 15; width: 232px;
  background: var(--panel); backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--edge); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.5); font-size: 11px;
}
#legend .lg-head { display: flex; justify-content: space-between; align-items: baseline; }
#legend .lg-name { font-size: 13px; font-weight: 600; color: #e7eefb; letter-spacing: 0.4px; }
#legend .lg-mode { font-size: 9.5px; color: var(--txt-dim); text-transform: uppercase; letter-spacing: 1px; }
#legend .lg-range { font-size: 10px; color: var(--txt-dim); margin: 2px 0 7px; font-variant-numeric: tabular-nums; }
#legend .lg-bar { height: 9px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.08); }
#legend .lg-scale { display: flex; justify-content: space-between; font-size: 8.5px; color: var(--txt-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 1px; }
#legend .lg-note { font-size: 10px; color: #b9c6dc; line-height: 1.45; margin-top: 7px; }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset {
  background: rgba(255,255,255,0.04); border: 1px solid var(--edge); border-radius: 9px;
  padding: 8px; cursor: pointer; text-align: left; transition: all 0.15s;
}
.preset:hover { border-color: var(--edge-bright); transform: translateY(-1px); background: rgba(255,255,255,0.07); }
.preset .pn { font-size: 11px; font-weight: 600; color: #e7eefb; }
.preset .pd { font-size: 9.5px; color: var(--txt-dim); margin-top: 2px; line-height: 1.35; }

.hint { font-size: 10px; color: var(--txt-dim); line-height: 1.5; margin-top: 6px; }
.kbd { display:inline-block; background: rgba(255,255,255,0.08); border:1px solid var(--edge); border-radius:4px; padding:0 4px; font-size:10px; font-family: ui-monospace, monospace; color:#cfe0f5; }

/* object list */
.obj-item { display:flex; align-items:center; gap:8px; padding:6px 8px; margin:5px 0; border:1px solid var(--edge); border-radius:8px; background: rgba(255,255,255,0.03); }
.obj-item .swatch { width:12px; height:12px; border-radius:50%; flex:0 0 auto; box-shadow:0 0 6px currentColor; }
.obj-item .nm { font-size:11px; flex:1; }
.obj-item .nm small { color: var(--txt-dim); display:block; font-size:9.5px; }
.obj-item .x { cursor:pointer; color: var(--txt-dim); font-size:14px; padding:0 4px; }
.obj-item .x:hover { color: #ff7676; }

/* black hole library */
.lib-fact { margin-top: 8px; padding: 8px 10px; border: 1px solid var(--edge); border-left: 2px solid var(--accent2); border-radius: 8px; background: rgba(93,180,255,0.06); font-size: 10.5px; line-height: 1.55; color: #cdd9ec; }
.lib-fact:empty { display: none; }
.lib-fact b { color: #d6ecff; }
.lib-fact .dim { color: var(--txt-dim); }

/* impactor section */
.imp-types { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 4px 0 9px; }
.imp-type {
  font: inherit; font-size: 11px; cursor: pointer; padding: 7px 6px; color: var(--txt-dim);
  background: rgba(255,255,255,0.03); border: 1px solid var(--edge); border-radius: 7px; transition: all 0.12s;
}
.imp-type:hover { border-color: var(--edge-bright); color: var(--txt); }
.imp-type.active { background: linear-gradient(90deg, rgba(93,180,255,0.22), rgba(93,180,255,0.08)); border-color: rgba(93,180,255,0.5); color: #d6ecff; }
.imp-ro { margin: 6px 0 4px; padding: 7px 9px; border: 1px solid var(--edge); border-radius: 8px; background: rgba(93,180,255,0.05); font-size: 11px; line-height: 1.7; }
.imp-ro .row { display: flex; justify-content: space-between; gap: 12px; }
.imp-ro .row .k { color: var(--txt-dim); }
.imp-ro .row .v { font-variant-numeric: tabular-nums; color: #e7eefb; }
.imp-ro .row .v .dim { color: var(--txt-dim); }
.imp-fate { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--edge); font-size: 10.5px; line-height: 1.5; color: #cdd9ec; }
.imp-fate b { color: var(--accent); }
.imp-status { font-size: 10px; color: var(--txt-dim); margin-top: 8px; line-height: 1.5; }
.imp-live { margin-top: 8px; padding: 7px 9px; border: 1px solid rgba(93,180,255,0.35); border-radius: 8px; background: rgba(93,180,255,0.07); font-size: 11px; line-height: 1.7; }
.imp-live .row { display: flex; justify-content: space-between; gap: 12px; }
.imp-live .row .k { color: var(--txt-dim); }
.imp-live .row .v { font-variant-numeric: tabular-nums; color: #e7eefb; }
.imp-event { margin-top: 8px; padding: 9px 11px; border: 1px solid rgba(255,150,70,0.45); border-radius: 9px; background: linear-gradient(160deg, rgba(255,122,44,0.14), rgba(93,180,255,0.06)); }
.imp-event .ev-title { font-size: 12px; font-weight: 600; color: #ffd9b3; letter-spacing: 0.3px; margin-bottom: 4px; }
.imp-event .ev-body { font-size: 10.5px; line-height: 1.55; color: #d7e2f3; }
.imp-event .ev-body b { color: #ffe0bd; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 14px; left: 14px; z-index: 15;
  background: var(--panel); backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--edge); border-radius: 12px; padding: 11px 13px;
  font-size: 11px; min-width: 210px; line-height: 1.6;
  box-shadow: 0 14px 36px rgba(0,0,0,0.5);
}
#hud .hh { font-size: 10px; letter-spacing: 2px; color: var(--txt-dim); text-transform: uppercase; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
#hud .hud-chev { font-size: 12px; transition: transform 0.2s; opacity: 0.7; }
#hud.collapsed .hud-chev { transform: rotate(-90deg); }
#hud.collapsed .row, #hud.collapsed .sep { display: none; }
#hud.collapsed .hh { margin-bottom: 0; }
#hud .row { display: flex; justify-content: space-between; gap: 14px; }
#hud .row .k { color: var(--txt-dim); }
#hud .row .v { font-variant-numeric: tabular-nums; color: #e7eefb; }
#hud .row .v.alert { color: var(--warn); }
#hud .row .v.danger { color: #ff7676; }
#hud .sep { height: 1px; background: var(--edge); margin: 7px 0; }

#fps { position: fixed; bottom: 12px; left: 14px; z-index: 15; font-size: 10px; color: var(--txt-dim); font-variant-numeric: tabular-nums; background: rgba(8,10,16,0.5); padding: 3px 8px; border-radius: 6px; }
#mode-badge { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 15; font-size: 11px; color: var(--txt); background: var(--panel); border:1px solid var(--edge); padding: 5px 12px; border-radius: 20px; letter-spacing: 0.5px; }
#mode-badge b { color: var(--accent2); }

/* hamburger menu button — shown whenever the panel is hidden (desktop & mobile) */
#menu-fab {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  z-index: 30; display: none; flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 12px; background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--edge); cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
#menu-fab span { display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--txt); transition: 0.2s; }
#menu-fab:hover { border-color: var(--edge-bright); }
#menu-fab:hover span { background: #fff; }
body:not(.nav-open) #menu-fab { display: flex; }

/* drawer backdrop (only active on mobile, via the media query) */
#scrim { position: fixed; inset: 0; z-index: 19; background: rgba(3,5,10,0.5); opacity: 0; pointer-events: none; transition: opacity 0.3s; }

/* ---------- responsive / touch: phones & small tablets ---------- */
@media (max-width: 820px) {
  :root { font-size: 14px; }

  /* panel becomes a full-height slide-in drawer */
  #panel {
    top: 0; right: 0; bottom: 0; width: min(88vw, 380px);
    max-height: none; height: 100dvh; border-radius: 0;
    border-top: none; border-right: none; border-bottom: none;
    padding: calc(6px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) 6px;
    -webkit-overflow-scrolling: touch;
  }
  body:not(.nav-open) #panel { transform: translateX(100%); }
  body.nav-open #scrim { opacity: 1; pointer-events: auto; }

  /* finger-friendly targets */
  .section > .sec-head { padding: 13px 12px; font-size: 13px; }
  .section .sec-body { padding: 2px 12px 14px; }
  .ctrl { margin: 14px 0; }
  .ctrl .lbl span:first-child, .ctrl .lbl .val { font-size: 12.5px; }
  input[type=range] { height: 6px; }
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type=range]::-moz-range-thumb { width: 24px; height: 24px; }
  .toggle-row { margin: 14px 0; }
  .toggle-row span { font-size: 12.5px; }
  .switch { width: 48px; height: 27px; }
  .switch .track::after { width: 23px; height: 23px; }
  .switch input:checked + .track::after { transform: translateX(21px); }
  select, button.btn { padding: 11px 9px; font-size: 13px; }
  .seg-btn { padding: 11px 2px; font-size: 11px; }
  .preset { padding: 11px; }
  .obj-item .x { font-size: 20px; padding: 4px 8px; }
  .imp-type { padding: 12px 6px; font-size: 12.5px; }
  .imp-ro, .imp-live { font-size: 12.5px; }

  /* HUD: compact; JS collapses it by default on mobile */
  #hud { top: calc(8px + env(safe-area-inset-top)); left: 8px; right: auto; min-width: 0; max-width: 64vw; padding: 9px 11px; font-size: 10.5px; }
  #hud .row { gap: 10px; }

  /* legend: compact, drop the long note */
  #legend { left: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; max-width: 58vw; padding: 8px 10px; }
  #legend .lg-note { display: none; }

  /* fps to bottom-right so it clears the legend */
  #fps { left: auto; right: calc(8px + env(safe-area-inset-right)); bottom: calc(8px + env(safe-area-inset-bottom)); }

  /* mode badge minimal (no fly on touch) */
  #mode-badge { font-size: 10px; padding: 4px 10px; bottom: calc(40px + env(safe-area-inset-bottom)); opacity: 0.85; }
}

/* very small phones: full-width drawer */
@media (max-width: 430px) {
  #panel { width: 100vw; }
  #hud { max-width: 72vw; }
}
