@font-face {
  font-family: 'Grenze Gotisch';
  src: url('fonts/grenze-gotisch--latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Grenze Gotisch';
  src: url('fonts/grenze-gotisch--latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Alegreya';
  src: url('fonts/alegreya--latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Alegreya';
  src: url('fonts/alegreya--latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Alegreya';
  src: url('fonts/alegreya--latin-400-italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'IM Fell English SC';
  src: url('fonts/im-fell-english-sc--latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}

:root {
  --wood-hi: #3a2817;
  --wood: #241708;
  --wood-lo: #170e05;
  --brass: #c9a154;
  --brass-dim: #8a6d33;
  --parch: #e6d5ac;
  --parch-dim: #b9a67c;
  --ink: #efe4c8;
  --wax: #8e2f24;
  --rope: #6d5326;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Alegreya', Georgia, serif;
  color: var(--ink);
  background: #0d0a06;
  user-select: none;
  -webkit-user-select: none;
}
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; cursor: grab; }
#scene canvas:active { cursor: grabbing; }

/* ---------- panels ---------- */
.panel {
  position: fixed;
  top: 66px;
  bottom: 14px;
  width: 296px;
  padding: 14px 16px 18px;
  overflow-y: auto;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.16) 0 2px, transparent 2px 26px),
    linear-gradient(160deg, var(--wood-hi), var(--wood) 40%, var(--wood-lo));
  border: 1px solid #000;
  box-shadow:
    inset 0 0 0 1px rgba(201,161,84,0.28),
    inset 0 0 34px rgba(0,0,0,0.65),
    0 8px 30px rgba(0,0,0,0.6);
  scrollbar-width: thin;
  scrollbar-color: var(--brass-dim) transparent;
  z-index: 5;
}
.panel::before {
  content: '';
  position: absolute; inset: 4px;
  border: 1px solid rgba(201,161,84,0.16);
  pointer-events: none;
}
.panel::-webkit-scrollbar { width: 7px; }
.panel::-webkit-scrollbar-thumb { background: var(--brass-dim); border-radius: 4px; }
.panel.left { left: 14px; border-radius: 3px 10px 10px 3px; }
.panel.right { right: 14px; border-radius: 10px 3px 3px 10px; }

.panel-head {
  font-family: 'IM Fell English SC', serif;
  font-size: 19px;
  letter-spacing: 0.08em;
  color: var(--brass);
  text-align: center;
  padding-bottom: 9px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(201,161,84,0.3);
  text-shadow: 0 1px 0 #000, 0 0 18px rgba(201,161,84,0.25);
}
.panel-sub {
  font-family: 'IM Fell English SC', serif;
  font-size: 15px;
  letter-spacing: 0.07em;
  color: var(--parch-dim);
  margin: 13px 0 7px;
}
.divider {
  height: 1px;
  margin: 14px 0 4px;
  background: linear-gradient(90deg, transparent, rgba(201,161,84,0.4), transparent);
}

/* ---------- controls ---------- */
.ctl { margin: 11px 0; }
.ctl-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: 'IM Fell English SC', serif;
  font-size: 14.5px; letter-spacing: 0.05em;
  color: var(--parch);
  margin-bottom: 5px;
}
.ctl-label i { font-style: normal; color: var(--parch-dim); font-size: 12px; }
.ctl-val {
  font-family: 'Alegreya', serif; font-weight: 700;
  color: var(--brass); font-size: 15px;
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(180deg, #0c0803, #241708);
  box-shadow: inset 0 1px 3px #000, 0 1px 0 rgba(201,161,84,0.15);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px; margin-top: -5.5px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ecd9a8, var(--brass) 55%, #6d5326);
  border: 1px solid #3a2c10;
  box-shadow: 0 2px 5px rgba(0,0,0,0.7), inset 0 0 3px rgba(255,240,200,0.5);
}
input[type='range']::-moz-range-track {
  height: 6px; border-radius: 3px; background: #180f06;
  box-shadow: inset 0 1px 3px #000;
}
input[type='range']::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ecd9a8, var(--brass) 55%, #6d5326);
  border: 1px solid #3a2c10;
}

.nudge-row { display: flex; gap: 6px; margin-top: 4px; }

.btn {
  font-family: 'IM Fell English SC', serif;
  font-size: 15px; letter-spacing: 0.06em;
  color: var(--parch);
  background: linear-gradient(180deg, #4a3319, #2c1d0c);
  border: 1px solid #0d0803;
  border-radius: 4px;
  padding: 8px 13px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(233,205,140,0.28), inset 0 -2px 4px rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.5);
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); box-shadow: inset 0 1px 0 rgba(233,205,140,0.35), 0 0 12px rgba(201,161,84,0.28), 0 2px 5px rgba(0,0,0,0.5); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: default; }
.btn.sq { padding: 4px 12px; font-size: 14px; flex: 1; }
.btn.ghost {
  background: rgba(20,12,4,0.72);
  border-color: rgba(201,161,84,0.35);
  font-size: 13.5px; padding: 6px 11px;
}
.btn.wind {
  width: 100%;
  font-size: 17px; padding: 11px;
  background: linear-gradient(180deg, #5a3d1c, #33210d);
  touch-action: none;
}
.btn.wind.disabled { opacity: 0.42; }
.btn.loose {
  flex: 1;
  font-family: 'Grenze Gotisch', serif; font-weight: 700;
  font-size: 21px; letter-spacing: 0.12em;
  color: #f6e3c2;
  background: linear-gradient(180deg, #7d2b1e, #4c150d);
  border-color: #220805;
}
.btn.loose.ready {
  animation: pulse 1.15s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,200,150,0.3), 0 0 4px rgba(214,80,50,0.4); }
  50% { box-shadow: inset 0 1px 0 rgba(255,200,150,0.3), 0 0 22px rgba(232,96,58,0.85); }
}
.fire-row { display: flex; gap: 8px; margin: 13px 0 4px; }

.meter {
  position: relative;
  height: 15px; margin-top: 8px;
  background: #120b04;
  border: 1px solid #000;
  border-radius: 3px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.8), 0 1px 0 rgba(201,161,84,0.14);
  overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #6d5326, var(--brass) 70%, #ecd9a8);
  transition: width 0.09s linear;
}
.meter-fill.gate { background: linear-gradient(90deg, #4c7a3a, #7fae54); }
.meter-fill.gate.low { background: linear-gradient(90deg, #8e2f24, #c9563a); }
.meter.thin { height: 10px; flex: 1; }
.meter-label {
  font-family: 'IM Fell English SC', serif;
  font-size: 12.5px; color: var(--parch-dim);
  margin-top: 4px; text-align: center; letter-spacing: 0.05em;
}

.seg { display: flex; gap: 0; border: 1px solid #0d0803; border-radius: 4px; overflow: hidden; }
.seg-btn {
  flex: 1; padding: 6px 4px;
  font-family: 'IM Fell English SC', serif; font-size: 13.5px; letter-spacing: 0.04em;
  color: var(--parch-dim);
  background: #20140a;
  border: none; border-right: 1px solid #0d0803;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--parch); }
.seg-btn.on {
  color: #1c1206;
  background: linear-gradient(180deg, #d9b96f, #a8813d);
  font-weight: 700;
}

.dir-row { display: flex; align-items: center; gap: 9px; }
.dir-row input { flex: 1; }
.compass {
  position: relative;
  width: 38px; height: 38px; flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 34%, #2c2013, #120b04);
  border: 1.5px solid var(--brass-dim);
  box-shadow: inset 0 0 8px #000;
}
.compass::after {
  content: 'N';
  position: absolute; top: 1px; left: 50%; transform: translateX(-50%);
  font-size: 8.5px; color: var(--parch-dim);
  font-family: 'IM Fell English SC', serif;
}
.compass-needle {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #d0512f; font-size: 17px;
  transform-origin: 50% 50%;
  transition: transform 0.12s linear;
  text-shadow: 0 0 6px rgba(208,81,47,0.6);
}

/* ---------- drill ---------- */
.drill { list-style: none; counter-reset: d; }
.drill-item {
  counter-increment: d;
  position: relative;
  padding: 6px 8px 6px 32px;
  font-size: 14.5px;
  color: var(--parch-dim);
  border-left: 2px solid rgba(201,161,84,0.15);
  margin-left: 9px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.drill-item::before {
  content: counter(d);
  position: absolute; left: -11px; top: 6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #1c1206;
  border: 1px solid var(--brass-dim);
  color: var(--parch-dim);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.drill-item.active {
  color: var(--ink);
  border-left-color: var(--brass);
  background: linear-gradient(90deg, rgba(201,161,84,0.12), transparent);
}
.drill-item.active::before {
  background: radial-gradient(circle at 35% 30%, #ecd9a8, var(--brass));
  color: #1c1206;
  box-shadow: 0 0 10px rgba(201,161,84,0.55);
}
.drill-item.done { color: #9db07a; }
.drill-item.done::before { content: '\2713'; background: #33421f; border-color: #5c7a3a; color: #cfe3a8; }

/* ---------- right panel ---------- */
.status {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  margin-bottom: 11px;
  border: 1px solid #000;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(0,0,0,0.4), rgba(0,0,0,0.15));
  box-shadow: inset 0 0 14px rgba(0,0,0,0.5);
}
.lamp {
  width: 13px; height: 13px; border-radius: 50%; flex: none;
  background: #555;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.6), 0 0 4px rgba(0,0,0,0.6);
  transition: background 0.25s, box-shadow 0.25s;
}
.status.armed .lamp { background: #6fbf5a; box-shadow: 0 0 12px #6fbf5a, inset 0 -2px 3px rgba(0,0,0,0.4); }
.status.winding .lamp { background: #d9a03c; box-shadow: 0 0 12px #d9a03c, inset 0 -2px 3px rgba(0,0,0,0.4); animation: blink 0.5s steps(2) infinite; }
.status.loaded .lamp { background: #d9a03c; box-shadow: 0 0 8px #d9a03c88; }
.status.flight .lamp { background: #5aa7d9; box-shadow: 0 0 12px #5aa7d9, inset 0 -2px 3px rgba(0,0,0,0.4); }
.status.impact .lamp { background: #d0512f; box-shadow: 0 0 14px #d0512f, inset 0 -2px 3px rgba(0,0,0,0.4); }
@keyframes blink { 50% { opacity: 0.45; } }
.status-text {
  font-family: 'Grenze Gotisch', serif; font-weight: 700;
  font-size: 19px; letter-spacing: 0.1em;
  color: var(--ink);
  text-shadow: 0 1px 0 #000;
}

.gauge { display: block; margin: 2px auto 10px; }

.stats { display: grid; gap: 0; }
.stat {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5.5px 2px;
  border-bottom: 1px dashed rgba(201,161,84,0.18);
}
.stat-k {
  font-family: 'IM Fell English SC', serif;
  font-size: 13.5px; color: var(--parch-dim); letter-spacing: 0.04em;
}
.stat-v {
  font-weight: 700; font-size: 15px; color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.gate-integrity { display: flex; align-items: center; gap: 9px; margin: 12px 0 2px; }
.gate-integrity .stat-k { flex: none; }

.shotlog { list-style: none; }
.log-entry {
  font-size: 13.5px;
  color: var(--parch-dim);
  padding: 5px 8px;
  margin-bottom: 4px;
  background: rgba(0,0,0,0.28);
  border-left: 2px solid var(--brass-dim);
  border-radius: 0 3px 3px 0;
  animation: slidein 0.3s ease;
}
.log-entry b { color: var(--brass); }
.log-entry em { font-style: normal; color: var(--ink); }
@keyframes slidein { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(16,10,4,0.92), rgba(16,10,4,0.55) 80%, transparent);
  z-index: 6;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.game-title {
  font-family: 'Grenze Gotisch', serif; font-weight: 700;
  font-size: 33px; line-height: 1;
  color: var(--brass);
  letter-spacing: 0.14em;
  text-shadow: 0 2px 0 #000, 0 0 26px rgba(201,161,84,0.35);
}
.game-sub {
  font-family: 'IM Fell English SC', serif;
  font-size: 12.5px; letter-spacing: 0.22em;
  color: var(--parch-dim);
  margin-top: 1px;
}
.top-actions { display: flex; gap: 8px; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; align-items: center; gap: 8px;
  z-index: 8; pointer-events: none;
}
.toast {
  font-size: 16px;
  color: #241708;
  background: linear-gradient(170deg, #ecdcb4, #d3bd8d);
  border: 1px solid #8a6d33;
  border-radius: 3px;
  padding: 8px 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.55);
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 70vw; text-align: center;
}
.toast.show { opacity: 1; transform: none; }
.toast.good { background: linear-gradient(170deg, #dde8c0, #b9cd8d); border-color: #5c7a3a; }
.toast.breach {
  background: linear-gradient(170deg, #e8c0b4, #cd9a8d);
  border-color: var(--wax);
  font-family: 'Grenze Gotisch', serif; font-weight: 700; font-size: 21px; letter-spacing: 0.08em;
}
.toast.hit { background: linear-gradient(170deg, #e8d9b4, #cdb88d); }

/* ---------- hint ---------- */
.hintbar {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 12.5px; color: rgba(239,228,200,0.62);
  background: rgba(12,8,3,0.55);
  padding: 5px 16px; border-radius: 20px;
  border: 1px solid rgba(201,161,84,0.18);
  z-index: 5; white-space: nowrap;
  font-family: 'IM Fell English SC', serif; letter-spacing: 0.03em;
}
.hintbar b { color: var(--brass); font-weight: 400; }

/* ---------- modals ---------- */
.modal-wrap {
  position: fixed; inset: 0;
  background: rgba(6,4,2,0.66);
  display: none; align-items: center; justify-content: center;
  z-index: 20;
  backdrop-filter: blur(2px);
}
.modal-wrap.open { display: flex; }
.modal {
  position: relative;
  width: min(620px, 92vw);
  max-height: 84vh;
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(120,90,40,0.12), transparent),
    linear-gradient(165deg, #e9d9b2, #d6c091 55%, #c4ab77);
  color: #2c1f10;
  border: 1px solid #6d5326;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8), inset 0 0 60px rgba(120,90,40,0.25);
  animation: modalin 0.25s ease;
}
@keyframes modalin { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-close {
  position: absolute; top: 8px; right: 10px;
  font-size: 26px; line-height: 1;
  background: none; border: none; color: #6d5326; cursor: pointer;
}
.modal-close:hover { color: var(--wax); }
.modal-body { padding: 30px 36px 34px; overflow-y: auto; max-height: 84vh; }
.modal-body h2 {
  font-family: 'Grenze Gotisch', serif; font-weight: 700;
  font-size: 34px; color: #4a2c12;
  margin-bottom: 12px; letter-spacing: 0.05em;
}
.modal-body h3 {
  font-family: 'IM Fell English SC', serif;
  font-size: 18px; color: #6d4318;
  margin: 18px 0 6px; letter-spacing: 0.05em;
}
.modal-body p { font-size: 15.5px; line-height: 1.55; margin-bottom: 9px; }
.modal-body .lede { font-size: 16.5px; font-style: italic; }
.dropcap {
  float: left;
  font-family: 'Grenze Gotisch', serif; font-weight: 700;
  font-size: 52px; line-height: 0.82;
  padding: 4px 8px 0 0;
  color: var(--wax);
}
.codex-foot { font-size: 13px; color: #7a6238; font-style: italic; margin-top: 16px; }
.help-table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.help-table td { padding: 5px 8px; font-size: 14.5px; border-bottom: 1px dashed rgba(109,83,38,0.4); }
.help-table td:first-child { width: 44%; color: #5a3d1c; }

/* ---------- responsive ---------- */
@media (max-width: 1060px) {
  .panel { width: 248px; }
  .hintbar { display: none; }
}
@media (max-width: 760px) {
  .panel { top: auto; bottom: 8px; max-height: 46vh; width: 46vw; }
  .panel.left { left: 8px; }
  .panel.right { right: 8px; }
  .game-sub { display: none; }
}
