/* Turmverteidigung · ISSON Spiele
   Farben, Schriften und Briefkopf kommen aus /mediathek/spiele/gemeinsam/spiele.css.
   Hier nur die Anordnung im Stil „Lieferschein“: weisses Papier, schwarze Linien,
   schwarzer Spielbildschirm, Cyan nur als Markierung. */

* { box-sizing: border-box; }

body {
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 48px) 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- Kopfzeile ---------- */

.app__bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 24px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--tinte);
  padding-bottom: 14px;
}

.app__title {
  margin: 0;
  font-family: var(--schrift-titel);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

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

.meta__item { display: flex; align-items: baseline; gap: 7px; }

.meta__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-leise);
}

.meta__value {
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--tinte);
}

.meta__value--low { color: var(--fehler); }

/* ---------- Anordnung ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* ---------- Spielfeld ---------- */

.board__bar {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-width: 0;
}

.board__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-leise);
}

.board__level {
  margin: 0;
  font-family: var(--schrift-titel);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.board__meta {
  font-size: 0.85rem;
  color: var(--text-leise);
  font-variant-numeric: tabular-nums;
}

.board__diff {
  margin-left: auto;
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--tinte);
  white-space: nowrap;
}

.board__frame {
  position: relative;
  width: 100%;
  /* `max-width` wird pro Karte gesetzt (68vh × Spalten/Zeilen), damit hohe
     Karten wie 22×22 nicht die ganze Seite füllen. */
  max-width: 100%;
  margin-inline: auto;
  aspect-ratio: 816 / 510;
  background: var(--bildschirm);
  border: 1px solid var(--tinte);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bildschirm);
  touch-action: manipulation;
  cursor: pointer;
}

.banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 14px;
  background: var(--bildschirm);
  border: 1px solid var(--bildschirm-text);
  color: var(--bildschirm-text);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner[hidden] { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.86);
  color: var(--bildschirm-text);
  text-align: center;
  padding: 16px;
  overflow: auto;
}

.overlay[hidden] { display: none; }

.overlay__title {
  margin: 0;
  font-family: var(--schrift-titel);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.overlay__title--bad { color: #FF5A4F; }
.overlay__title--good { color: var(--cyan-hell); }

.overlay__hint {
  margin: 0;
  max-width: 44ch;
  color: var(--bildschirm-leise);
  font-size: 0.85rem;
}

.overlay__stats {
  margin: 0;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--bildschirm-text);
  white-space: pre-line;
}

.overlay :focus-visible { outline-color: var(--papier); }

/* ---------- Steuerung ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.55rem 1rem;
  font: 600 0.9rem/1.2 var(--schrift-text);
  color: var(--tinte);
  background: var(--papier);
  border: 2px solid var(--tinte);
  border-radius: 0;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.button:hover:not(:disabled) { background: var(--tinte); color: var(--papier); }
.button:disabled { color: var(--text-leise); border-color: var(--linie); cursor: not-allowed; }

/* Hauptknopf: Tinte mit weisser Schrift, beim Darüberfahren umgekehrt */
.button--primary { color: var(--papier); background: var(--tinte); }
.button--primary:hover:not(:disabled) { background: var(--papier); color: var(--tinte); }
.button--primary:disabled { background: var(--papier); }

.button--ghost { border-width: 1px; }

/* Auf dem schwarzen Bildschirm: weisser Knopf */
.button--hell { color: var(--tinte); background: var(--papier); border-color: var(--papier); }
.button--hell:hover:not(:disabled) { background: transparent; color: var(--papier); }

.speeds {
  display: inline-flex;
  border: 1px solid var(--tinte);
}

.chip {
  min-width: 44px;
  min-height: 42px;
  padding: 0 12px;
  font: 600 0.85rem/1 var(--schrift-text);
  font-variant-numeric: tabular-nums;
  color: var(--tinte);
  background: var(--papier);
  border: 0;
  border-right: 1px solid var(--tinte);
  border-radius: 0;
  cursor: pointer;
}

.chip:last-child { border-right: 0; }
.chip:hover { box-shadow: inset 0 -3px 0 var(--cyan); }
.chip[aria-pressed="true"] { background: var(--tinte); color: var(--papier); }
.chip[aria-pressed="true"]:hover { box-shadow: inset 0 -3px 0 var(--cyan); }

.notice {
  margin: 0;
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--text-leise);
}

.notice--good { color: var(--tinte); font-weight: 600; }
.notice--warn { color: var(--tinte); }
.notice--bad { color: var(--fehler); font-weight: 600; }

/* ---------- Panels ---------- */

.panel {
  background: var(--papier);
  border-top: 2px solid var(--tinte);
  padding-top: 10px;
}

.panel__title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tinte);
}

.panel__hint {
  margin: -2px 0 10px;
  font-size: 0.85rem;
  color: var(--text-leise);
}

/* ---------- Wellenvorschau ---------- */

.wave-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-leise);
}

.wave-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 9px;
  border: 1px solid var(--tinte);
  background: var(--papier);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--tinte);
}

/* Gegnerfarbe wie auf dem Bildschirm: kleiner Punkt auf schwarzem Grund */
.wave-chip b {
  width: 12px; height: 12px;
  display: inline-block;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--tinte);
}
.wave-chip--boss { border-width: 2px; font-weight: 600; }

/* ---------- Kartenauswahl (Positionsliste) ---------- */

.levels {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--linie);
}

