/* Wedding Survivor — styles
   Layout: a full-bleed canvas "venue" with HUD panels pinned to the safe edges;
   menus are gold-edged invitation cards floating over the live hall.
   Deliberately single-theme: the game always takes place at night. */
:root {
  --night: #170d1f;
  --plum: #2a1838;
  --plum-2: #3b2350;
  --line: #5b3a72;
  --panel: rgba(23, 13, 31, 0.84);
  --scrim: rgba(23, 13, 31, 0.72);
  --gold: #f2c46d;
  --gold-2: #b98a35;
  --rose: #ff7a9c;
  --mint: #7ee0c3;
  --sky: #7fc8ff;
  --paper: #fff4e4;
  --muted: #cdb8d9;
  --danger: #ff5e6c;
  --ink: #1d1026;
  --flash: #ffffff;

  --display: 'Silkscreen', 'Courier New', monospace;
  --body: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --step--1: 0.75rem;
  --step-0: 0.95rem;
  --step-1: 1.15rem;
  --step-2: 1.6rem;
  --step-3: 2.6rem;

  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Screens and overlays are toggled with the `hidden` attribute; keep it
   stronger than component rules like `.screen { display: flex }`. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--paper);
  font-family: var(--body);
  font-size: var(--step-0);
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: relative; width: 100%; height: 100%; overflow: hidden; }
#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible + span {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-row {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 3px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.meters {
  display: grid; gap: 6px;
  padding: 8px 10px;
  width: 240px; max-width: 100%;
}
.meter { display: grid; gap: 3px; }
.m-label {
  font-family: var(--display);
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
  display: flex; justify-content: space-between; gap: 8px;
}
.m-track {
  display: block; height: 10px;
  background: var(--ink);
  border: 2px solid var(--line);
  position: relative;
}
.m-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 50%;
  background: var(--gold);
  transition: width 0.15s linear;
}
#m-battery .m-fill { background: var(--mint); }
#m-battery.low .m-fill { background: var(--danger); animation: blink 0.6s steps(2) infinite; }
#m-food.low .m-fill { background: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
.chips:empty { display: none; }
.chip-s {
  font-family: var(--display); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 5px;
  background: var(--plum-2); color: var(--paper);
  border: 1px solid var(--line);
}
.chip-s.bad { background: var(--danger); color: var(--ink); border-color: var(--danger); }
.chip-s.good { background: var(--mint); color: var(--ink); border-color: var(--mint); }

.clock-box {
  margin-left: auto;
  padding: 6px 12px; text-align: center; min-width: 150px;
}
#clock {
  font-family: var(--display); font-size: var(--step-2); line-height: 1;
  color: var(--gold); font-variant-numeric: tabular-nums;
}
#event-name { font-size: var(--step--1); color: var(--muted); margin-top: 4px; }

.score-box { padding: 6px 12px; text-align: right; min-width: 104px; }
.score-label {
  font-family: var(--display); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
#score {
  font-family: var(--display); font-size: var(--step-2); line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.excuses { display: flex; gap: 3px; justify-content: flex-end; margin-top: 4px; min-height: 12px; }
.excuses span {
  width: 8px; height: 12px;
  border: 2px solid var(--line);
  background: transparent;
}
.excuses span.on { background: var(--sky); border-color: var(--sky); }

#minimap { width: 160px; height: 112px; image-rendering: pixelated; }

#zone-label {
  position: absolute;
  left: max(16px, env(safe-area-inset-left, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  font-family: var(--display); font-size: var(--step-1);
  color: var(--paper);
  text-shadow: 2px 2px 0 var(--ink);
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.35s, transform 0.35s;
}
#zone-label.show { opacity: 1; transform: none; }
#zone-label small { display: block; font-family: var(--body); font-size: var(--step-0); color: var(--gold); }

/* ---------- Toast & conversation ---------- */
#toast {
  position: absolute; left: 50%; top: calc(150px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  background: var(--panel);
  border: 2px solid var(--gold);
  padding: 10px 14px; text-align: center;
  pointer-events: none;
  animation: pop 0.25s ease-out;
}
#toast.event { border-color: var(--rose); }
#toast-title { font-family: var(--display); font-size: var(--step-1); color: var(--gold); line-height: 1.2; }
#toast.event #toast-title { color: var(--rose); }
#toast-sub { font-size: var(--step-0); color: var(--paper); margin-top: 4px; }

#convo {
  position: absolute; left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  background: var(--panel);
  border: 2px solid var(--rose);
  padding: 12px 16px;
  pointer-events: none;
}
.convo-who { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
#convo-name { font-family: var(--display); font-size: var(--step-0); color: var(--rose); }
#convo-line { margin: 6px 0 10px; font-size: var(--step-1); }
.convo-bar { height: 12px; border: 2px solid var(--line); background: var(--ink); position: relative; }
#convo-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--mint); }
.convo-hint { margin: 6px 0 0; font-size: var(--step--1); color: var(--muted); }

#flash {
  position: absolute; inset: 0;
  background: var(--flash);
  opacity: 0; pointer-events: none;
}
#flash.on { animation: flash 1.1s ease-out; }

/* ---------- Touch controls ---------- */
#touch {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}
#touch button {
  pointer-events: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  color: var(--paper);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
#touch button.held, #touch button:active { background: var(--plum-2); border-color: var(--gold); }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 4px;
}
.pad-up { grid-area: 1 / 2; }
.pad-left { grid-area: 2 / 1; }
.pad-right { grid-area: 2 / 3; }
.pad-down { grid-area: 3 / 2; }
.touch-right { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
#btn-pause { width: 44px; height: 44px; font-family: var(--display); }
#btn-action {
  width: 88px; height: 88px; border-radius: 50%;
  font-family: var(--display); font-size: 12px;
  border-color: var(--rose) !important;
}
#app.touching #zone-label { bottom: calc(200px + env(safe-area-inset-bottom, 0px)); }
#app.touching #convo { bottom: calc(196px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Screens & cards ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex;
  overflow-y: auto;
  padding-block: calc(24px + env(safe-area-inset-top, 0px)) calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--scrim);
}
.card {
  margin: auto;
  width: 100%; max-width: 900px;
  background: var(--plum);
  border: 2px solid var(--gold);
  box-shadow: inset 0 0 0 5px var(--plum), inset 0 0 0 6px var(--gold-2), 0 24px 60px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 32px clamp(18px, 4vw, 40px);
  display: grid; gap: 24px;
}
.small-card { max-width: 520px; text-align: center; }
.eyebrow {
  margin: 0;
  font-family: var(--display); font-size: var(--step--1);
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold);
}
.invite { display: grid; gap: 8px; text-align: center; justify-items: center; }
.invite h1 {
  margin: 4px 0 0;
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.2rem, 7vw, 3.6rem); line-height: 0.95;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--rose), 8px 8px 0 var(--ink);
  text-wrap: balance;
}
.lede { margin: 0; max-width: 46ch; color: var(--muted); text-wrap: balance; }

