:root {
  --color-primary: #ec4899;
  --color-on-primary: #ffffff;
  --color-secondary: #8b5cf6;
  --color-accent: #f59e0b;
  --color-background: #fdf2f8;
  --color-foreground: #0f172a;
  --color-muted: #fce7f3;
  --color-border: #f9a8d4;
  --color-destructive: #dc2626;
  --shadow: 0 10px 0 #f9a8d4, 0 18px 28px rgba(244, 114, 182, 0.28);
  --radius: 22px;
  --font-title: "Fredoka", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100dvh;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 12% 10%, #fce7f3 0, transparent 42%),
    radial-gradient(circle at 90% 0%, #fde68a 0, transparent 36%),
    var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-body);
}

html.is-playing,
html.is-playing body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.phone {
  width: min(1100px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
}

html.is-playing .phone {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

#app {
  max-width: none;
  margin: 0;
  height: 100%;
  min-height: 0;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  position: relative;
}

.hud {
  display: grid;
  grid-template-columns: minmax(110px, 1.2fr) auto;
  gap: 6px 8px;
  align-items: center;
}

.energy {
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 18px;
  padding: 6px 10px;
  box-shadow: 0 6px 0 #fbcfe8;
}

.energy-label {
  display: block;
  font-family: var(--font-title);
  font-size: 0.95rem;
}

.energy-track {
  position: relative;
  height: 14px;
  margin-top: 6px;
  background: #fce7f3;
  border-radius: 999px;
  overflow: hidden;
}

.energy-next,
.energy-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  border-radius: inherit;
}

.energy-next {
  background: #fde68a;
}

.energy-fill {
  background: #f59e0b;
}

.energy-enemy .energy-fill {
  background: #fb7185;
}

.energy-count {
  margin: 4px 0 0;
  font-weight: 700;
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.4;
}

#field {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  border: 5px solid #f9a8d4;
  border-radius: 22px;
  box-shadow: var(--shadow);
  background: #7dd3fc;
  cursor: pointer;
  touch-action: none;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.card {
  position: relative;
  min-height: 78px;
  padding: 6px 4px 8px;
  border: 4px solid #f9a8d4;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 6px 0 #fbcfe8;
  cursor: pointer;
  font-family: var(--font-body);
  color: inherit;
  transition: transform 180ms ease-out, box-shadow 180ms ease-out, border-color 180ms ease-out;
}

.card:hover:not(:disabled):not(.is-locked) {
  transform: translateY(-3px);
}

.card:focus-visible {
  outline: 3px solid #8b5cf6;
  outline-offset: 3px;
}

.card.is-selected {
  border-color: #8b5cf6;
  box-shadow: 0 6px 0 #c4b5fd;
}

.card:disabled,
.card.is-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.card-art {
  display: block;
  width: 64px;
  height: 46px;
  margin: 2px auto 0;
  pointer-events: none;
}

.card-cost {
  position: absolute;
  top: 6px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f59e0b;
  color: #0f172a;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.card-key {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.75rem;
  color: #9d174d;
}

.card-name {
  display: block;
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.95rem;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
}

.overlay[hidden] {
  display: none !important;
}

.panel {
  width: min(460px, 100%);
  background: #fff;
  border: 5px solid #f9a8d4;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}

h1 {
  margin: 0 0 10px;
  font-family: var(--font-title);
  font-size: 2.2rem;
}

.panel p {
  margin: 0 0 18px;
  line-height: 1.5;
}

#btn-start {
  min-height: 48px;
  min-width: 180px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: #ec4899;
  color: #fff;
  font-family: var(--font-title);
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: 0 6px 0 #be185d;
}

#btn-start:hover {
  transform: translateY(-1px);
}

#btn-start:focus-visible {
  outline: 3px solid #8b5cf6;
  outline-offset: 3px;
}

.screen[hidden],
.overlay[hidden] {
  display: none !important;
}

.screen {
  max-width: none;
  margin: 0;
  min-height: 100dvh;
  padding: 16px 16px 28px;
}

.home-actions {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.home-actions .btn {
  min-height: 52px;
  font-size: 1.15rem;
}

.field-label {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  font-weight: 700;
}

.field-label[hidden] {
  display: none !important;
}

.field-label select,
.field-label input {
  min-height: 48px;
  border: 3px solid #f9a8d4;
  border-radius: 16px;
  padding: 0 12px;
  font: inherit;
}

.shop-cats {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.code-show {
  font-size: 1.4rem;
  text-align: center;
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 18px;
  padding: 12px;
}

.tower-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 118px;
  z-index: 4;
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 20px;
  padding: 10px;
  box-shadow: var(--shadow);
  max-height: 42%;
  overflow: auto;
}

.tower-menu[hidden] {
  display: none !important;
}

.tower-menu-title {
  margin: 0 0 8px;
  font-family: var(--font-title);
}

.tower-opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin: 0 0 6px;
  padding: 8px 10px;
  border: 3px solid #f9a8d4;
  border-radius: 14px;
  background: #fff;
  font: inherit;
}

.tower-opt.is-locked {
  opacity: 0.45;
}

.battle-coins {
  margin: 4px auto;
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.8rem;
}

