/* Lanternfall page chrome: HUD bar, stage, Keeper panel, overlays and menus. The lake itself is canvas. */

:root {
  --night: #07061a;
  --night-2: #12103a;
  --indigo: #1d1a52;
  --panel: rgba(16, 13, 46, 0.92);
  --panel-edge: rgba(255, 190, 110, 0.3);
  --paper: #f6ead0;
  --paper-dim: #c9bda2;
  --text: #f3ead8;
  --text-dim: #b7aed0;
  --amber: #ffb54d;
  --amber-bright: #ffd58a;
  --amber-soft: rgba(255, 181, 77, 0.35);
  --vermilion: #e8623f;
  --lake: #6fa6c8;
  --lake-soft: rgba(111, 166, 200, 0.16);
  --focus: #ffd58a;
  --danger: #ff9b84;
  --hud-height: 3rem;
  --field-width: min(100vw, 75vh);
  --field-height: min(100vh, 133vw);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-title: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-numbers: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 50% 35% at 18% 0%, rgba(255, 181, 77, 0.12), transparent 70%),
    radial-gradient(ellipse 45% 30% at 85% 4%, rgba(232, 98, 63, 0.1), transparent 70%),
    radial-gradient(ellipse at 50% 115%, var(--lake-soft), transparent 60%),
    linear-gradient(180deg, var(--night-2), var(--night));
  color: var(--text);
  font: 15px/1.4 var(--font-ui);
  overflow: hidden;
}

/* HUD */

