/* Belagerungswerkstatt – Oberfläche */
:root {
  --k: 54px;
  --dunkel: #4b2a12;
  --holzhell: #f0c584;
  --holz: #cf9150;
  --regal1: #9a6234;
  --regal2: #6e4120;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #7fbde6;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 800; color: var(--dunkel);
}
#welt { position: fixed; left: 0; top: 0; display: block; touch-action: none; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* Knöpfe im Holz-Stil */
.knopf {
  position: relative; width: var(--k); height: var(--k); min-width: 48px; min-height: 48px;
  border-radius: 14px; border: 3px solid var(--dunkel); padding: 0; cursor: pointer;
  background: linear-gradient(var(--holzhell), var(--holz));
  box-shadow: 0 4px 0 var(--dunkel), inset 0 2px 0 rgba(255,255,255,0.45);
  display: grid; place-items: center; touch-action: manipulation;
  transition: transform .06s, box-shadow .06s, filter .1s;
}
.knopf svg { width: 72%; height: 72%; pointer-events: none; display: block; }
.knopf:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--dunkel); }
.knopf.klein { --k: 48px; }
.knopf.an {
  background: linear-gradient(#fff6cf, #ffd166);
  box-shadow: 0 4px 0 var(--dunkel), 0 0 0 3px #fff, 0 0 14px 4px rgba(255,220,120,0.9);
}
.knopf.feuer { background: linear-gradient(#ffab6b, #e3562c); }
.knopf.feuer svg { width: 80%; height: 80%; }
.knopf .taste {
  position: absolute; right: 3px; bottom: 1px; font-size: 10px; opacity: .55; pointer-events: none; display: none;
}
@media (hover: hover) and (pointer: fine) { .knopf .taste { display: block; } .knopf:hover { filter: brightness(1.08); } }
.knopf.puls::after, .knopf.rund::after {
  content: ''; position: absolute; inset: -5px; border-radius: inherit; border: 3px solid #fff6c8;
  pointer-events: none; animation: ring 1.3s ease-out infinite;
}
@keyframes ring { 0% { transform: scale(.92); opacity: .95; } 100% { transform: scale(1.3); opacity: 0; } }
.knopf.wackel { animation: wackel .4s; }
@keyframes wackel { 20% { transform: translateX(-6px) rotate(-4deg); } 40% { transform: translateX(6px) rotate(4deg); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.ui { position: fixed; z-index: 5; display: none; }
.schirm { position: fixed; inset: 0; z-index: 10; display: none; }

/* Sichtbarkeit je Bildschirm */
.bs-werkstatt #hud, .bs-test #hud, .bs-ergebnis #hud { display: flex; }
.bs-werkstatt #leisten { display: flex; }
.bs-test #testknoepfe { display: flex; }
.bs-start #start { display: flex; }
.bs-auswahl #auswahl { display: flex; }
.bs-ergebnis #ergebnis { display: flex; }

/* HUD */
#hud {
  top: calc(6px + var(--safe-t)); left: 8px; right: 8px; align-items: flex-start; gap: 8px; pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-mitte { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; pointer-events: none !important; }
#h-name {
  font-size: 13px; background: rgba(255,248,230,0.85); border-radius: 10px; padding: 1px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.hud-pillen { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pille {
  display: inline-flex; align-items: center; gap: 3px; height: 32px; padding: 0 9px; border-radius: 16px;
  background: rgba(255,248,230,0.92); border: 2.5px solid var(--dunkel); font-size: 17px; line-height: 1;
}
.pille i, .pille .ic { display: inline-block; width: 22px; height: 22px; }
.pille svg { width: 100%; height: 100%; display: block; }
.pille small { font-size: 12px; opacity: .65; }
#h-kosten.zuviel b { color: #d62f1e; }
#h-kosten.zuviel { background: #ffe1d6; }
#h-schuesse .ic, #h-sterne .ic { width: 20px; height: 20px; }
body.hoch .pille { height: 30px; padding: 0 6px; font-size: 15px; gap: 2px; }
body.hoch .pille i { width: 19px; height: 19px; }
body.hoch #h-schuesse .ic, body.hoch #h-sterne .ic { width: 17px; height: 17px; }
body.hoch .hud-pillen { gap: 4px; flex-wrap: nowrap; }
.ic.weg { opacity: .25; filter: grayscale(1); }

/* Leisten */
#leisten { gap: 6px; }
.reihe { display: flex; gap: 6px; align-items: center; justify-content: center; }
body.hoch #leisten {
  left: 0; right: 0; bottom: 0; flex-direction: column; padding: 8px 8px calc(8px + var(--safe-b));
  background: linear-gradient(var(--regal1), var(--regal2)); border-top: 4px solid var(--dunkel);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.25);
}
body.hoch #leisten .knopf.feuer { width: calc(var(--k) * 1.9); }
body.hoch #leiste-aktion .knopf { margin-bottom: 4px; }
body.hoch #leiste-werkzeug .knopf { margin-bottom: 4px; }
body.quer #leisten { inset: 0; justify-content: space-between; pointer-events: none; background: none; }
body.quer .reihe {
  pointer-events: auto; flex-direction: column; padding: 8px 8px 12px; height: 100%;
  background: linear-gradient(90deg, var(--regal1), var(--regal2));
  box-shadow: 0 0 12px rgba(0,0,0,0.25);
}
body.quer #leiste-werkzeug { border-right: 4px solid var(--dunkel); padding-left: calc(8px + var(--safe-l)); }
body.quer #leiste-aktion { border-left: 4px solid var(--dunkel); padding-right: calc(8px + var(--safe-r)); }
body.quer #leisten .knopf.feuer { height: calc(var(--k) * 1.5); }

/* Test-Knöpfe */
#testknoepfe { left: calc(12px + var(--safe-l)); bottom: calc(12px + var(--safe-b)); gap: 10px; }

/* Start */
#start { flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(255,240,205,0.25); padding: 16px; }
#titel { width: min(92vw, 640px); height: min(34vw, 230px); }
.bs-start.quer #titel { height: min(26vh, 200px); width: min(80vw, 600px); }
.untertitel { font-size: clamp(16px, 4.5vw, 24px); background: rgba(255,248,230,0.9); padding: 4px 16px; border-radius: 16px; border: 2.5px solid var(--dunkel); text-align: center; }
.knopf.rund { --k: 112px; border-radius: 50%; background: linear-gradient(#ffb36e, #e3562c); border-width: 4px; box-shadow: 0 6px 0 var(--dunkel); }
.bs-start.quer .knopf.rund { --k: 88px; }
.optionen { display: flex; gap: 12px; }
#sprache-z { font-size: 18px; }

/* Auswahl */
#auswahl { flex-direction: column; align-items: center; background: rgba(255,240,205,0.3); padding: calc(8px + var(--safe-t)) 12px calc(12px + var(--safe-b)); gap: 10px; }
.kopf { display: flex; width: 100%; max-width: 1100px; align-items: center; justify-content: space-between; }
.kopf-sterne { display: flex; align-items: center; gap: 4px; font-size: 22px; background: rgba(255,248,230,0.92); border: 2.5px solid var(--dunkel); border-radius: 18px; padding: 4px 12px; }
.kopf-sterne svg { width: 26px; height: 26px; }
#karten { flex: 1; display: flex; gap: 14px; align-items: center; justify-content: center; width: 100%; max-width: 1100px; min-height: 0; }
body.hoch #karten { flex-direction: column; }
.karte {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 8px;
  border-radius: 18px; border: 3px solid var(--dunkel); cursor: pointer;
  background: linear-gradient(#fff3d6, #f0cf93); box-shadow: 0 5px 0 var(--dunkel); touch-action: manipulation;
}
body.quer .karte { height: min(78vh, 420px); max-width: 340px; }
body.hoch .karte { width: min(92vw, 460px); max-height: 30vh; }
.karte:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--dunkel); }
.karte canvas { flex: 1; min-height: 0; width: 100%; border-radius: 12px; border: 2.5px solid var(--dunkel); display: block; }
.karte .k-unten { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.karte .k-name { font-size: 17px; text-align: left; }
.karte .k-nr { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--dunkel); color: #ffe9b8; font-size: 15px; margin-right: 6px; }
.karte .k-sterne { display: flex; gap: 2px; }
.karte .k-sterne svg { width: 24px; height: 24px; }
body.quer .karte .k-unten { flex-direction: column; gap: 2px; }
body.quer .karte .k-name { font-size: 15px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Ergebnis */
#ergebnis { align-items: center; justify-content: center; background: rgba(40,22,8,0.45); padding: 16px; }
.tafel {
  background: linear-gradient(#fff3d6, #efcd90); border: 4px solid var(--dunkel); border-radius: 22px;
  box-shadow: 0 8px 0 var(--dunkel), 0 10px 30px rgba(0,0,0,0.35);
  padding: 14px 18px 18px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(92vw, 440px); animation: rein .35s cubic-bezier(.2,1.4,.5,1);
}
@keyframes rein { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tafel h2 { margin: 0; font-size: clamp(24px, 7vw, 34px); text-align: center; }
.e-bild svg { width: 90px; height: 90px; display: block; }
.e-bild .wackelt { animation: burgwackel 1.2s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes burgwackel { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.e-sterne { display: flex; gap: 10px; }
.e-stern { display: flex; flex-direction: column; align-items: center; font-size: 12px; gap: 2px; width: 84px; text-align: center; }
.e-stern svg { width: 56px; height: 56px; }
.e-stern.an svg { animation: sternrein .5s cubic-bezier(.2,1.6,.5,1) backwards; }
.e-stern:nth-child(2).an svg { animation-delay: .25s; }
.e-stern:nth-child(3).an svg { animation-delay: .5s; }
@keyframes sternrein { from { transform: scale(0) rotate(-60deg); } to { transform: scale(1); } }
.e-tipp { font-size: 15px; text-align: center; opacity: .85; }
.e-knoepfe { display: flex; gap: 12px; margin-top: 6px; }
.e-knoepfe .knopf { --k: 64px; }
.bs-ergebnis #hud { opacity: .35; pointer-events: none; }

/* Hinweis-Blase */
#hinweis {
  position: fixed; left: 50%; top: 22%; z-index: 20; transform: translate(-50%, -50%) scale(.6); opacity: 0;
  background: rgba(255,248,230,0.96); border: 3px solid var(--dunkel); border-radius: 18px; padding: 8px 18px;
  font-size: 24px; display: flex; align-items: center; gap: 8px; pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2,1.5,.5,1);
  white-space: nowrap;
}
#hinweis.zeigen { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#hinweis svg { width: 28px; height: 28px; }

/* Ergebnis kompakt bei wenig Höhe (Handy quer) */
@media (max-height: 520px) {
  .bs-ergebnis .tafel { padding: 8px 18px 12px; gap: 4px; width: min(70vw, 420px); }
  .bs-ergebnis .tafel h2 { font-size: clamp(20px, 6vh, 28px); }
  .bs-ergebnis #hud { opacity: .0; }
  .bs-ergebnis .e-bild svg { width: 48px; height: 48px; }
  .bs-ergebnis .e-stern svg { width: 40px; height: 40px; }
  .bs-ergebnis .e-stern { font-size: 11px; }
  .bs-ergebnis .e-knoepfe .knopf { --k: 52px; }
}
