/* ---------------------------------------------------------------------------
   Grayford County storm simulator - interface.
   The rule throughout: the spectacle is the content. Chrome is translucent,
   low-contrast until touched, and gets out of the way on small screens.
--------------------------------------------------------------------------- */

:root {
  --ink: #edeae3;
  --ink-dim: #a8a49c;
  --ink-faint: #6f6c66;
  --glass: rgba(16, 18, 22, 0.72);
  --glass-solid: rgba(20, 22, 27, 0.94);
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.20);
  --accent: #d8b44a;
  --accent-hot: #e2603a;
  --danger: #c2453a;
  --radius: 12px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  --pad: 14px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0b0e;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  font: 600 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
}

/* ------------------------------------------------------------------ HUD */

.hud {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  animation: fadeIn 0.7s 0.2s both;
}
.hud > *, .hud button, .hud canvas { pointer-events: auto; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.hud-top {
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
}

.status-block {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 14px 8px 8px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  box-shadow: var(--shadow);
  min-width: 0;
}

.ef-badge {
  --ef: #7fd4ff;
  flex: 0 0 auto;
  width: 50px; height: 50px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  /* Fallback first for engines without color-mix(); the tinted version wins
     wherever it is supported. */
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--ef);
  background: color-mix(in srgb, var(--ef) 22%, transparent);
  border-color: color-mix(in srgb, var(--ef) 55%, transparent);
  box-shadow: inset 0 0 22px color-mix(in srgb, var(--ef) 26%, transparent);
  transition: background 0.5s, border-color 0.5s, box-shadow 0.5s;
}
.ef-badge span {
  font: 800 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.02em;
  color: var(--ef);
  text-shadow: 0 0 14px color-mix(in srgb, var(--ef) 65%, transparent);
}

