:root {
  --kk-bg: #fff4dc;
  --kk-surface: #ffffff;
  --kk-ink: #3a2a1c;
  --kk-accent: #ff5d73;
  --kk-accent-fg: #ffffff;
  --kk-border: #e8d5b0;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  font-family: system-ui, sans-serif;
  background: var(--kk-bg);
  color: var(--kk-ink);
  overflow: hidden;
}

body > .games-shared-footer { margin-top: 0; padding: 8px 20px; }

#app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.kk-hud {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 1.05rem;
}

.kk-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: manipulation;
}
.kk-stage canvas { display: block; }

.kk-controls {
  flex: 0 0 auto;
  padding: 8px 12px 10px;
  background: var(--kk-surface);
  border-top: 2px solid var(--kk-border);
}

.kk-context {
  display: flex;
  gap: 8px;
  align-items: stretch;
  min-height: 58px;
  margin-bottom: 8px;
}
.kk-hint { margin: auto 0; flex: 1; }

/* Feste Hoehe fuer zwei Textzeilen: wechselt der Start-Knopf zwischen einer und zwei Zeilen (Countdown,
   Frueh-Start-Bonus), darf der Bedienbereich nicht mitwachsen -- sonst schrumpft die Buehne, das Canvas wird
   neu skaliert und blitzt kurz auf. */
.kk-buttons { display: flex; gap: 8px; height: 4.2rem; }
.kk-buttons .kk-btn { display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.2; padding-top: 0; padding-bottom: 0; }

.kk-btn {
  font: inherit;
  padding: 0.6rem 0.9rem;
  border: 2px solid var(--kk-border);
  border-radius: 10px;
  background: var(--kk-surface);
  color: var(--kk-ink);
  cursor: pointer;
}
.kk-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.kk-btn--primary { background: var(--kk-accent); border-color: var(--kk-accent); color: var(--kk-accent-fg); font-weight: 700; flex: 1; }

.kk-tower-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  font-size: 0.8rem;
}
.kk-tower-btn__cost { font-weight: 700; }

