:root {
  --pergament: #f1e6cc;
  --pergament-dunkel: #e2d3b0;
  --holz: #4d3522;
  --holz-hell: #6e4f33;
  --tinte: #33261a;
  --gruen: #3f7d3a;
  --rot: #b23a2c;
  --gold: #d9a62e;
  --schatten: 0 3px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2a7a9e;
  font-family: Georgia, 'Times New Roman', serif; color: var(--tinte);
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: none;
}

#karte { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

button {
  font: inherit; color: var(--pergament); background: var(--holz); border: 1px solid #2c1d11;
  border-radius: 6px; padding: 8px 12px; min-height: 42px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--holz-hell); }
button:disabled { opacity: 0.5; cursor: default; }
button.an { background: var(--gold); color: var(--tinte); }
button.gruen { background: var(--gruen); }

#leiste {
  position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px; background: rgba(51, 35, 22, 0.92); color: var(--pergament); box-shadow: var(--schatten); font-size: 15px;
}
#leiste .wert b { font-variant-numeric: tabular-nums; }
#leiste .stufe { color: var(--gold); }
#leiste button.wert { padding: 2px 6px; min-height: 30px; font-size: 13px; }
#leiste button.feind { background: var(--rot); }
#leiste .tempo { margin-left: auto; display: flex; gap: 3px; }
#leiste .tempo button { padding: 2px 8px; min-height: 30px; font-size: 12px; min-width: 34px; }

#hinweise {
  position: fixed; top: 52px; left: 12px; right: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}

#ziel {
  max-width: 620px; padding: 8px 14px; background: rgba(241, 230, 204, 0.95); border: 1px solid var(--holz); border-radius: 8px;
  box-shadow: var(--schatten); font-size: 14px; text-align: center;
}

#meldung {
  padding: 8px 14px; background: var(--gold); border-radius: 8px; box-shadow: var(--schatten); font-weight: bold; font-size: 14px; text-align: center;
}

#knoepfe {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 6px; padding: 5px; background: rgba(51, 35, 22, 0.85); border-radius: 10px; box-shadow: var(--schatten);
}
#knoepfe button { white-space: nowrap; }

#bauleiste {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  width: min(520px, calc(100vw - 16px)); display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: rgba(241, 230, 204, 0.97); border: 1px solid var(--holz); border-radius: 8px; box-shadow: var(--schatten);
}
#bauleiste .was { flex: 1; min-width: 0; font-size: 14px; }
#bauleiste em { display: block; font-size: 12.5px; color: var(--rot); font-style: normal; min-height: 16px; }
#bauleiste em.ruhig { color: inherit; }

#tafel {
  position: fixed; right: 10px; top: 56px; bottom: 72px; width: 340px; max-width: calc(100vw - 20px); overflow-y: auto; touch-action: pan-y;
  padding: 12px; background: var(--pergament); border: 2px solid var(--holz); border-radius: 10px; box-shadow: var(--schatten); font-size: 14.5px;
}
#tafel.bau { width: 400px; }
#tafel .kopf { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
#tafel h2 { margin: 0; font-size: 18px; }
#tafel h3 { margin: 12px 0 4px; font-size: 15px; }
#tafel .kopf button { padding: 2px 10px; min-height: 34px; }
#tafel .reiter { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#tafel .reiter button { padding: 4px 8px; min-height: 34px; font-size: 13px; }
#tafel .karten { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
#tafel .karte {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; background: var(--pergament-dunkel); color: var(--tinte);
  border: 1px solid #b7a27c; border-radius: 8px; font-size: 13px; text-align: center; min-height: 112px;
}
#tafel .karte:hover:not(:disabled) { background: #f4e9c8; }
#tafel .karte.zu { filter: grayscale(0.7); }
#tafel .karte small { font-size: 11.5px; color: #5c4630; }
#tafel .bild canvas { width: 74px; height: 56px; display: block; }
#tafel .waren { display: grid; gap: 3px; }
#tafel .ware { position: relative; display: flex; justify-content: space-between; padding: 3px 6px; background: var(--pergament-dunkel); border-radius: 4px; overflow: hidden; }
#tafel .ware span, #tafel .ware b { position: relative; z-index: 1; }
#tafel .ware i { position: absolute; inset: 0 auto 0 0; background: rgba(63, 125, 58, 0.25); }
#tafel .balken { height: 8px; background: var(--pergament-dunkel); border-radius: 4px; overflow: hidden; margin: 6px 0; }
#tafel .balken i { display: block; height: 100%; background: var(--gruen); }
#tafel .laderaum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
#tafel .platz { position: relative; display: flex; justify-content: space-between; gap: 2px; padding: 4px 5px; background: var(--pergament-dunkel); border-radius: 4px; overflow: hidden; font-size: 13.5px; }
#tafel .platz span, #tafel .platz b { position: relative; z-index: 1; }
#tafel .platz i { position: absolute; inset: 0 auto 0 0; background: rgba(63, 125, 58, 0.25); }
#tafel .platz.leer { justify-content: center; color: #7a6248; }
#tafel .ladeliste { display: grid; gap: 3px; max-height: 30dvh; overflow-y: auto; }
#tafel .ladezeile { display: flex; align-items: center; gap: 6px; }
#tafel .ladezeile span { flex: 1; min-width: 0; }
#tafel .ladezeile button { padding: 2px 12px; min-height: 36px; }
#tafel .regler { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#tafel .regler input { flex: 1; min-width: 0; min-height: 34px; }
#tafel .regler b { min-width: 3.2em; text-align: right; }
#tafel .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#tafel .chips button { padding: 3px 8px; min-height: 34px; font-size: 13.5px; }
#tafel .wuensche { list-style: none; margin: 8px 0; padding: 0; columns: 2; }
#tafel .wuensche .ja { color: var(--gruen); }
#tafel .wuensche .nein { color: var(--rot); }
#tafel .hilfe { padding-left: 18px; }
#tafel .reihe { display: flex; gap: 6px; margin-top: 10px; }
#tafel .warn { color: var(--rot); font-weight: bold; }
#tafel .gut { color: var(--gruen); font-weight: bold; }
#tafel p { margin: 6px 0; }

@media (max-width: 640px) {
  #leiste { gap: 8px; font-size: 14px; padding: calc(5px + env(safe-area-inset-top, 0px)) 8px 5px; }
  #leiste .tempo button { min-width: 28px; padding: 2px 4px; }
  #leiste:has(button.wert) .stufe { display: none; }
  #hinweise { top: 84px; left: 8px; right: 8px; }
  #ziel { font-size: 13px; padding: 6px 10px; }
  #tafel, #tafel.bau {
    left: 8px; right: 8px; width: auto; top: auto; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); max-height: 58dvh;
  }
  #knoepfe { gap: 4px; padding: 4px; width: calc(100vw - 16px); justify-content: space-between; }
  #knoepfe button { padding: 6px 4px; font-size: 13.5px; flex: 1 1 auto; min-width: 0; }
}

@media (max-height: 460px) {
  #hinweise { top: 44px; }
  #ziel { display: none; }
  #tafel, #tafel.bau { top: 48px; bottom: 60px; max-height: none; }
  #knoepfe { bottom: 4px; }
  #bauleiste { bottom: 56px; }
}
