@font-face {
  font-family: 'Jost';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/jost-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-400.woff2') format('woff2');
}

:root {
  --fels:        #1F2724;
  --fels-hell:   #38423C;
  --kalk:        #C9C4B2;
  --pauspapier:  #AEB8B2;
  --tinte:       #16211D;
  --mennige:     #C2452D;
  --lampe:       #E8A33D;
  --gruenspan:   #6FA8A0;

  --f-titel: 'Jost', sans-serif;
  --f-ui: 'IBM Plex Sans', system-ui, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 2px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fels);
  color: var(--kalk);
  font-family: var(--f-ui);
  font-size: 16px;
  line-height: 1.55;
}

body { overflow: hidden; }

button {
  font-family: var(--f-ui);
  font-size: 16px;
  background: transparent;
  color: var(--kalk);
  border: 1px solid rgba(201, 196, 178, 0.4);
  border-radius: var(--radius);
  padding: 0.6em 1.2em;
  cursor: pointer;
}
button:hover { border-color: var(--lampe); color: var(--lampe); }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible {
  outline: 2px solid var(--lampe);
  outline-offset: 2px;
}
button:disabled { opacity: 0.4; cursor: default; }
button.primary { border-color: var(--gruenspan); color: var(--gruenspan); }
button.primary:hover { background: rgba(111, 168, 160, 0.12); }
button.danger { border-color: var(--mennige); color: var(--mennige); }

/* Auf Papier (heller Grund) haben kalk/gruenspan/lampe als Textfarbe kaum
   Kontrast - dort bleibt Text immer Tinte, Akzentfarben nur als Rahmen/Füllung. */
#screen-title button, #screen-lobby button, #screen-build button {
  color: var(--tinte);
  border-color: rgba(22, 33, 29, 0.4);
}
#screen-title button:hover, #screen-lobby button:hover, #screen-build button:hover {
  border-color: var(--tinte);
  background: rgba(22, 33, 29, 0.06);
  color: var(--tinte);
}
#screen-title button.primary, #screen-lobby button.primary, #screen-build button.primary {
  border-color: var(--gruenspan);
  background: rgba(111, 168, 160, 0.22);
}
#screen-title button.danger, #screen-lobby button.danger, #screen-build button.danger {
  border-color: var(--mennige);
  background: rgba(194, 69, 45, 0.12);
}

input[type="text"] {
  font-family: var(--f-ui);
  font-size: 16px;
  background: var(--fels-hell);
  color: var(--kalk);
  border: 1px solid rgba(201, 196, 178, 0.4);
  border-radius: var(--radius);
  padding: 0.5em 0.7em;
}

h1, h2, h3 {
  font-family: var(--f-titel);
  font-weight: 400;
  letter-spacing: 0.02em;
  margin: 0 0 0.4em;
}
h1 { font-size: 39px; }
h2 { font-size: 31px; }
h3 { font-size: 25px; }

p { max-width: 70ch; }

.hidden { display: none !important; }

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Titelbildschirm & Lobby: Papier-Look ---------- */

#screen-title, #screen-lobby {
  background: var(--pauspapier);
  color: var(--tinte);
  align-items: center;
  justify-content: center;
  gap: 1.5em;
  text-align: center;
  padding: 2em;
}
#screen-title h1, #screen-lobby h1 { color: var(--tinte); }
#screen-lobby .code {
  font-family: var(--f-mono);
  font-size: 39px;
  letter-spacing: 0.15em;
  border: 1px solid rgba(22, 33, 29, 0.35);
  padding: 0.2em 0.5em;
  border-radius: var(--radius);
}
#lobby-players {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 0.6em;
  flex-wrap: wrap;
  justify-content: center;
}
#lobby-players li {
  border: 1px solid rgba(22, 33, 29, 0.35);
  border-radius: var(--radius);
  padding: 0.3em 0.8em;
}
#screen-title input, #screen-lobby p { color: var(--tinte); }
#screen-title .hint { color: rgba(22,33,29,0.7); font-size: 14px; }

