/* Fonts: SIL Open Font License, see fonts/OFL-*.txt */
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/barlow-400.woff2) format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/barlow-600.woff2) format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/barlow-700.woff2) format('woff2'); }
@font-face { font-family: 'Saira Stencil One'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/saira-stencil-one-400.woff2) format('woff2'); }

:root {
  --ground: #110c09;
  --plate-hi: #3d3129;
  --plate: #2b231d;
  --plate-lo: #231c17;
  --well: #17110d;
  --line: #3a2f27;
  --line-hi: #5f4f42;
  --ink: #f1e6d4;
  --text: #d9cbb4;
  --dim: #bfae94;
  --amber: #f0a830;
  --amber-hi: #ffc760;
  --danger-line: #8a3a2a;
  --danger-ink: #f2a08f;
  --stencil: 'Saira Stencil One', Impact, 'Arial Narrow', sans-serif;
  --body: Barlow, 'Arial Narrow', Arial, sans-serif;
  color-scheme: dark;
}

/* elements below get display values of their own; hidden must still win */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  background: #000;
  touch-action: none;
}

#screen-wrap, #screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

body.playing .launcher { display: none; }

/* ---- the launcher: one riveted plate on a rusted bulkhead ---- */
.launcher {
  position: relative;
  min-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: max(clamp(28px, 5vw, 64px), env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(40px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background-color: var(--ground);
  background-image:
    radial-gradient(ellipse 55% 38% at 12% 8%, rgba(154, 74, 34, 0.30), transparent 70%),
    radial-gradient(ellipse 45% 40% at 92% 88%, rgba(154, 74, 34, 0.24), transparent 70%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.028) 0 1px, transparent 1px 180px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.4) 0 2px, transparent 2px 180px);
}
.grain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.2;
  mix-blend-mode: overlay;
}

