@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=Rajdhani:wght@500;600;700&display=swap");

:root {
  --bg: #140e0c;
  --bg-2: #1c1512;
  --panel: #241a16;
  --ink: #f3e6d8;
  --muted: #b7a394;
  --line: #3a2c26;
  --copper: #c47a3a;
  --copper-2: #e8b07a;
  --brass: #d4b45a;
  --alarm: #c1121f;
  --ok: #3d9a64;
  --warn: #e23d3d;
  --tile: #2a211c;
  --tile-2: #332822;
  --clue: #3a3124;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(193, 18, 31, 0.16), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, #0c0908 100%);
  color: var(--ink);
  font-family: Rajdhani, "Segoe UI", sans-serif;
}

body {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    radial-gradient(1200px 500px at 50% -10%, rgba(193, 18, 31, 0.16), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, #0c0908 100%);
  background-size: 28px 28px, 28px 28px, auto, auto;
}

.hazard-strip {
  height: 10px;
  background: repeating-linear-gradient(
    -45deg,
    #111 0 10px,
    var(--brass) 10px 20px
  );
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 52px;
  height: 52px;
  color: var(--copper-2);
}

.logo { width: 100%; height: 100%; }

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass);
  font-family: "IBM Plex Mono", monospace;
}

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.meta { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 6px 10px;
  border-radius: 999px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.pill.muted { color: var(--muted); }

.modes {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode {
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  background: #181210;
  color: var(--muted);
  border: 1px solid #3d2d26;
  border-radius: 12px;
  padding: 10px 14px;
}

.mode strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mode span { font-size: 13px; }
.mode.active {
  background: linear-gradient(180deg, #3a2818, #24180f);
  border-color: var(--copper);
  color: #f3e6d8;
}
.mode.active strong { color: var(--brass); }

body[data-mode="leitung"] .brand-only { display: none !important; }
body[data-mode="brand"] .leitung-only { display: none !important; }

.console {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "diffs actions"
    "stock stats";
  gap: 10px;
  align-items: stretch;
  background: linear-gradient(180deg, #2b211c, #1a1411);
  border: 1px solid #4a372c;
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.difficulties { grid-area: diffs; display: flex; gap: 6px; flex-wrap: wrap; }
.actions { grid-area: actions; display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.stock { grid-area: stock; }
.readouts { grid-area: stats; }

.stock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bin {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  flex: 1 1 108px;
  min-width: 108px;
  background: #120e0c;
  border: 1px solid #5a3f28;
  border-radius: 12px;
  padding: 8px 12px;
}

.bin .label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.bin-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 26px;
}

.bin strong {
  font-family: "IBM Plex Mono", monospace;
  font-size: 22px;
  line-height: 1;
  color: var(--copper-2);
}

.bin.empty strong { color: var(--muted); }
.bin.over {
  border-color: var(--warn);
  background: #3a1212;
}
.bin.over strong { color: #ff8d8d; }
.bin.flash { animation: binflash 0.45s ease; }

.bin-glyph {
  font-size: 18px;
  color: var(--copper);
  font-weight: 700;
  line-height: 1;
  flex: 0 0 auto;
}
.bin-glyph.elbow { color: var(--brass); }
.bin-glyph.tee { color: #e07a5f; }
.bin-glyph.head { color: #ff6b6b; }
.bin.alarm { border-color: #7a1c1c; background: #1a0c0c; }
.bin.alarm strong { color: #ffb4b4; }

.diff, .ghost, .reset, .modal button {
  font-family: inherit;
  cursor: pointer;
}

.diff {
  background: #181210;
  color: var(--muted);
  border: 1px solid #3d2d26;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 84px;
  text-align: left;
}

.diff strong { display: block; color: var(--ink); font-size: 18px; }
.diff span { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.diff.active {
  background: linear-gradient(180deg, #5a1a1a, #3a1010);
  border-color: var(--alarm);
  color: #f7d0d0;
}
.diff.active strong { color: #fff; }

.readouts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.readout {
  flex: 1 1 120px;
  min-width: 120px;
  background: #120e0c;
  border: 1px solid #3a2b24;
  border-radius: 12px;
  padding: 8px 12px;
}

.readout .label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.readout strong {
  font-family: "IBM Plex Mono", monospace;
  font-size: 18px;
}

.reset, .ghost, .modal button {
  border-radius: 12px;
  border: 1px solid #5a4336;
  background: #2a201b;
  color: var(--ink);
  padding: 10px 12px;
  font-weight: 600;
}

.reset {
  background: linear-gradient(180deg, #c47a3a, #8a4a1e);
  border-color: #e8b07a;
  color: #1a0f08;
}

.reset-face { margin-right: 4px; }

.stage {
  margin-top: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  align-items: start;
}

.board-wrap {
  background: #1a1411;
  border: 1px solid #4a372c;
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.leg.line {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--brass), var(--copper), var(--alarm));
  border-radius: 2px;
}

.board {
  display: grid;
  gap: 3px;
  justify-content: center;
  user-select: none;
  touch-action: none;
  background:
    repeating-linear-gradient(#0000 0 26px, rgba(255,255,255,0.02) 26px 27px),
    repeating-linear-gradient(90deg, #0000 0 26px, rgba(255,255,255,0.02) 26px 27px),
    #231a16;
  padding: 10px;
  border-radius: 12px;
}

.cell {
  width: var(--cell, 40px);
  height: var(--cell, 40px);
  border-radius: 6px;
  position: relative;
  background: linear-gradient(180deg, var(--tile-2), var(--tile));
  border: 1px solid #4a3a32;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.cell.clue {
  background: linear-gradient(180deg, #4a3f2c, var(--clue));
  cursor: default;
  font-weight: 700;
  font-size: calc(var(--cell, 40px) * 0.48);
}
.cell.clue.n1 { color: #7db7ff; }
.cell.clue.n2 { color: #7dce8a; }
.cell.clue.n3 { color: #ff6b6b; }
.cell.clue.n4 { color: #9aa6ff; }
.cell.clue.n5 { color: #e07a5f; }
.cell.clue.n6 { color: #7ad7d4; }
.cell.clue.n7 { color: #f4f1de; }
.cell.clue.n8 { color: #c9a227; }
.cell.clue.under { color: #d7c39a; opacity: 0.78; }
.cell.blocked { cursor: default; }

.cell.revealed {
  background: linear-gradient(180deg, #2a2218, #1a140f);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.55);
  font-weight: 700;
  font-size: calc(var(--cell, 40px) * 0.46);
}

.cell.revealed.n1 { color: #7db7ff; }
.cell.revealed.n2 { color: #7dce8a; }
.cell.revealed.n3 { color: #ff6b6b; }
.cell.revealed.n4 { color: #9aa6ff; }
.cell.revealed.n5 { color: #e07a5f; }
.cell.revealed.n6 { color: #7ad7d4; }
.cell.revealed.n7 { color: #f4f1de; }
.cell.revealed.n8 { color: #c9a227; }
.cell.revealed.n0 { color: transparent; }

.cell.clue.ok { color: #8ee0ad; box-shadow: inset 0 0 0 2px var(--ok); }
.cell.clue.over { color: #ff8d8d; box-shadow: inset 0 0 0 2px var(--warn); animation: pulse 1s infinite; }

.cell.marked::after {
  content: "×";
  color: #8a7468;
  font-size: 18px;
  font-weight: 700;
}

.cell.burning {
  background: radial-gradient(circle at 50% 60%, #ffb703, #c1121f 55%, #3a0a0a);
  border-color: #ff6b3a;
}

.cell.wrong-flag {
  box-shadow: inset 0 0 0 2px #ff6b6b;
}

.modal.lose { text-align: center; border-color: var(--alarm); }

.cell.pipe { background: transparent; border-color: transparent; box-shadow: none; }
.cell.start, .cell.end { z-index: 2; }

.pipe-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.pipe-arm {
  position: absolute;
  background: linear-gradient(90deg, #8a5a32, #e0b07a 40%, #8a5a32);
  box-shadow: 0 0 0 1px #5a3418;
}

.pipe-arm.n, .pipe-arm.s { width: 8px; height: 55%; left: calc(50% - 4px); }
.pipe-arm.n { top: -2px; }
.pipe-arm.s { bottom: -2px; }
.pipe-arm.e, .pipe-arm.w { height: 8px; width: 55%; top: calc(50% - 4px); }
.pipe-arm.e { right: -2px; }
.pipe-arm.w { left: -2px; }

.pipe-joint {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0d2a8, #b87333 55%, #6a4018);
  box-shadow: 0 0 0 2px #4a2a10;
  z-index: 1;
}

.pipe-joint.stub {
  width: 10px;
  height: 10px;
  background: #6a4a32;
}

.pipe-joint.elbow {
  width: 16px;
  height: 16px;
  border-radius: 3px 11px 3px 3px;
  background: linear-gradient(135deg, #f0d78a, #b8862a 55%, #7a5a18);
  box-shadow: 0 0 0 2px #5a4010;
}

.pipe-joint.tee {
  width: 17px;
  height: 17px;
  border-radius: 2px;
  background: linear-gradient(180deg, #d97a55, #8a3218);
  box-shadow: 0 0 0 2px #5a180c;
}

.cell.head .icon { width: 68%; height: 68%; }

.cell.won .pipe-arm {
  background: linear-gradient(90deg, #2c6ea5, #8fd3ff 45%, #2c6ea5);
  box-shadow: 0 0 10px rgba(100, 180, 255, 0.55);
}

.icon {
  width: 74%;
  height: 74%;
  z-index: 3;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.45));
}

.hint-line {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}

.panel h2 {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 18px;
}

.panel p, .panel li { color: #e6d5c5; }
.panel em { color: var(--brass); font-style: normal; }

.keys { padding-left: 16px; }
kbd {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  background: #120e0c;
  border: 1px solid #4a3a32;
  padding: 1px 6px;
  border-radius: 4px;
}

.sample {
  display: flex;
  gap: 12px;
  align-items: center;
  background: #181210;
  padding: 10px;
  border-radius: 12px;
}

.mini {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  gap: 3px;
}

.mini i, .mini b {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: #322822;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.mini b { background: #4a3f2c; color: #7db7ff; }
.mini i.p { background: #c1121f; }
.mini i.pipe { background: #c47a3a; }

.fine { font-size: 13px; color: var(--muted); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 4, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.overlay.hidden { display: none; }

.modal {
  max-width: 520px;
  background: linear-gradient(180deg, #2c211c, #1a1411);
  border: 1px solid var(--brass);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal.win { text-align: center; }
.modal ol { padding-left: 18px; color: #eadccf; }
.modal button { margin-top: 8px; background: linear-gradient(180deg, #c47a3a, #8a4a1e); color: #1a0f08; border: none; }

@keyframes pulse {
  50% { box-shadow: inset 0 0 0 2px #ffd0d0; }
}

@keyframes binflash {
  50% { box-shadow: 0 0 0 2px var(--warn); transform: translateY(-1px); }
}

@media (max-width: 920px) {
  .console {
    grid-template-columns: 1fr;
    grid-template-areas:
      "diffs"
      "stock"
      "stats"
      "actions";
  }
  .actions { justify-content: flex-start; }
  .stage { grid-template-columns: 1fr; }
}