.status-text { min-width: 0; }
.phase {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.readout {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.readout b { color: var(--ink); font-weight: 650; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.camera-modes {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.camera-modes button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 600 11.5px/1 inherit;
  letter-spacing: 0.01em;
  padding: 8px 11px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s;
}
.camera-modes button:hover { color: var(--ink); background: rgba(255, 255, 255, 0.07); }
.camera-modes button.on {
  color: #14161b;
  background: var(--ink);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.icon-btn {
  appearance: none;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--ink-dim);
  font: 700 15px/1 inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-btn.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.icon-btn.off #sound-waves { opacity: 0.2; }

/* --------------------------------------------------------------- tally */

.hud-tally {
  left: 12px;
  bottom: 12px;
  width: 208px;
  padding: 11px 13px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.tally-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 2.5px 0;
  font-size: 11.5px;
}
.tally-row .k { color: var(--ink-faint); }
.tally-row .v { font-weight: 700; font-size: 13px; }
.tally-row.destroyed .v { color: var(--accent-hot); }
.tally-sep { height: 1px; background: var(--line); margin: 6px 0 5px; }

/* -------------------------------------------------------------- minimap */

.hud-map {
  right: 12px;
  bottom: 12px;
  padding: 8px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
#minimap {
  display: block;
  width: 230px; height: 230px;
  border-radius: 8px;
  cursor: crosshair;
  background: #10120f;
}
.map-legend {
  margin-top: 6px;
  font-size: 10px;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ------------------------------------------------------------------ CTA */

.cta {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 25;
  animation: fadeIn 0.8s 0.5s both;
}
.summon {
  appearance: none;
  display: block;
  padding: 13px 30px;
  border-radius: 999px;
  border: 1px solid rgba(226, 96, 58, 0.55);
  background: linear-gradient(180deg, rgba(58, 33, 26, 0.94), rgba(30, 18, 15, 0.94));
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 34px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.16s, box-shadow 0.2s, border-color 0.2s, opacity 0.3s;
}
.summon:hover { transform: translateY(-1px); border-color: rgba(226, 96, 58, 0.9); }
.summon:active { transform: translateY(1px); }
.summon-main {
  display: block;
  font: 700 15px/1.2 inherit;
  letter-spacing: 0.01em;
}
.summon-sub {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(226, 140, 110, 0.9);
}
.cta.armed .summon { border-color: rgba(216, 180, 74, 0.6); background: linear-gradient(180deg, rgba(52, 45, 24, 0.94), rgba(28, 25, 16, 0.94)); }
.cta.armed .summon-sub { color: rgba(216, 180, 74, 0.9); }
.cta.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(14px); }

/* ---------------------------------------------------------------- panel */

.panel {
  position: fixed;
  top: 74px;
  right: 12px;
  width: 296px;
  max-height: calc(100vh - 372px);
  z-index: 22;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 22px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s;
}
.panel.open { transform: none; opacity: 1; pointer-events: auto; }
.panel::after {
  content: "";
  position: absolute;
  left: 1px; right: 9px; bottom: 1px;
  height: 34px;
  border-radius: 0 0 var(--radius) var(--radius);
  background: linear-gradient(180deg, transparent, var(--glass-solid) 82%);
  pointer-events: none;
}
.panel-scroll {
  max-height: inherit;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 15px 30px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 4px; }

.panel-section { padding: 12px 0 4px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }
.panel-section h2 {
  margin: 0 0 10px;
  font: 700 10px/1 inherit;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.control { margin-bottom: 13px; }
.control label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.control .val {
  font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hint {
  margin: 5px 0 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--ink-faint);
}

input[type=range] {
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
  display: block;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 15px; height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  transition: transform 0.14s;
}
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:active::-webkit-slider-thumb { background: var(--accent); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border: 0; border-radius: 50%;
  background: var(--ink); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 9px;
}
.seg button {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 600 11px/1 inherit;
  padding: 7px 4px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}
.seg button:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.seg button.on { background: var(--ink); color: #14161b; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.act {
  appearance: none;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  font: 600 11.5px/1.25 inherit;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}
.act:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--line-strong); }
.act.on { background: var(--accent); border-color: var(--accent); color: #1a1608; }
.act.danger { color: #e79a90; }
.act.danger:hover { background: rgba(194, 69, 58, 0.22); border-color: rgba(194, 69, 58, 0.5); }
.act:disabled { opacity: 0.35; cursor: default; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 5px 0;
  cursor: pointer;
  color: var(--ink-dim);
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.check:hover { color: var(--ink); }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  top: 78px;
  transform: translate(-50%, -12px);
  z-index: 30;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  max-width: min(84vw, 460px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(6, 7, 9, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.24s both;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  width: min(860px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px 28px 30px;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { margin: 0 0 18px; font-size: 19px; letter-spacing: -0.01em; }
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }
.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 20px 26px;
}
.help-grid h3 {
  margin: 0 0 8px;
  font: 700 10px/1 inherit;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.help-grid p { margin: 0 0 6px; font-size: 12px; line-height: 1.55; color: var(--ink-dim); }

/* -------------------------------------------------------------- loader */

.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 12%, #26262a 0%, #121319 45%, #08090c 100%);
  transition: opacity 0.8s ease, visibility 0.8s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader-inner { text-align: center; padding: 24px; max-width: 460px; }
.loader h1 {
  margin: 22px 0 4px;
  font: 300 30px/1.1 inherit;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.tagline {
  margin: 0 0 26px;
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.loader-mark {
  position: relative;
  width: 92px; height: 92px;
  margin: 0 auto;
}
.loader-mark .swirl {
  position: absolute;
  left: 50%;
  border: 2px solid rgba(216, 180, 74, 0.55);
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: translateX(-50%);
  animation: spin 1.5s linear infinite;
}
.loader-mark .swirl:nth-child(1) { top: 4px; width: 84px; height: 30px; opacity: 0.35; animation-duration: 2.4s; }
.loader-mark .swirl:nth-child(2) { top: 32px; width: 54px; height: 26px; opacity: 0.6; animation-duration: 1.6s; }
.loader-mark .swirl:nth-child(3) { top: 58px; width: 26px; height: 22px; opacity: 0.95; animation-duration: 1.05s; }
@keyframes spin { to { transform: translateX(-50%) rotate(360deg); } }

.loader-bar {
  width: 240px;
  height: 3px;
  margin: 0 auto 12px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.loader-bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #e2603a);
  transition: width 0.35s ease;
}
#loader-status {
  margin: 0;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
  min-height: 1.4em;
}
.begin-btn {
  margin-top: 22px;
  padding: 12px 34px;
  border-radius: 999px;
  border: 1px solid rgba(216, 180, 74, 0.5);
  background: rgba(216, 180, 74, 0.12);
  color: var(--ink);
  font: 700 14px/1 inherit;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, transform 0.16s;
  animation: fadeIn 0.5s both;
}
.begin-btn:hover { background: rgba(216, 180, 74, 0.24); transform: translateY(-1px); }
.loader-note {
  margin: 20px 0 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.22);
  text-transform: uppercase;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .panel { max-height: calc(100vh - 210px); }
  .hud-map { display: none; }
  .hud-tally { width: 178px; }
}

@media (max-width: 680px) {
  :root { --pad: 10px; }
  /* Two stacked rows: readout on top, controls beneath, so nothing overlaps. */
  .hud-top { padding: 8px; gap: 6px; flex-wrap: wrap; }
  .status-block { flex: 1 1 100%; }
  .top-actions { flex: 1 1 100%; justify-content: flex-start; gap: 6px; }
  .camera-modes { flex: 1 1 auto; }
  .camera-modes button { flex: 1; }
  .toast { top: 128px; font-size: 11.5px; padding: 8px 14px; }
  .status-block { padding: 6px 10px 6px 6px; gap: 8px; }
  .ef-badge { width: 40px; height: 40px; }
  .ef-badge span { font-size: 14px; }
  .phase { font-size: 12px; }
  .readout { font-size: 10px; gap: 2px 9px; }
  .camera-modes button { padding: 7px 8px; font-size: 10.5px; }
  .camera-modes button span.long { display: none; }
  .panel {
    top: auto;
    right: 0; left: 0;
    bottom: 0;
    width: 100%;
    max-height: 62vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% + 20px));
  }
  .panel.open { transform: none; }
  .panel-scroll { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .hud-tally {
    left: 8px; right: 8px; bottom: 8px;
    width: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 14px;
    padding: 8px 10px;
  }
  .tally-row { gap: 6px; }
  .tally-row .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tally-sep { display: none; }
  .tally-row { font-size: 10px; }
  .tally-row .v { font-size: 11.5px; }
  .cta { bottom: 92px; }
  /* The drawer owns the lower screen on mobile, so the primary action rides
     above it rather than being buried under it. */
  .panel.open ~ .cta { bottom: calc(62vh + 14px); }
  .panel.open ~ .hud-tally { opacity: 0; pointer-events: none; }
  .summon { padding: 11px 22px; }
  .summon-main { font-size: 13.5px; }
  .modal-card { padding: 22px 18px 24px; }
}

@media (max-height: 560px) {
  .hud-tally { display: none; }
  .panel { max-height: calc(100vh - 90px); top: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.06s !important; }
}