.level {
  position: relative;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 0;
  border-top: 1px solid var(--linie);
  border-radius: 0;
  background: var(--papier);
  padding: 10px 8px 10px 12px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

/* Auswahl ohne Seitenbalken: Hover hellgrau, aktive Karte mit Cyan-Rahmen ums Bild */
.level { transition: background-color 160ms var(--ease); }
.level:hover { background: var(--surface-2); }
.level.is-active .level__thumb { outline: 2px solid var(--cyan); outline-offset: 2px; }
.level.is-active .level__name { text-decoration: underline; text-decoration-color: var(--cyan); text-decoration-thickness: 2px; text-underline-offset: 0.2em; }

.level__thumb {
  display: block;
  width: 84px;
  height: 56px;
  border: 1px solid var(--tinte);
  background: var(--bildschirm);
}

.level__body { min-width: 0; }

.level__name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
}

.level__diff {
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--tinte);
  font-weight: 400;
}

.level__tag {
  margin: 2px 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-leise);
}

.level__meta {
  margin: 3px 0 0;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-leise);
}

/* ---------- Turmbau (Positionsliste) ---------- */

.shop {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--linie);
}

.card {
  position: relative;
  border-top: 1px solid var(--linie);
  background: var(--papier);
  padding: 10px 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.card { transition: background-color 160ms var(--ease); }
.card:hover { background: var(--surface-2); }
.card.is-active { box-shadow: inset 0 0 0 2px var(--tinte); }
.card.is-active .card__name { text-decoration: underline 2px var(--cyan); text-underline-offset: 0.2em; }
.card.is-locked .card__name,
.card.is-locked .card__desc,
.card.is-locked .card__stats { color: var(--text-leise); }

.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Turmzeichen wie auf dem Bildschirm: Schwarz mit hellem Buchstaben */
.card__icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--bildschirm);
  font-family: var(--schrift-titel);
  font-weight: 700;
  font-size: 0.95rem;
}

.card__name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.card__desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-leise);
  line-height: 1.35;
}

.card__stats {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-leise);
}

.card__stats b { color: var(--tinte); font-weight: 600; }

.card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card__price {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--tinte);
}

.card__state {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-leise);
}

.card__state--no { color: var(--fehler); }
.card__state--yes { color: var(--tinte); }

/* ---------- Gewählter Turm ---------- */

.inspector {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.insp__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.insp__title { margin: 0; font-size: 0.95rem; font-weight: 600; }
.insp__tag { margin: 0; font-size: 0.8rem; color: var(--text-leise); }

.insp__stats {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  font-size: 0.85rem;
}

.insp__stats dt,
.insp__stats dd { padding: 4px 0; border-bottom: 1px solid var(--linie); }
.insp__stats dt { color: var(--text-leise); }
.insp__stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--tinte);
}

.upgrades {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upgrade {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--tinte);
  border-radius: 0;
  background: var(--papier);
  color: var(--tinte);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.upgrade:hover:not(:disabled) { background: var(--tinte); color: var(--papier); }
.upgrade:hover:not(:disabled) .upgrade__hint { color: var(--text-hell-leise); }
.upgrade:disabled { cursor: not-allowed; border-color: var(--linie); color: var(--text-leise); }

.upgrade__label { display: block; font-weight: 600; }
.upgrade__hint { display: block; color: var(--text-leise); font-size: 0.78rem; }
.upgrade__cost { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.sell {
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--fehler);
  border-radius: 0;
  background: var(--papier);
  color: var(--fehler);
  font: 600 0.85rem/1.2 var(--schrift-text);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.sell:hover { background: var(--fehler); color: var(--papier); }

.empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-leise);
  line-height: 1.5;
}

/* ---------- Tastenlegende ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  padding-top: 14px;
  border-top: 1px solid var(--linie);
}

.legend__copyright {
  flex-basis: 100%;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-leise);
}

.legend__group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--text-leise);
}

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 2px 6px;
  font-family: var(--schrift-text);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  color: var(--tinte);
  background: var(--papier);
  border: 1px solid var(--tinte);
  border-radius: 0;
}

/* Kartenwahl steht links unter dem Spielfeld, zweispaltig */
@media (min-width: 1041px) {
  .stage .levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; border-bottom: 0; }
  .stage .level { border-top: 0; border-bottom: 1px solid var(--linie); }
}

/* ---------- Eine Spalte: Turmbau direkt unter das Spielfeld ---------- */

@media (max-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .stage, .side { display: contents; }
  .board__bar { order: 1; }
  .board__frame { order: 2; }
  .controls { order: 3; }
  .notice { order: 4; }
  .panel--bau { order: 5; }
  .panel--turm { order: 6; }
  .panel--welle { order: 7; }
  .panel--karten { order: 8; }
  .shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); column-gap: 16px; border-bottom: 0; }
  .card { border-bottom: 1px solid var(--linie); border-top: 0; }
  .levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); column-gap: 16px; border-bottom: 0; }
  .level { border-top: 0; border-bottom: 1px solid var(--linie); }
}

@media (max-width: 560px) {
  .app { padding: 16px 16px 28px; gap: 14px; }
  .app__meta { gap: 4px 14px; }
  .meta__value { font-size: 1.05rem; }
  .board__diff { margin-left: 0; }
  .shop { grid-template-columns: 1fr 1fr; column-gap: 10px; }
  .card { padding: 8px 4px 8px 10px; gap: 4px; }
  .card__desc, .card__stats { display: none; }
  .card__head { gap: 8px; }
  .card__icon { width: 26px; height: 26px; }
  .card__name { font-size: 0.85rem; line-height: 1.2; }
  .levels { grid-template-columns: 1fr; }
  .controls .button { flex: 1 1 auto; padding-inline: 0.7rem; }
  .legend { padding-top: 10px; }
  .legend__group { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  .legend__group { display: none; }
}