.coins {
  margin: 0;
  background: #fff;
  border: 3px solid #f9a8d4;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: #ec4899;
  color: #fff;
  font-family: var(--font-title);
  cursor: pointer;
  box-shadow: 0 4px 0 #be185d;
}

.btn-ghost {
  background: #fff;
  color: #9d174d;
  border: 3px solid #f9a8d4;
  box-shadow: none;
}

.btn-primary {
  min-width: 180px;
  font-size: 1.1rem;
}

.btn-tiny {
  min-height: 36px;
  font-size: 0.9rem;
}

.btn:focus-visible,
.card:focus-visible,
.node:focus-visible,
.slot:focus-visible {
  outline: 3px solid #8b5cf6;
  outline-offset: 3px;
}

.level-map {
  display: grid;
  gap: 18px;
}

.world {
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 24px;
  padding: 14px;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--hill) 35%, #fbcfe8);
}

.world h2 {
  margin: 0 0 10px;
  font-family: var(--font-title);
}

.nodes {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.node {
  min-height: 64px;
  border: 3px solid #f9a8d4;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  font-family: var(--font-body);
}

.node-num {
  display: block;
  font-family: var(--font-title);
  font-size: 1.1rem;
}

.node-stars {
  color: #d97706;
  letter-spacing: 1px;
}

.node.is-current {
  border-color: #8b5cf6;
  box-shadow: 0 4px 0 #c4b5fd;
}

.node.is-boss {
  background: #fef3c7;
}

.node.is-locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.shop-grid {
  display: grid;
  gap: 22px;
}

.shop-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.shop-card {
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 20px;
  padding: 12px;
}

.shop-card.is-locked {
  opacity: 0.5;
}

.slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.slot {
  min-height: 72px;
  border: 4px solid #f9a8d4;
  border-radius: 18px;
  background: #fff;
  cursor: pointer;
  font-family: var(--font-body);
}

.slot strong {
  display: block;
  font-family: var(--font-title);
}

.roster,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
}

.chip,
.level-chip {
  background: #fff;
  border: 3px solid #f9a8d4;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
}

.battle-mid {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px 8px;
  text-align: right;
  min-width: 0;
}

.battle-mid .level-chip,
.battle-mid .battle-coins {
  margin: 0;
  white-space: nowrap;
  font-size: 0.78rem;
}

.battle-mid .level-chip {
  padding: 3px 8px;
}

.battle-mid .btn-tiny {
  flex: 0 0 auto;
}

.energy-enemy {
  display: none !important;
}

.stars-big {
  font-size: 2rem;
  color: #d97706;
  margin: 0 0 8px;
}

.screen-battle {
  max-width: none;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  padding: env(safe-area-inset-top, 0px) 0 0;
  overflow: hidden;
}

html.is-playing .screen-battle,
html.is-playing #app {
  height: 100%;
}

#rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: #0f172a;
  color: #fff;
  padding: 32px;
  text-align: center;
  font-family: var(--font-title);
  font-size: 1.4rem;
}

#rotate-hint[hidden] {
  display: none !important;
}

@media (max-width: 800px) {
  .energy {
    padding: 4px 8px;
    border-width: 3px;
    border-radius: 14px;
    box-shadow: 0 4px 0 #fbcfe8;
  }

  .energy-label {
    font-size: 0.8rem;
  }

  .energy-track {
    height: 10px;
    margin-top: 3px;
  }

  .energy-count {
    margin: 2px 0 0;
    font-size: 0.8rem;
  }

  .cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nodes {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .card-name {
    font-size: 0.8rem;
  }
}

@media (max-height: 740px) {
  .card {
    min-height: 56px;
    padding: 4px 2px 6px;
  }

  .cards {
    gap: 4px;
  }

  #app {
    gap: 4px;
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .btn,
  #btn-start {
    transition: none;
  }
}

.color-legend {
  font-weight: 700;
  margin: 12px 0 8px;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 4px 0 #f9a8d4;
  cursor: pointer;
  padding: 0;
}

.color-swatch.is-on {
  outline: 4px solid #0f172a;
  outline-offset: 2px;
}

.freund-code,
.code-show {
  font-family: var(--font-title);
  font-size: 1.6rem;
  letter-spacing: 0.12em;
  text-align: center;
  margin: 12px 0;
}

.freund-code-row,
.freund-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.freund-liste {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.freund-zeile {
  background: #fff;
  border: 4px solid #f9a8d4;
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 6px 0 #fbcfe8;
}

.freund-kopf {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.freund-name {
  font-weight: 800;
}

.freund-more {
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
}

.freund-status {
  display: inline-block;
  margin-top: 6px;
  font-weight: 700;
  color: #64748b;
}

.freund-status.on {
  color: #15803d;
}

.freund-confirm,
.freund-invite {
  margin-top: 10px;
}

.freund-confirm-btns,
.freund-invite-btns,
.freund-decide {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

#overlay-freund-sheet,
#overlay-freund-invite,
#overlay-freund-wait,
#overlay-freund-offline {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.45);
  padding: 20px;
}

#overlay-freund-sheet[hidden],
#overlay-freund-invite[hidden],
#overlay-freund-wait[hidden],
#overlay-freund-offline[hidden] {
  display: none !important;
}