.plate-wrap {
  position: relative;
  width: 100%;
  max-width: 46rem;
  filter: drop-shadow(0 36px 60px rgba(0, 0, 0, 0.65));
}
.plate {
  position: relative;
  background: linear-gradient(180deg, var(--plate-hi) 0%, var(--plate) 22%, var(--plate-lo) 100%);
  clip-path: polygon(30px 0, calc(100% - 30px) 0, 100% 30px, 100% calc(100% - 30px),
                     calc(100% - 30px) 100%, 30px 100%, 0 calc(100% - 30px), 0 30px);
}
.hazard {
  height: 16px;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 16px, #19120b 16px 32px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.45);
}
.rivet {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #a8968a, #3a2f27 72%);
}
.rivet.tl { top: 34px; left: 22px; }
.rivet.tr { top: 34px; right: 22px; }
.rivet.bl { bottom: 22px; left: 22px; }
.rivet.br { bottom: 22px; right: 22px; }
.plate-body {
  padding: clamp(28px, 5vw, 52px) clamp(24px, 6vw, 60px) clamp(32px, 5vw, 52px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.plate-foot { height: 6px; background: linear-gradient(90deg, #6a3412, #9a4a22 30%, #6a3412 60%, #9a4a22); }

h1 {
  margin: 0;
  font: 400 clamp(4.2rem, 13vw, 8rem)/0.9 var(--stencil);
  letter-spacing: 0.05em;
  text-indent: 0.05em;   /* balances the spacing after the last letter */
  text-align: center;
  text-transform: uppercase;
  color: var(--amber);
  text-shadow: 0 3px 0 #6a3412, 0 0 48px rgba(240, 168, 48, 0.28);
}
.rule { border-top: 1px solid #140f0b; border-bottom: 1px solid #4d3f34; }

.view { display: flex; flex-direction: column; gap: 18px; }
.view > p { margin: 0; }
.view > p:not(.error) { color: var(--text); }
.status, .hint { color: var(--dim); }
.hint { font-size: 14px; }
.error { margin: 0; color: var(--danger-ink); white-space: pre-wrap; }

code {
  background: #0006;
  padding: 0.05em 0.35em;
  border-radius: 3px;
  font-size: 0.92em;
  color: var(--ink);
}

/* Multiplayer first, Campaign below */
.actions { display: flex; flex-direction: column; gap: 14px; }

.btn-mp {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  width: 100%;
  min-height: 100px;
  padding: 12px clamp(18px, 5vw, 32px);
  border: 0;
  cursor: pointer;
  background: linear-gradient(180deg, #ffc65a 0%, #f0a830 48%, #c47a14 100%);
  color: #1a1008;
  font: 400 clamp(1.25rem, 5.4vw, 2.4rem)/1.1 var(--stencil);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: left;
  clip-path: polygon(20px 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%, 0 20px);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}
.btn-mp:hover:not(:disabled) { filter: brightness(1.08); }
.btn-mp:focus-visible { outline: 3px solid #1a1008; outline-offset: -8px; }
/* a dull plate rather than a faded one, so the offline chip stays readable */
.btn-mp:disabled {
  cursor: default;
  background: linear-gradient(180deg, #54463a 0%, #3e332a 100%);
  color: #b3a28a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.btn-mp-label { display: flex; align-items: center; gap: clamp(10px, 3vw, 16px); }
.btn-mp-label svg { flex: 0 0 auto; }
.chip-offline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #16110d;
  border: 1px solid var(--line);
  font: 700 13px/1.2 var(--body);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--danger-ink);
}
.chip-offline .led { width: 9px; height: 9px; border-radius: 50%; background: #e0533d; box-shadow: 0 0 8px rgba(224, 83, 61, 0.7); }

.readout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  padding: 12px 18px;
  background: var(--well);
  border: 1px solid var(--line);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  font-size: 15px;
  letter-spacing: 0.02em;
}
.readout p { margin: 0; }
.mp-status { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--text); }
.mp-status strong { color: var(--amber); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.mp-you { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--dim); }
.mp-you strong { color: var(--ink); font-weight: 600; }
.link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--amber-hi); }

.btn-campaign {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 76px;
  margin-top: 10px;
  padding: 0 clamp(18px, 5vw, 28px);
  cursor: pointer;
  background: linear-gradient(180deg, #4a3e35 0%, #342a23 100%);
  border: 1px solid var(--line-hi);
  color: var(--ink);
  font: 400 clamp(1.4rem, 4vw, 1.7rem)/1.1 var(--stencil);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.btn-campaign svg { color: var(--amber); flex: 0 0 auto; }
.btn-campaign:hover { border-color: var(--amber); }
.btn-campaign:focus-visible { outline: 3px solid var(--amber); outline-offset: -8px; }

details.data { background: #1d1713; border: 1px solid var(--line); }
details.data summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
}
details.data summary::-webkit-details-marker { display: none; }
.data-title { display: flex; align-items: center; gap: 10px; }
.chev { color: var(--amber); transition: transform 0.15s; }
details[open] .chev { transform: rotate(90deg); }
.data-brief { font-weight: 500; letter-spacing: 0.04em; text-transform: none; color: var(--dim); }
.data-body { padding: 0 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.data-body p { margin: 0; color: var(--text); }

/* ---- general controls ---- */
.buttons { display: flex; flex-wrap: wrap; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  background: #2b231d;
  border: 1px solid var(--line-hi);
  color: var(--text);
  font: 600 15px/1.2 var(--body);
  letter-spacing: 0.02em;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--amber); color: var(--ink); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, #ffc65a 0%, #f0a830 55%, #d48a1c 100%);
  border-color: #c47a14;
  color: #1a1008;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: #1a1008; border-color: #c47a14; }
.btn.danger { border-color: var(--danger-line); color: var(--danger-ink); }
.btn.danger:hover:not(:disabled) { border-color: #c0533e; color: #ffc4b8; }
.btn:focus-visible, .link:focus-visible, summary:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.drop {
  border: 2px dashed var(--line-hi);
  background: #1d1713;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45);
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.drop.over { border-color: var(--amber); background: #2a1f14; }
.drop p { margin: 0 0 1rem; color: var(--text); font-size: 14px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.drop .buttons { justify-content: center; }

.progress { position: relative; height: 1.8rem; background: var(--well); border: 1px solid var(--line); overflow: hidden; }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: repeating-linear-gradient(-45deg, #f0a830 0 12px, #d48a1c 12px 24px); transition: width 0.2s; }
.progress span { position: relative; display: block; text-align: center; font-size: 0.85rem; line-height: 1.8rem; color: var(--ink); text-shadow: 0 1px 2px #000; }

/* ---- the name prompt ---- */
dialog {
  width: min(26rem, calc(100vw - 2rem));
  padding: 0;
  border: 0;
  background: linear-gradient(180deg, var(--plate-hi) 0%, var(--plate) 30%, var(--plate-lo) 100%);
  color: var(--ink);
  clip-path: polygon(18px 0, calc(100% - 18px) 0, 100% 18px, 100% calc(100% - 18px),
                     calc(100% - 18px) 100%, 18px 100%, 0 calc(100% - 18px), 0 18px);
}
dialog::backdrop { background: rgba(8, 5, 3, 0.78); }
dialog form { padding: 1.25rem 1.5rem 1.5rem; }
dialog h2 { margin: 0 0 1rem; font: 400 1.6rem/1.1 var(--stencil); letter-spacing: 0.06em; text-transform: uppercase; color: var(--amber); }
dialog label { display: block; margin-bottom: 0.35rem; color: var(--dim); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; }
dialog input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font: 600 1.2rem var(--body);
  background: var(--well);
  color: var(--ink);
  border: 1px solid var(--line-hi);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}
dialog input:focus { outline: none; border-color: var(--amber); }
dialog .hint { min-height: 1.4em; margin: 0.45rem 0 0; font-size: 0.85rem; }
dialog .hint.error { color: var(--danger-ink); }
dialog .buttons { flex-direction: row-reverse; justify-content: flex-start; margin-top: 1.25rem; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--plate);
  border: 1px solid var(--amber);
  color: var(--ink);
  padding: 0.6rem 1rem;
  z-index: 10;
}

/* ---- touch controls ---- */
#touch {
  position: absolute;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.tc-game, .tc-menu-pad { position: absolute; inset: 0; display: none; }
#touch.playing .tc-game { display: block; }
#touch:not(.playing) .tc-menu-pad { display: block; }
.tc-stick-zone { position: absolute; left: 0; top: 25%; bottom: 0; width: 45%; }
.tc-look-zone { position: absolute; right: 0; top: 0; bottom: 0; width: 55%; }
.tc-stick {
  position: fixed;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px solid #fff4;
  display: none;
  pointer-events: none;
}
.tc-stick.active { display: block; }
.tc-knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: #fff5; }
.tc-btn {
  position: absolute;
  border-radius: 50%;
  border: 2px solid #fff5;
  background: #0006;
  color: #fffc;
  font: 600 13px system-ui, sans-serif;
  width: 64px; height: 64px;
  touch-action: none;
}
.tc-btn.down { background: #c8642a99; }
.tc-fire { right: max(24px, env(safe-area-inset-right)); bottom: 40px; width: 88px; height: 88px; }
.tc-jump { right: max(124px, calc(env(safe-area-inset-right) + 100px)); bottom: 28px; }
.tc-crouch { right: max(124px, calc(env(safe-area-inset-right) + 100px)); bottom: 104px; }
.tc-weapon { right: max(32px, env(safe-area-inset-right)); bottom: 148px; }
.tc-use { right: max(108px, calc(env(safe-area-inset-right) + 84px)); bottom: 180px; }
.tc-inv { left: max(16px, env(safe-area-inset-left)); top: 16px; width: 52px; height: 52px; }
.tc-menu { right: max(16px, env(safe-area-inset-right)); top: 16px; width: 52px; height: 52px; }
.tc-up, .tc-down, .tc-left, .tc-right { width: 60px; height: 60px; }
.tc-up { left: 84px; bottom: 140px; }
.tc-down { left: 84px; bottom: 20px; }
.tc-left { left: 20px; bottom: 80px; }
.tc-right { left: 148px; bottom: 80px; }
.tc-ok { right: 40px; bottom: 60px; width: 84px; height: 84px; }
.tc-back { right: 140px; bottom: 40px; }
