:root {
  --ink: #0e1116;
  --panel: rgba(18, 22, 29, 0.86);
  --panel-solid: #151a22;
  --edge: rgba(196, 168, 116, 0.22);
  --parchment: #ece2cd;
  --muted: #97a0ae;
  --brass: #d8a94b;
  --brass-dim: #8d7233;
  --good: #6fbf73;
  --bad: #d9584a;
  --warn: #e0a33c;
  --radius: 10px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--parchment);
  font: 14px/1.5 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }
.muted { color: var(--muted); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--parchment);
  padding: 9px 16px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(216, 169, 75, 0.5); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, #c9992f, #9a7223);
  border-color: #e0bb6a;
  color: #1a1409;
  font-weight: 700;
  letter-spacing: 0.02em;
}
button.primary:hover { background: linear-gradient(180deg, #dcaa3a, #ab7f28); }
button.ghost { background: transparent; }

.panel {
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- join -- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 20%, rgba(30, 38, 50, 0.55), rgba(8, 10, 14, 0.94));
  z-index: 40;
  padding: 24px;
}

.join-panel { width: min(520px, 100%); padding: 32px 34px 26px; text-align: center; }

.join-panel h1 {
  margin: 0 0 4px;
  font-size: 42px;
  letter-spacing: 0.01em;
  font-weight: 600;
}
.join-panel h1 span { color: var(--brass); margin-left: 0.32em; }

.tagline { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  font: inherit;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: rgba(0, 0, 0, 0.32);
  color: var(--parchment);
}
.field input:focus { outline: none; border-color: var(--brass); }

.join-panel .primary { width: 100%; padding: 12px; font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }

/* --------------------------------------------------------------- build -- */

.build-panel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 372px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  z-index: 20;
}

.build-panel header { display: flex; align-items: baseline; justify-content: space-between; }
.build-panel h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
.timer { font-variant-numeric: tabular-nums; color: var(--brass); font-size: 19px; }

.slider { margin-bottom: 11px; }
.slider .top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.slider .top b { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--brass); }
.slider .note { font-size: 11px; color: var(--muted); margin-top: 1px; }

input[type=range] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 20px;
  margin: 2px 0 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--brass-dim), rgba(255,255,255,0.14));
}
input[type=range]::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--brass-dim), rgba(255,255,255,0.14));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--brass); border: 2px solid #2a2113; margin-top: -6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; border: 2px solid #2a2113;
  background: var(--brass); box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.budget { margin-top: 2px; }
.budget-bar { height: 7px; border-radius: 4px; background: rgba(0,0,0,0.4); overflow: hidden; }
#budget-fill { height: 100%; width: 0; background: linear-gradient(90deg, #6fbf73, #d8a94b); transition: width 0.15s, background 0.2s; }
#budget-fill.over { background: linear-gradient(90deg, #d9584a, #e0a33c); }
.budget-text { display: flex; justify-content: space-between; font-size: 12px; margin-top: 5px; font-variant-numeric: tabular-nums; }

.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px; }
.readout { display: flex; justify-content: space-between; font-size: 13px; border-bottom: 1px dotted rgba(255,255,255,0.09); padding-bottom: 3px; }
.readout span { color: var(--muted); }
.readout b { font-variant-numeric: tabular-nums; font-weight: 600; }

.energy { font-size: 11.5px; color: var(--muted); }
.energy .bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-bottom: 5px; background: rgba(0,0,0,0.4); }
.energy .bar i { display: block; height: 100%; }
.energy .key { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.energy .key i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.verdict { margin: 0; font-size: 12.5px; color: var(--warn); min-height: 1.5em; }
.verdict.ok { color: var(--good); }

.build-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }
.build-actions .primary { flex: 1; }
#btn-ready.waiting { background: linear-gradient(180deg, #4e8a52, #3a6b3d); border-color: #7fc084; }

/* ----------------------------------------------------------------- hud -- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

.hud-top { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.pill {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 999px;
  padding: 6px 15px; font-size: 13px; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; gap: 8px; backdrop-filter: blur(10px);
}
.pill.wind { color: var(--brass); }
#wind-arrow { transform-origin: 0 0; transition: transform 0.4s ease-out; }

.roster {
  position: absolute; top: 14px; right: 14px; width: 232px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius);
  padding: 9px 11px; backdrop-filter: blur(10px);
}
.roster h3 { margin: 0 0 7px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.foe { margin-bottom: 8px; font-size: 12.5px; }
.foe:last-child { margin-bottom: 0; }
.foe .line { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.foe .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foe .rng { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; flex: none; }
.foe .hpbar { height: 4px; border-radius: 2px; background: rgba(0,0,0,0.45); margin-top: 3px; overflow: hidden; }
.foe .hpbar i { display: block; height: 100%; background: var(--good); transition: width 0.3s; }
.foe.you .nm { color: var(--brass); font-weight: 600; }
.foe.dead { opacity: 0.4; }
.foe.dead .hpbar i { background: var(--bad); }

.log {
  position: absolute; left: 14px; bottom: 132px; width: 330px; max-height: 168px;
  overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end;
  font-size: 12.5px; pointer-events: none;
}
.log div {
  background: rgba(10, 13, 18, 0.72); border-left: 2px solid var(--brass-dim);
  padding: 4px 9px; margin-top: 3px; border-radius: 0 5px 5px 0;
  animation: fade 0.25s ease-out;
}
@keyframes fade { from { opacity: 0; transform: translateX(-8px); } }

.controls {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  width: min(700px, calc(100vw - 28px));
  background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius);
  padding: 10px 14px 12px; backdrop-filter: blur(12px);
}
.control-row { display: flex; gap: 16px; align-items: flex-end; }
.control-row.bottom { margin-top: 9px; align-items: center; }
.ctl { flex: 1; font-size: 12px; }
.ctl > span { display: block; color: var(--muted); margin-bottom: 1px; }
.ctl b { color: var(--brass); font-variant-numeric: tabular-nums; font-size: 13px; }

.predict { flex: 1; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.predict b { color: var(--parchment); }

.fire {
  position: relative; overflow: hidden; width: 168px; padding: 12px 0;
  font-weight: 700; letter-spacing: 0.14em; font-size: 15px;
  background: linear-gradient(180deg, #b8452f, #82301f); border-color: #d9705a; color: #ffeee8;
}
.fire:hover:not(:disabled) { background: linear-gradient(180deg, #cc4e35, #923726); }
.fire:disabled { background: rgba(255,255,255,0.05); color: var(--muted); border-color: var(--edge); }
.fire-label { position: relative; z-index: 2; }
.reload-fill {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: rgba(216, 169, 75, 0.28); z-index: 1; pointer-events: none;
}

.camhint {
  position: absolute; left: 14px; bottom: 14px; font-size: 11px; color: var(--muted);
  background: rgba(10, 13, 18, 0.6); padding: 5px 10px; border-radius: 6px;
}
.camhint b { color: var(--parchment); font-weight: 600; }

.toast {
  position: fixed; top: 62px; left: 50%; transform: translateX(-50%);
  background: rgba(160, 60, 40, 0.94); color: #fff; padding: 9px 18px;
  border-radius: 8px; z-index: 50; font-size: 13.5px; box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .build-panel { width: calc(100vw - 32px); }
  .roster { display: none; }
  .log { display: none; }
}