.hud {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.3rem 1rem;
  flex-wrap: wrap;
  width: 100%;
  max-width: max(var(--field-width), 36rem);
  min-height: var(--hud-height);
  margin: 0 auto;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid rgba(255, 181, 77, 0.14);
  font-variant-numeric: tabular-nums;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

.hud-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud-wave-number {
  color: var(--text);
  font-weight: 650;
}

.hud-value {
  font: 650 1.05rem/1.2 var(--font-numbers);
  color: var(--amber-bright);
  text-shadow: 0 0 6px var(--amber-soft);
}

.hud-wave { flex: 1 1 auto; }

.hud-wave-name {
  min-width: 0;
  max-width: 12rem;
  overflow: hidden;
  color: var(--paper);
  font-family: var(--font-title);
  font-style: italic;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hud-back {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-decoration: none;
}

.hud-back:hover { color: var(--text); }

.hud-lives {
  display: flex;
  gap: 0.35rem;
  min-height: 1rem;
}

/*
 * A tiny gunboat in side view (bow to the right): a steel hull with a vermilion stripe, a low
 * wheelhouse aft, the launcher barrel raised towards the bow, and a signal lamp on a short mast.
 */
.life-icon {
  position: relative;
  width: 1.4rem;
  height: 0.95rem;
  background:
    radial-gradient(circle, var(--amber-bright) 0 30%, var(--amber) 45%, transparent 70%) 0.2rem 0 / 0.3rem 0.3rem no-repeat,
    linear-gradient(#1a2230, #1a2230) 0.33rem 0.2rem / 0.07rem 0.3rem no-repeat;
}

.life-icon::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.36rem;
  background: linear-gradient(180deg, #9cb0c6 0 38%, var(--vermilion) 38% 64%, #3c4c60 64%);
  clip-path: polygon(0 0, 100% 0, 82% 100%, 3% 100%);
}

.life-icon::after {
  content: "";
  position: absolute;
  left: 0.08rem;
  right: 0.02rem;
  bottom: 0.34rem;
  height: 0.42rem;
  background: linear-gradient(180deg, #b7c6d6, #71859c);
  clip-path: polygon(0 100%, 4% 30%, 36% 30%, 44% 100%, 52% 100%, 54% 64%, 62% 58%, 97% 6%, 100% 30%, 70% 76%, 70% 100%);
}

.hud-sound {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  background: rgba(255, 181, 77, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.hud-sound:hover { background: rgba(255, 181, 77, 0.14); }
.hud-sound.is-muted { color: var(--text-dim); text-decoration: line-through; }

@media (max-width: 480px) {
  .hud { gap: 0.2rem 0.7rem; padding: 0.3rem 0.5rem; }
  .hud-back-text { display: none; }
  .hud-value { font-size: 0.95rem; }
  .hud-label { font-size: 0.64rem; letter-spacing: 0.08em; }
  .hud-wave-name { max-width: 8.5rem; }
  .hud-sound { padding: 0.15rem 0.45rem; font-size: 0.72rem; }
}

/* Stage and playfield */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.playfield {
  position: relative;
  width: var(--field-width);
  height: var(--field-height);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 181, 77, 0.28),
    0 0 0 4px rgba(18, 16, 58, 0.9),
    0 0 0 5px rgba(232, 98, 63, 0.28),
    0 12px 50px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Keeper panel: three paper seals in the playfield's top-left corner, clear of the Keeper's sway. */

.keeper {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  padding: 0.25rem 0.4rem 0.3rem;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  background: rgba(10, 8, 32, 0.7);
  pointer-events: none;
}

.keeper-title {
  margin: 0 0 0.15rem;
  color: var(--text-dim);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.keeper-seals {
  display: flex;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.seal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.seal-badge {
  display: grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid rgba(201, 189, 162, 0.6);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #e9dcbc, #a99a7a);
  color: #2a2140;
  font: 700 0.75rem/1 var(--font-numbers);
}

.seal-pips {
  width: 1.45rem;
  height: 0.2rem;
  border-radius: 1px;
  background:
    linear-gradient(var(--amber), var(--amber)) left / calc(var(--hp-share, 1) * 100%) 100% no-repeat,
    rgba(255, 255, 255, 0.12);
}

.seal-open .seal-badge {
  border-color: var(--amber-bright);
  background: radial-gradient(circle at 50% 40%, #fff2c8, var(--amber));
  box-shadow: 0 0 8px var(--amber-soft), 0 0 0 2px rgba(255, 181, 77, 0.35);
  animation: seal-glow 0.8s ease-in-out infinite alternate;
}

.seal-closed .seal-badge { opacity: 0.75; }
.seal-closed .seal-pips { opacity: 0.6; }

.seal-broken .seal-badge {
  border-style: dashed;
  border-color: rgba(183, 174, 208, 0.5);
  background: transparent;
  color: var(--text-dim);
}

.seal-broken .seal-pips { visibility: hidden; }

@keyframes seal-glow {
  from { box-shadow: 0 0 4px var(--amber-soft), 0 0 0 2px rgba(255, 181, 77, 0.25); }
  to { box-shadow: 0 0 12px rgba(255, 181, 77, 0.7), 0 0 0 2px rgba(255, 181, 77, 0.5); }
}

/* Overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem;
  overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(12, 10, 38, 0.6), rgba(6, 5, 22, 0.88));
}

.panel {
  width: min(100%, 26rem);
  margin: auto;
  padding: 0.9rem 1.15rem 1.1rem;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 181, 77, 0.08), transparent 40%),
    var(--panel);
  text-align: center;
  box-shadow: inset 0 0 0 3px rgba(7, 6, 26, 0.6), inset 0 0 0 4px rgba(232, 98, 63, 0.18), 0 0 40px rgba(255, 181, 77, 0.08);
}

.panel-narrow { width: min(100%, 17rem); }

.kicker {
  margin: 0;
  color: var(--lake);
  font-size: 0.7rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.game-title {
  margin: 0.05rem 0 0.4rem;
  font: 700 clamp(2rem, 7vw, 3rem)/1.05 var(--font-title);
  color: var(--amber-bright);
  letter-spacing: 0.06em;
  text-shadow: 0 2px 0 #7a2f1c, 0 0 20px rgba(255, 181, 77, 0.4);
}

.screen-heading {
  margin: 0.1rem 0 0.5rem;
  font: 700 1.5rem/1.15 var(--font-title);
  color: var(--amber-bright);
  text-shadow: 0 2px 0 #7a2f1c;
}

.lead {
  margin: 0 0 0.6rem;
  color: var(--paper);
  font-size: 0.86rem;
}

.hint {
  margin: 0 0 0.6rem;
  color: var(--amber);
  font-size: 0.78rem;
}

.gameover-line {
  margin: 0 0 0.6rem;
  color: var(--paper);
  font-size: 0.86rem;
  font-style: italic;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0.9rem;
  margin: 0 0 0.6rem;
  padding: 0;
  list-style: none;
  color: var(--text-dim);
  font-size: 0.8rem;
}

kbd {
  display: inline-block;
  min-width: 1.35em;
  margin: 0 0.08em;
  padding: 0 0.3em;
  border: 1px solid rgba(255, 181, 77, 0.4);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255, 181, 77, 0.08);
  color: var(--text);
  font: 600 0.75rem/1.5 var(--font-ui);
}

.table-heading {
  margin: 0.2rem 0 0.3rem;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.scores { margin: 0 0 0.8rem; }

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.score-table th {
  padding: 0.15rem 0.4rem;
  border-bottom: 1px solid rgba(255, 181, 77, 0.25);
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-table td { padding: 0.12rem 0.4rem; }
.score-table td:nth-child(2) { text-align: left; overflow-wrap: anywhere; }
.score-table th:nth-child(2) { text-align: left; }
.score-table td:nth-child(3) { color: var(--amber-bright); font-family: var(--font-numbers); }
.score-table tbody tr:nth-child(odd) { background: rgba(255, 181, 77, 0.05); }

.score-table tr.is-player {
  background: rgba(255, 181, 77, 0.2);
  outline: 1px solid rgba(255, 181, 77, 0.6);
  font-weight: 700;
}

.score-message {
  margin: 0.3rem 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}

.result { margin: 0 0 0.7rem; }
.result strong { color: var(--amber-bright); font-size: 1.15rem; font-family: var(--font-numbers); }

.name-form { margin: 0 0 0.6rem; }

.name-form label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.name-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.name-row input {
  width: 10rem;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font: inherit;
}

.name-error {
  min-height: 1.2em;
  margin: 0.3rem 0 0;
  color: var(--danger);
  font-size: 0.8rem;
}

.status {
  margin: 0 0 0.4rem;
  color: var(--paper);
  font-size: 0.85rem;
}

.status:empty { display: none; }

/* Buttons and focus */

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  background: rgba(255, 181, 77, 0.06);
  color: var(--text);
  font: 600 0.92rem/1.2 var(--font-ui);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.button:hover { background: rgba(255, 181, 77, 0.14); }
.button:disabled { opacity: 0.6; cursor: default; }

.button-primary {
  border-color: rgba(255, 213, 138, 0.7);
  background: linear-gradient(180deg, rgba(255, 181, 77, 0.32), rgba(232, 98, 63, 0.26));
  color: #fff4dc;
}

.button-primary:hover { background: linear-gradient(180deg, rgba(255, 181, 77, 0.44), rgba(232, 98, 63, 0.36)); }

.button:focus-visible,
.hud-sound:focus-visible,
.hud-back:focus-visible,
.name-row input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(255, 213, 138, 0.45);
}

/* Programmatic focus on menu buttons should also be visible for keyboard players. */
.overlay .button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 400px) {
  .panel { padding: 0.75rem 0.8rem 0.9rem; }
  .lead { font-size: 0.8rem; }
  .controls { font-size: 0.74rem; gap: 0.2rem 0.6rem; }
  .keeper { top: 0.25rem; left: 0.25rem; padding: 0.2rem 0.3rem; }
  .seal-badge, .seal-pips { width: 1.25rem; }
  .seal-badge { height: 1.25rem; font-size: 0.68rem; }
}

/* Small windows (phones): the field can be much shorter than a menu panel, so the menus cover
   the whole window instead of just the field (still scrolling inside themselves). */
@media (max-height: 560px), (max-width: 560px) {
  .overlay { position: fixed; z-index: 30; }
}

/* Touch devices (html.is-touch, shared/touch-controls.css): gestures, nothing reserved on screen;
   the pause button and the steering marker glow like a paper lantern. Landscape: one compact HUD
   line across the screen so the lake keeps its height. */
:root {
  --tc-ink: var(--amber-bright);
  --tc-fill-solid: rgba(16, 13, 46, 0.92);
  --tc-edge: rgba(255, 190, 110, 0.6);
  --tc-pressed: rgba(232, 98, 63, 0.6);
  --tc-marker: var(--amber-bright);
  --tc-marker-opacity: 0.35;
}

@media (orientation: landscape) and (max-height: 560px) {
  /* Sound stays in the pause menu; the bar must fit one line without widening the page. */
  html.is-touch .hud-sound { display: none; }
  html.is-touch .hud {
    flex-wrap: nowrap;
    max-width: none;
    min-height: 0;
    gap: 0.8rem;
    padding: 0.1rem 0.6rem;
  }
  html.is-touch .hud-back-text { display: none; }
}

/* Portrait: the field sits under the HUD and the free space below it is where thumbs rest
   (nothing is reserved there; the field keeps its full width). */
@media (orientation: portrait) {
  html.is-touch .stage { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
  .seal-open .seal-badge { animation: none; }
}