.creator {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 28px; align-items: start;
}
.preview {
  display: grid; gap: 12px; justify-items: center;
  padding: 12px;
  background: var(--ink);
  border: 2px solid var(--line);
}
#preview { width: 160px; height: 200px; image-rendering: pixelated; }
.arch-stats { width: 100%; display: grid; gap: 6px; }
.stat { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 8px; }
.stat span {
  font-family: var(--display); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.stat i { display: block; height: 8px; background: var(--plum-2); position: relative; }
.stat i b { position: absolute; inset: 0 auto 0 0; background: var(--gold); }

.options { display: grid; gap: 16px; min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend {
  padding: 0; margin-bottom: 8px;
  font-family: var(--display); font-size: var(--step--1);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.note { color: var(--rose); text-transform: none; letter-spacing: 0; font-family: var(--body); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.arch-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.chip { position: relative; display: block; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip > span {
  display: block;
  padding: 8px 14px;
  background: var(--ink);
  border: 2px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.chip:hover > span { border-color: var(--gold-2); }
.chip input:checked + span { border-color: var(--gold); background: var(--plum-2); box-shadow: 0 3px 0 var(--gold-2); }
.chip.arch > span { height: 100%; padding: 10px 12px; }
.chip.arch b { display: block; font-weight: 700; }
.chip.arch small { display: block; color: var(--muted); font-size: var(--step--1); margin-top: 2px; }

.swatch-groups { display: flex; flex-wrap: wrap; gap: 20px 32px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; display: block; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch span {
  display: block; width: 30px; height: 30px;
  border: 2px solid var(--line);
  cursor: pointer;
}
.swatch input:checked + span { outline: 2px solid var(--gold); outline-offset: 2px; border-color: var(--ink); }

.btn-primary, .btn-ghost {
  font-family: var(--display); font-size: var(--step-0); letter-spacing: 0.04em;
  padding: 14px 22px;
  border-radius: 2px;
  transition: transform 0.08s;
}
.btn-primary {
  background: var(--gold); color: var(--ink);
  border: 0;
  box-shadow: 0 4px 0 var(--gold-2);
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-2); }
.btn-ghost { background: transparent; color: var(--paper); border: 2px solid var(--line); }
.btn-ghost:hover { border-color: var(--gold-2); }
#btn-start { justify-self: start; }

.controls {
  display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center;
  padding-top: 18px; border-top: 2px dashed var(--line);
  font-size: var(--step--1); color: var(--muted);
}
kbd {
  font-family: var(--display); font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--line); border-bottom-width: 3px;
  background: var(--ink); color: var(--paper);
}

.small-card h2 {
  margin: 0;
  font-family: var(--display); font-size: var(--step-2); line-height: 1.1;
  color: var(--paper); text-wrap: balance;
}
.rank { margin: -12px 0 0; color: var(--rose); font-weight: 500; }
.final-score { display: grid; gap: 2px; justify-items: center; }
.final-score span { font-family: var(--display); font-size: var(--step--1); color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.final-score strong {
  font-family: var(--display); font-size: var(--step-3); line-height: 1;
  color: var(--gold); font-variant-numeric: tabular-nums;
}
.final-score em { font-style: normal; font-size: var(--step--1); color: var(--muted); }
.stats {
  margin: 0;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px;
  text-align: left;
  padding: 14px 16px; background: var(--ink); border: 2px solid var(--line);
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-family: var(--display); font-variant-numeric: tabular-nums; text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ---------- Animation ---------- */
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes pop { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  #flash.on { animation: none; opacity: 0; }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 760px) {
  .creator { grid-template-columns: minmax(0, 1fr); }
  .preview { grid-template-columns: 160px minmax(0, 1fr); align-items: center; justify-items: start; }
  .arch-row { grid-template-columns: minmax(0, 1fr); }
  #btn-start { justify-self: stretch; }
  #minimap { display: none; }
  .meters { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
  .meters .chips { grid-column: 1 / -1; }
  .clock-box { margin-left: 0; flex: 1; min-width: 0; }
  .score-box { flex: 1; min-width: 0; }
  #toast { top: calc(170px + env(safe-area-inset-top, 0px)); }
}
@media (max-width: 420px) {
  .preview { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); }
  #btn-action { width: 76px; height: 76px; }
}
