/* RUNEGUARD - Fantasy Tower Defense UI
   Teal forest terrain / warm gold UI. Landscape-first iPad Air (1180x820, 1180x720),
   portrait fallback. Body text 14px+, touch controls 44px+. No external assets. */

:root {
  --bg-deep: #06231e;
  --bg-mid: #0d3a30;
  --panel: rgba(10, 44, 36, 0.92);
  --panel-edge: rgba(212, 175, 55, 0.35);
  --panel-edge-bright: rgba(230, 195, 90, 0.6);
  --gold: #e6c35a;
  --gold-bright: #f4d98a;
  --gold-deep: #9c7a26;
  --teal: #17635a;
  --teal-bright: #2e9d8f;
  --text: #f2ead2;
  --text-dim: #a9c4b4;
  --danger: #e07856;
  --ok: #6fd39a;
  --hud-h: 64px;
  --cards-h: 152px;
  --help-h: 44px;
  --panel-w: 300px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Play surface: canvas fills the window; HUD/cards/help/panel overlay it. */
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* prevent touch scrolling/pinch on the play surface */
  background:
    radial-gradient(120% 90% at 30% 20%, #12584a 0%, transparent 55%),
    radial-gradient(110% 100% at 75% 85%, #0e4a3c 0%, transparent 60%),
    linear-gradient(160deg, #0d3f34 0%, #093028 55%, #06231e 100%);
}

/* ---------- HUD (top bar) ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--hud-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(6, 30, 25, 0.94), rgba(6, 30, 25, 0.78));
  border-bottom: 2px solid var(--panel-edge);
  z-index: 10;
}

#hud-left, #hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#hud-center {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: 10px;
  background: rgba(23, 99, 90, 0.55);
  border: 1px solid var(--panel-edge);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}

.hud-badge b {
  font-size: 17px;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

#badge-gold b { color: var(--gold-bright); }
#badge-lives b { color: var(--ok); }

#wave-label {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.hud-big {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

#wave-status {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Buttons (all touch controls >= 44px) ---------- */
.ctrl {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(23, 99, 90, 0.7), rgba(13, 58, 48, 0.85));
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, border-color 0.15s ease, background 0.15s ease;
}

.ctrl:active { transform: scale(0.96); }
.ctrl[disabled] { opacity: 0.45; cursor: default; }

.ctrl.primary,
.start {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  border-color: var(--panel-edge-bright);
  color: #241a05;
  font-weight: 700;
}

/* ---------- Tower cards (bottom build area) ---------- */
#tower-cards {
  position: absolute;
  left: 0; right: 0; bottom: var(--help-h);
  height: var(--cards-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(0deg, rgba(6, 30, 25, 0.95), rgba(6, 30, 25, 0.75));
  border-top: 2px solid var(--panel-edge);
  z-index: 10;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 44px;
  border-radius: 14px;
  border: 2px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(20, 74, 62, 0.9), rgba(9, 42, 35, 0.95));
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
  padding: 6px 8px;
  transition: transform 0.06s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.card:active { transform: scale(0.97); }

.card.selected {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 2px var(--gold-bright), 0 0 18px rgba(230, 195, 90, 0.45);
}

.card.unaffordable { opacity: 0.5; }

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(244, 217, 138, 0.35), rgba(23, 99, 90, 0.9));
  border: 1px solid var(--panel-edge);
  display: block;
  position: relative;
  flex: none;
}

/* Distinct procedural silhouettes per tower type */
.card-icon[data-icon="arrow"]::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 4px; height: 22px;
  transform: translate(-50%, -58%);
  background: var(--gold-bright);
}
.card-icon[data-icon="arrow"]::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
  transform: translate(-50%, -78%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid var(--gold-bright);
}

.card-icon[data-icon="splash"]::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 18px; height: 18px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-bright), #7a5a14);
  box-shadow: 0 0 10px rgba(224, 120, 86, 0.8);
}

.card-icon[data-icon="slow"]::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 16px; height: 24px;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #bfe8ff, #4aa8c9);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.card-icon[data-icon="arcane"]::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 18px; height: 18px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: linear-gradient(135deg, #c98af0, #5b2e8f);
  border: 2px solid rgba(244, 217, 138, 0.7);
  border-radius: 3px;
}

.card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.card-role {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
}

.card-cost {
  font-size: 14px;
  font-weight: 700;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

/* ---------- Start wave button ---------- */
.start {
  position: absolute;
  bottom: calc(var(--help-h) + var(--cards-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  min-height: 52px;
  padding: 10px 28px;
  border-radius: 14px;
  border: 2px solid var(--panel-edge-bright);
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold-deep) 100%);
  color: #241a05;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5), 0 0 14px rgba(230, 195, 90, 0.35);
  z-index: 11;
}

.start:active { transform: translateX(-50%) scale(0.97); }
.start[disabled] { opacity: 0.4; cursor: default; box-shadow: none; }

.start.big {
  position: static;
  transform: none;
  min-height: 56px;
  padding: 14px 36px;
  font-size: 19px;
}
.start.big:active { transform: scale(0.97); }

/* ---------- Detail panel (right side; must not cover the game board) ---------- */
#tower-panel {
  position: absolute;
  top: calc(var(--hud-h) + 10px);
  right: 12px;
  bottom: calc(var(--help-h) + var(--cards-h) + 12px);
  width: var(--panel-w);
  max-width: 34vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  z-index: 12;
}

