@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;600;700&display=swap');

:root {
  --sky-top: #5b9bd0;
  --sky-bottom: #bfe3f2;
  --grass: #6fbb4e;
  --grass-dark: #4f9636;
  --wood: #c08a4a;
  --wood-dark: #8a5f34;
  --wood-darker: #6b4726;
  --stone: #9fa9b5;
  --cream: #fffaf0;
  --cream-2: #fff1d6;
  --ink: #4a3423;
  --muted: #8d7358;
  --gold: #f0b93c;
  --gold-dark: #c8901f;
  --left: #2f9c86;
  --right: #d1584c;
  --danger: #d1584c;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 55%, #d8ecd0 100%) fixed;
  color: var(--ink);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2 {
  font-family: "Baloo 2", "Segoe UI", sans-serif;
  font-weight: 700;
  margin: 0;
}
h1 { font-size: 20px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
h2 {
  font-size: 15px;
  color: var(--wood-darker);
  margin-bottom: 10px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: linear-gradient(180deg, #7ab0d8, var(--sky-top));
  border-bottom: 4px solid rgba(0,0,0,.12);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 18px; height: 22px;
  background: linear-gradient(var(--gold) 40%, #e8e8e8 40%);
  clip-path: polygon(0 22%, 25% 22%, 25% 0, 50% 22%, 75% 0, 75% 22%, 100% 22%, 100% 100%, 0 100%);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.35));
}

.conn {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: #fff;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.dot.on { background: #7fe08a; box-shadow: 0 0 6px #7fe08a; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 250px;
  gap: 14px;
  padding: 16px 18px;
  align-items: start;
}

.panel {
  background: var(--cream);
  border: 2px solid #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 3px 10px rgba(30,50,20,.16);
}

.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.hint.small { font-size: 11.5px; margin-top: 10px; margin-bottom: 0; }

/* ---------- Baumaterial ---------- */
.palette { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }

.palette button {
  width: 100%;
  height: 58px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--cream-2);
  border: 2px solid #ecd9ae;
  border-radius: 12px;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: transform .08s, border-color .12s;
}
.palette button:hover { border-color: var(--gold); transform: translateY(-1px); }
.palette button[aria-pressed="true"] {
  border-color: var(--grass-dark);
  background: #eaf6df;
  box-shadow: 0 0 0 2px rgba(111,187,78,.3);
}
.palette .swatch {
  width: 22px; height: 22px; border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 2px rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.25);
}
.palette .cost {
  color: var(--gold-dark);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.palette .sub {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; color: var(--muted); font-weight: 600; }
.budget-row span:last-child { color: var(--wood-darker); }
.budget-bar {
  height: 10px;
  background: #ecd9ae;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.15);
}
.budget-fill {
  height: 100%; width: 0;
  background: linear-gradient(180deg, #ffd876, var(--gold));
  border-radius: 999px;
  transition: width .2s;
}

.mode-toggle { display: none; }
.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  border: 2px solid #ecd9ae;
  border-radius: 10px;
  background: var(--cream-2);
  color: var(--ink);
  font: inherit;
  font-family: "Baloo 2", sans-serif;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.mode-btn svg { flex: none; }
.mode-btn[aria-pressed="true"] {
  border-color: var(--grass-dark);
  background: #eaf6df;
  box-shadow: 0 0 0 2px rgba(111,187,78,.3);
}

.hint-touch { display: none; }

.actions { display: grid; gap: 8px; margin-top: 14px; }

.btn {
  padding: 10px 12px;
  border: 2px solid #ecd9ae;
  border-radius: 10px;
  background: none;
  color: var(--wood-darker);
  font: inherit;
  font-family: "Baloo 2", sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffd876, var(--gold));
  color: #5c3d0a;
  box-shadow: 0 3px 0 var(--gold-dark);
  transition: transform .06s, box-shadow .06s;
}
.btn-primary:hover { border-color: transparent; box-shadow: 0 2px 0 var(--gold-dark); transform: translateY(1px); }
.btn-primary:active { box-shadow: 0 0 0 var(--gold-dark); transform: translateY(3px); }
.btn-primary:disabled { box-shadow: 0 3px 0 var(--gold-dark); transform: none; }

/* ---------- Kanonenliste ---------- */
.cannon-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cannon-list li {
  padding: 8px 10px;
  background: var(--cream-2);
  border: 2px solid #ecd9ae;
  border-left: 5px solid var(--stone);
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.cannon-list li:hover { border-color: var(--gold); }
.cannon-list li.selected {
  border-color: var(--grass-dark);
  border-left-color: var(--grass-dark);
  background: #eaf6df;
}
.cannon-list .meta { color: var(--muted); font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---------- Spielfeld ---------- */
.stage { display: grid; gap: 10px; }
.stage-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-size: 13px;
}
.side-label {
  color: #fff;
  font-weight: 700;
  font-family: "Baloo 2", sans-serif;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.side-label.right { text-align: right; }
.phase {
  color: var(--wood-darker);
  font-family: "Baloo 2", sans-serif;
  font-weight: 600;
  font-size: 12px;
  text-align: center;
  background: #fff;
  border-radius: 999px;
  padding: 5px 16px;
  box-shadow: 0 2px 0 rgba(0,0,0,.1);
}

.stage-crop { position: relative; transition: width .2s ease, height .2s ease; }

canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #0d1116;
  border: 2px solid #fff;
  border-radius: var(--radius);
  box-shadow: 0 3px 12px rgba(20,40,20,.22);
  cursor: crosshair;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  transition: width .2s ease, height .2s ease;
}

.stage-crop.cropped {
  overflow: hidden;
  margin: 0 auto;
  border: 2px solid #fff;
  border-radius: var(--radius);
  box-shadow: 0 3px 12px rgba(20,40,20,.22);
}
.stage-crop.cropped canvas {
  position: absolute;
  top: 0;
  left: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.status { margin: 0; font-size: 12.5px; color: var(--ink); font-weight: 600; min-height: 18px; text-align: center; text-shadow: 0 1px 1px rgba(255,255,255,.4); }
.status.error { color: #a23a30; }

/* ---------- Statistik ---------- */
.stats { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.stats li { background: var(--cream-2); border: 2px solid #ecd9ae; border-radius: 10px; padding: 9px 10px; }
.stats .who { font-size: 12.5px; font-weight: 700; color: var(--wood-darker); margin-bottom: 5px; }
.stats .row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats .row span:last-child { color: var(--ink); font-weight: 600; }

.feed-title { margin-top: 4px; }
.feed {
  list-style: none; margin: 0; padding: 9px 10px;
  max-height: 190px; overflow-y: auto;
  background: #263038;
  border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
}
.feed li { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.08); color: #aab5bd; }
.feed li:last-child { border-bottom: none; }
.feed .topic { color: #f0b93c; }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(30, 40, 30, .55);
  display: flex; align-items: center; justify-content: center;
}
.overlay-card {
  background: var(--cream);
  border: 2px solid #fff;
  border-radius: 16px;
  padding: 30px 34px 26px;
  text-align: center;
  max-width: 380px;
  box-shadow: 0 10px 34px rgba(0,0,0,.28);
}
.overlay-card h2 { font-size: 22px; color: var(--wood-darker); margin-bottom: 8px; }
.overlay-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .panel-right { order: 3; }
}

@media (max-width: 860px) {
  .topbar { padding: 10px 14px; }
  h1 { font-size: 16px; }

  .layout { padding: 8px; gap: 8px; }

  .layout, .stage, .panel-left, .panel-right { min-width: 0; }

  .stage { order: -1; }
  .panel-left { order: 0; }
  .panel-right { order: 3; }

  .stage-head { font-size: 12px; }
  .status { min-height: 0; margin-top: 2px; }

  .panel { padding: 10px; }

  .mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .hint-touch { display: block; }
  .hint-mouse { display: none; }

  .palette {
    grid-auto-flow: column;
    grid-auto-columns: 150px;
    grid-template-columns: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
  }
  .palette li { scroll-snap-align: start; }
}