.kk-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(58, 42, 28, 0.55);
}
.kk-overlay[hidden] { display: none; }
.kk-overlay__box {
  background: var(--kk-surface);
  border-radius: 16px;
  padding: 24px 28px;
  text-align: center;
}
.kk-overlay__box h2 { margin: 0 0 8px; }
.kk-stars { font-size: 2rem; margin: 0 0 12px; color: #f5b942; }

.kk-hint__text { margin: 0; }
.kk-preview { margin: 0 0 4px; font-weight: 700; }
.kk-preview[hidden] { display: none; }

@keyframes kk-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px) scale(1.15); }
  40% { transform: translateX(4px) scale(1.15); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.kk-shake { display: inline-block; color: #e0455a; animation: kk-shake 0.4s; }

/* Etappe 3a: Turm-Panel (Stufe, Aufwerten, Zielwahl, Verkaufen) und vier Tuerme im Baumenue */
.kk-context { min-height: 84px; }
.kk-tower-panel { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.kk-tower-title { margin: 0; font-weight: 700; }
.kk-tower-actions { display: flex; gap: 6px; }
/* feste Hoehe fuer zwei Zeilen: bricht ein Text um (z. B. hoher Verkaufspreis), verschiebt sich nichts */
.kk-btn--on { background: #d8f2c8; border-color: #5aa83a; font-weight: 700; }
.kk-btn--warn { background: #ffe0d6; border-color: #e0623a; font-weight: 700; }
.kk-btn--small { flex: 1; min-height: 3.1rem; padding: 0.4rem 0.3rem; font-size: 0.82rem; display: flex; align-items: center; justify-content: center; text-align: center; }
/* Sechs Tuerme in einer Zeile: gleich breite, kompakte Knoepfe (eine zweite Zeile wuerde die Buehne bei jedem Tipp verkleinern). */
.kk-tower-btn { font-size: 0.6rem; flex: 1 1 0; min-width: 0; padding: 4px 2px; overflow-wrap: anywhere; hyphens: auto; }
.kk-tower-btn__cost { font-size: 0.66rem; }
.kk-tower-btn__icon { width: 34px; height: 34px; align-self: center; pointer-events: none; }


/* Etappe 3b-2: Level-Auswahl und Ergebnisfenster mit mehreren Knoepfen */
.kk-menu { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.kk-menu h1 { margin: 0 0 4px; font-size: 1.4rem; }
.kk-level { display: flex; align-items: center; gap: 12px; padding: 14px; text-align: left; flex: none; }
.kk-level__num { font-size: 1.6rem; font-weight: 700; min-width: 2rem; text-align: center; }
.kk-level__name { flex: 1; font-weight: 600; }
.kk-level__stars { color: #f5b942; font-size: 1.2rem; }
.kk-level:disabled { opacity: 0.55; }
.kk-version { margin: 8px 0 0; font-size: 0.75rem; opacity: 0.6; text-align: center; }
.kk-menu__endless { margin: 14px 0 0; font-size: 1.2rem; }
.kk-menu__hint { margin: 0; opacity: 0.7; }
.kk-end-reached { margin: 0 0 4px; font-weight: 600; }
.kk-end-best { margin: 0 0 12px; opacity: 0.8; }
.kk-end-level { margin: 0 0 4px; opacity: 0.7; }
.kk-end-buttons { display: flex; flex-direction: column; gap: 8px; }

/* Etappe 3c: Werte-Karte und zweistufiges Bauen (Vorschau, dann "Bauen") */
.kk-statcard { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 2; padding: 8px 10px; background: rgba(255, 255, 255, 0.72); border: 2px solid var(--kk-border); border-radius: 12px; font-size: 0.75rem; line-height: 1.25; pointer-events: none; }
.kk-statcard[hidden] { display: none; }
.kk-statcard__title { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.kk-statcard__icon { width: 28px; height: 28px; }
.kk-statcard table { width: 100%; border-collapse: collapse; }
.kk-statcard th, .kk-statcard td { padding: 1px 6px; text-align: right; font-weight: 400; }
.kk-statcard th:first-child { text-align: left; }
.kk-statcard thead th, .kk-statcard tr:first-child th { font-weight: 700; }
.kk-statcard .kk-stat--cur { background: rgba(245, 185, 66, 0.4); font-weight: 700; }
.kk-statcard .kk-stat--boost { color: #2e7d32; }
.kk-statcard .kk-stat--boost::after { content: ' ▲'; font-size: 0.8em; }
.kk-statcard__special { margin: 4px 0 0; }
.kk-tower-btn--armed { background: var(--kk-accent); border-color: var(--kk-accent); color: var(--kk-accent-fg); font-weight: 700; }
.kk-tower-btn--poor { opacity: 0.6; }
.kk-statcard--bottom { top: auto; bottom: 8px; }
.kk-end-rank { margin: 0 0 8px; font-weight: 600; }
.kk-rank__tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.kk-rank__tab { flex: 1 0 17%; min-width: 44px; min-height: 44px; padding: 0.5rem 0; } /* zehn Reiter in zwei Zeilen, Tippflaeche >= 44 px */
.kk-rank__tab--on { background: #d8f2c8; border-color: #5aa83a; font-weight: 700; }
.kk-rank__list { list-style: none; margin: 0; padding: 0; }
.kk-rank__row { display: flex; gap: 10px; padding: 6px 4px; border-bottom: 1px solid #0001; }
.kk-rank__row--me { background: #fff3c4; font-weight: 700; }
.kk-rank__pos { min-width: 2rem; text-align: right; }
.kk-rank__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kk-notice { margin: 0; padding: 8px 10px; background: #d8f2c8; border: 2px solid #5aa83a; border-radius: 10px; }
a.kk-btn { text-decoration: none; display: flex; align-items: center; justify-content: center; }
a.kk-btn--primary { color: var(--kk-accent-fg); }
a.kk-btn:not(.kk-btn--primary) { color: var(--kk-ink); }