#tp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#tp-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--gold-bright);
}

#tp-close {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

#tp-stats {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#tp-stats li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(23, 99, 90, 0.35);
  font-size: 14px;
}

#tp-stats li .k { color: var(--text-dim); }

#tp-stats li .v {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#tp-stats li .v .next {
  color: var(--ok);
  font-weight: 700;
}

#tp-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

#tp-actions .ctrl { width: 100%; }
#tp-upgrade {
  background: linear-gradient(180deg, rgba(230, 195, 90, 0.9), rgba(156, 122, 38, 0.95));
  border-color: var(--panel-edge-bright);
  color: #241a05;
  font-weight: 700;
}

#tp-empty {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  padding: 12px 4px;
}

/* ---------- Help footer ---------- */
#help {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--help-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: rgba(6, 30, 25, 0.95);
  border-top: 1px solid var(--panel-edge);
  z-index: 10;
}

#help-text {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ---------- Title / result overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 18, 15, 0.82);
  backdrop-filter: blur(5px);
}

#overlay-card {
  width: min(560px, 92vw);
  max-height: min(92vh, 880px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 22px 24px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(13, 58, 48, 0.97), rgba(6, 30, 25, 0.98));
  border: 2px solid var(--panel-edge-bright);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(244, 217, 138, 0.15);
  overflow-y: auto; /* short heights: card scrolls internally */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#overlay-card h1 {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-align: center;
  color: var(--gold-bright);
  text-shadow: 0 2px 12px rgba(230, 195, 90, 0.4);
}

.ov-sub {
  text-align: center;
  font-size: 15px;
  color: var(--text-dim);
  margin-top: -6px;
}

#ov-help {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(23, 99, 90, 0.25);
  border: 1px solid rgba(212, 175, 55, 0.2);
}

#ov-help li { padding-left: 14px; position: relative; }
#ov-help li::before {
  content: "";
  position: absolute;
  left: 0; top: 8px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
}
#ov-help b { color: var(--gold-bright); }

#ov-result {
  padding: 12px;
  border-radius: 12px;
  background: rgba(224, 120, 86, 0.15);
  border: 1px solid rgba(224, 120, 86, 0.4);
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-bright);
}

#ov-card-end { margin-top: auto; padding-top: 8px; }

/* ---------- Responsive: short landscape (1180x720) ---------- */
@media (max-height: 760px) {
  :root {
    --hud-h: 56px;
    --cards-h: 132px;
    --help-h: 40px;
    font-size: 15px;
  }

  .card { gap: 2px; padding: 4px 6px; }
  .card-icon { width: 34px; height: 34px; }
  .card-name { font-size: 14px; }
  .card-role { font-size: 14px; }
  .card-cost { font-size: 14px; }

  .hud-badge { min-height: 40px; font-size: 14px; }
  .hud-big { font-size: 20px; }
  .ctrl { min-height: 44px; padding: 6px 12px; font-size: 14px; }

  .start { min-height: 48px; font-size: 16px; }

  #overlay-card h1 { font-size: 28px; }
  #ov-help { font-size: 14px; gap: 6px; }
}

/* ---------- Responsive: portrait fallback ---------- */
@media (orientation: portrait) {
  :root { --panel-w: min(320px, 78vw); }

  #tower-cards { grid-template-columns: repeat(2, 1fr); height: auto; }
  .card { min-height: 64px; }

  #tower-panel {
    left: 12px; right: 12px; top: auto;
    bottom: calc(var(--help-h) + 260px);
    width: auto; max-width: none;
  }

  #hud-center { flex-wrap: wrap; }
  #wave-status { max-width: 140px; }
}

/* ---------- Very narrow: keep controls usable ---------- */
@media (max-width: 700px) {
  :root { font-size: 14px; }
  #hud { gap: 6px; padding: 0 8px; }
  .ctrl { min-width: 44px; padding: 6px 8px; font-size: 14px; }
  #btn-restart { display: none; } /* keep pause + speed on small screens */
}

/* Focus visibility for keyboard/touch */
button:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

/* Independent layout review: honor hidden and reserve the complete play surface. */
[hidden] { display: none !important; }
#app { height: 100dvh; }
#game { inset: auto; left: 12px; top: calc(var(--hud-h) + 10px); width: calc(100% - var(--panel-w) - 36px); height: calc(100% - var(--hud-h) - var(--cards-h) - var(--help-h) - 30px); }
#tower-panel { bottom: calc(var(--help-h) + var(--cards-h) + 76px); }
#btn-start { left: auto; right: 12px; width: var(--panel-w); max-width: 34vw; transform: none; padding: 8px 12px; }
#btn-start:active { transform: scale(.97); }
@media (orientation: portrait) {
  #app::after { content: 'Für RUNEGUARD bitte das iPad ins Querformat drehen.'; position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 32px; background: #082c25; text-align: center; color: #f4d98a; font-size: 22px; }
}
