/* Cogfall page chrome: HUD bar, stage, overlays and menus. The playfield itself is canvas. */

:root {
  --soot: #0d0805;
  --soot-2: #1c110a;
  --panel: rgba(24, 14, 8, 0.9);
  --panel-edge: rgba(212, 166, 74, 0.32);
  --text: #f1e4cc;
  --text-dim: #bba486;
  --brass: #d9ac52;
  --brass-bright: #f6d488;
  --brass-soft: rgba(217, 172, 82, 0.35);
  --copper: #c4703f;
  --amber: #ffb54a;
  --moon: #a8c3e6;
  --moon-soft: rgba(168, 195, 230, 0.18);
  --focus: #ffd27a;
  --danger: #ff9a7a;
  --hud-height: 3rem;
  --field-width: min(100vw, 93vh);
  --field-height: min(100vh, 107vw);
  --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 60% 40% at 82% 0%, var(--moon-soft), transparent 70%),
    radial-gradient(ellipse at 50% 110%, rgba(196, 112, 63, 0.18), transparent 60%),
    linear-gradient(180deg, var(--soot-2), var(--soot));
  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), 22rem);
  min-height: var(--hud-height);
  margin: 0 auto;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid rgba(217, 172, 82, 0.14);
  font-variant-numeric: tabular-nums;
}

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

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

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

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

.hud-bonus { color: var(--amber); }

.hud-level { flex: 1 0 auto; }

.hud-stage {
  flex: none;
  max-width: 12rem;
  overflow: hidden;
  color: var(--moon);
  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-key {
  align-items: center;
  padding: 0.05rem 0.5rem;
  border: 1px solid rgba(255, 181, 74, 0.6);
  border-radius: 999px;
  background: rgba(255, 181, 74, 0.12);
  animation: key-glow 0.9s ease-in-out infinite alternate;
}

.hud-key .hud-value { color: var(--amber); }

/* A small winding key: a ring bow and a shaft with a bit. */
.key-icon {
  position: relative;
  flex: none;
  width: 1.2rem;
  height: 0.6rem;
}

.key-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 0.6rem;
  height: 0.6rem;
  border: 2px solid var(--amber);
  border-radius: 50%;
}

.key-icon::after {
  content: "";
  position: absolute;
  left: 0.58rem;
  top: 0.24rem;
  width: 0.62rem;
  height: 0.34rem;
  background:
    linear-gradient(var(--amber), var(--amber)) left top / 100% 0.12rem no-repeat,
    linear-gradient(var(--amber), var(--amber)) right 0.06rem top / 0.12rem 100% no-repeat,
    linear-gradient(var(--amber), var(--amber)) right 0.24rem top / 0.1rem 70% no-repeat;
}

@keyframes key-glow {
  from { box-shadow: 0 0 0 rgba(255, 181, 74, 0); }
  to { box-shadow: 0 0 10px rgba(255, 181, 74, 0.55); }
}

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

/* A tiny brass gear: teeth from a conic gradient, a body and a dark axle hole. */
.life-icon {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--soot-2) 0 20%, transparent 22%),
    radial-gradient(circle, var(--brass) 0 60%, transparent 62%),
    repeating-conic-gradient(var(--brass) 0deg 22deg, transparent 22deg 45deg);
  filter: drop-shadow(0 0 3px var(--brass-soft));
}

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

.hud-sound:hover { background: rgba(217, 172, 82, 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-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;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(217, 172, 82, 0.28),
    0 0 0 4px rgba(28, 17, 10, 0.9),
    0 0 0 5px rgba(196, 112, 63, 0.3),
    0 12px 50px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

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

/* 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(14, 8, 4, 0.6), rgba(10, 6, 3, 0.86));
}

.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(217, 172, 82, 0.07), transparent 40%),
    var(--panel);
  text-align: center;
  box-shadow: inset 0 0 0 3px rgba(13, 8, 5, 0.6), inset 0 0 0 4px rgba(196, 112, 63, 0.18), 0 0 40px rgba(255, 181, 74, 0.06);
}

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

.kicker {
  margin: 0;
  color: var(--moon);
  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(--brass-bright);
  letter-spacing: 0.06em;
  text-shadow: 0 2px 0 #6e4a1c, 0 0 18px rgba(255, 181, 74, 0.35);
}

.screen-heading {
  margin: 0.1rem 0 0.6rem;
  font: 700 1.55rem/1.15 var(--font-title);
  color: var(--brass-bright);
  text-shadow: 0 2px 0 #6e4a1c;
}

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

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

.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(217, 172, 82, 0.4);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(217, 172, 82, 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(217, 172, 82, 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(--brass-bright); font-family: var(--font-numbers); }
.score-table tbody tr:nth-child(odd) { background: rgba(217, 172, 82, 0.05); }

.score-table tr.is-player {
  background: rgba(255, 181, 74, 0.2);
  outline: 1px solid rgba(255, 181, 74, 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(--brass-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(--text);
  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(217, 172, 82, 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(217, 172, 82, 0.14); }
.button:disabled { opacity: 0.6; cursor: default; }

.button-primary {
  border-color: rgba(246, 212, 136, 0.7);
  background: linear-gradient(180deg, rgba(217, 172, 82, 0.32), rgba(196, 112, 63, 0.24));
  color: #fff3d6;
}

.button-primary:hover { background: linear-gradient(180deg, rgba(217, 172, 82, 0.44), rgba(196, 112, 63, 0.34)); }

.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, 210, 122, 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;
}

/* 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; }
  .panel { padding: 0.7rem 0.85rem 0.85rem; }
}

/* Touch devices (html.is-touch, shared/touch-controls.css): gestures, nothing reserved on screen;
   the pause button and the steering marker are brass. Landscape: one compact HUD line across the
   screen so the tower keeps its height. */
:root {
  --tc-ink: var(--brass-bright);
  --tc-fill-solid: rgba(28, 17, 10, 0.92);
  --tc-edge: rgba(217, 172, 82, 0.6);
  --tc-pressed: rgba(217, 172, 82, 0.5);
  --tc-marker: var(--brass-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; }
  .hud-key { animation: none; }
}