/* ---------- Bauphase: Pauspapier, Editor ---------- */

#screen-build {
  background: var(--pauspapier);
  color: var(--tinte);
}
#build-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  flex: 1;
  min-height: 0;
}
#palette {
  border-right: 1px solid rgba(22, 33, 29, 0.3);
  padding: 1em;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  overflow-y: auto;
}
.palette-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em 0.6em;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.palette-item:hover { border-color: rgba(22,33,29,0.3); }
.palette-item.active { border-color: var(--lampe); color: var(--tinte); background: rgba(232, 163, 61, 0.18); }
.palette-item .cost { font-variant-numeric: tabular-nums; }
#budget-readout {
  margin-top: auto;
  padding-top: 0.8em;
  border-top: 1px solid rgba(22, 33, 29, 0.3);
  font-family: var(--f-mono);
}

#build-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  min-height: 0;
  padding: 1em;
}
#build-canvas {
  border: 1px solid var(--tinte);
  image-rendering: pixelated;
  background: var(--pauspapier);
  cursor: crosshair;
}
#build-actions { display: flex; gap: 0.8em; align-items: center; }
#build-msg { min-height: 1.4em; font-size: 14px; }
/* dunklere Ableitungen von mennige/gruenspan - auf hellem Papier reicht der
   normale Ton nicht für lesbaren Kontrast (der ist für den dunklen Fels-Grund
   abgestimmt, siehe .lives/.exits-readout auf #screen-run). */
#build-msg.err { color: #7A2717; }
#build-msg.ok { color: #1B4A43; }

/* ---------- Beweislauf / Laufphase: Fels ---------- */

#screen-proof, #screen-run {
  background: var(--fels);
}
.run-header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1em;
  font-family: var(--f-ui);
  flex-shrink: 0;
}
.run-header .countdown {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  min-width: 3ch;
}
.run-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#run-canvas, #proof-canvas {
  background: var(--fels-hell);
  image-rendering: pixelated;
}
.minimap {
  position: absolute;
  right: 1em;
  bottom: 1em;
  width: 140px;
  height: 105px;
  border: 1px solid var(--kalk);
  opacity: 0.25;
  transition: opacity 0.15s;
  background: var(--fels);
}
.minimap:hover, .minimap.active { opacity: 0.95; }
.run-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6em 1em;
  flex-shrink: 0;
}
.lives { color: var(--mennige); letter-spacing: 0.2em; }
.exits-readout { color: var(--gruenspan); }

/* ---------- Auswertung ---------- */

#screen-score, #screen-end {
  background: var(--fels);
  align-items: center;
  justify-content: center;
  gap: 1em;
  text-align: center;
  padding: 2em;
}
#score-table, #end-table {
  border-collapse: collapse;
  font-family: var(--f-ui);
}
#score-table td, #score-table th, #end-table td, #end-table th {
  padding: 0.4em 1em;
  border-bottom: 1px solid rgba(201, 196, 178, 0.2);
  text-align: left;
}
#score-table th, #end-table th { color: var(--kalk); font-weight: 400; }

/* ---------- Übergang Plan -> Fels ---------- */

.transition-veil {
  position: fixed;
  inset: 0;
  background: var(--fels);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.transition-veil.active { opacity: 1; transition-duration: 0.6s; }
@media (prefers-reduced-motion: reduce) {
  .transition-veil { transition-duration: 0.12s; }
}

/* ---------- Phasenanzeige ---------- */

.phase-steps {
  display: flex;
  gap: 0.5em;
  font-family: var(--f-mono);
  font-size: 12px;
}
.phase-steps span { opacity: 0.4; }
.phase-steps span.active { opacity: 1; color: var(--lampe); }

@media (max-width: 700px) {
  #build-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #palette { border-right: none; border-bottom: 1px solid rgba(22,33,29,0.3); flex-direction: row; flex-wrap: wrap; }
  #budget-readout { margin-top: 0; }
}
