:root {
  --bg: #1b1b1b;
  --bg-soft: #1f1f1f;
  --nav-bg: rgba(27, 27, 27, 0.98);
  --card-bg: #242424;
  --card-hover: #2a2a2a;
  --border-color: #333333;
  --text: #ffffff;
  --text-muted: #8e8e93;
  --accent: #8354f7;
  --accent-hover: #9b72f9;
  --accent-tint: rgba(131, 84, 247, 0.12);
  --up: #34c759;
  --down: #ff3b30;
  --played: #6b7280;
  --radius: 8px;
  --radius-lg: 10px;
  --btn-radius: 6px;
  --font: "Montserrat", "Codec Pro", system-ui, -apple-system, sans-serif;
  --brand-gradient: linear-gradient(135deg, #8354f7, #9b72f9);
}

[data-theme="light"] {
  --bg: #f4f4f6;
  --bg-soft: #ececf0;
  --nav-bg: rgba(255, 255, 255, 0.97);
  --card-bg: #ffffff;
  --card-hover: #efeff2;
  --border-color: #e2e2e7;
  --text: #1c1c1e;
  --text-muted: #6b6b72;
  --up: #1f9d49;
  --down: #e02424;
  --played: #9aa0a8;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  width: 100%;
  max-width: 720px;
  padding: 28px 20px 20px;
}

.screen[hidden] {
  display: none;
}

/* Kopfbereich / Menü ----------------------------------------------------- */
.app__head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--brand-gradient);
  color: #fff;
  display: grid;
  place-items: center;
}

.brand svg {
  width: 26px;
  height: 26px;
}

.app__title {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
}

.app__sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Levelkarten ------------------------------------------------------------ */
.levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.level-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 18px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.level-card:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--card-hover);
}

.level-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.level-card:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.level-card__no {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--theme-color, var(--accent));
  background: color-mix(in srgb, var(--theme-color, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--theme-color, var(--accent)) 45%, transparent);
}

.level-card__body {
  min-width: 0;
  flex: 1;
}

.level-card__name {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.4px;
}

.level-card__meta {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.level-card__status {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.level-card__status--done {
  border-color: var(--up);
  color: var(--up);
  background: color-mix(in srgb, var(--up) 12%, transparent);
}

/* Spiel-Screen ----------------------------------------------------------- */
.screen--game {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gamebar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.gamebar__info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.gamebar__name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.4px;
  line-height: 1.2;
}

.gamebar__theme {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.stats {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--accent-tint);
}

.stat__label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat__value {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* Bühne ------------------------------------------------------------------ */
.stage {
  display: flex;
  justify-content: center;
}

.stage__frame {
  position: relative;
  width: min(100%, calc(var(--avail) * (960 / 528)));
  aspect-ratio: 960 / 528;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 10px 30px rgba(131, 84, 247, 0.15);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlay ---------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 28px 24px;
  background: rgba(27, 27, 27, 0.84);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.overlay__title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
}

.overlay__text {
  margin: 0;
  max-width: 40ch;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.overlay__text strong {
  color: var(--accent-hover);
  font-weight: 800;
}

.overlay__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

/* Komponenten ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 4px 14px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  background: var(--accent-tint);
  color: var(--accent-hover);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge--muted {
  border-color: var(--border-color);
  background: var(--card-hover);
  color: var(--text-muted);
}

.badge--success {
  border-color: var(--up);
  background: color-mix(in srgb, var(--up) 12%, transparent);
  color: var(--up);
}

.btn {
  min-height: 46px;
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease;
}

.btn--primary {
  background: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text);
}

.btn--ghost:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.btn--icon {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.btn--icon svg {
  width: 22px;
  height: 22px;
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

/* Touch-Steuerung -------------------------------------------------------- */
.touch {
  display: none;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px;
}

.touch__move {
  display: flex;
  gap: 12px;
}

.touch__btn {
  width: 68px;
  height: 68px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.15s ease;
}

.touch__btn--jump {
  width: 84px;
  background: var(--accent);
  border-color: var(--accent);
}

.touch__btn.is-down {
  transform: translateY(1px);
  background: var(--accent);
  border-color: var(--accent);
}

/* Hinweis & Fuß ---------------------------------------------------------- */
.hint {
  margin: 22px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

kbd {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card-hover);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 6px;
  margin: 0 1px;
}

.app__foot {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

/* Steuerung erfolgt auf Mobil ueber unsichtbare Zonen (keine Tasten) */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Zurück zur Spielhalle -------------------------------------------------- */
.backlink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  width: fit-content;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  transition: color 0.2s ease;
}

.backlink svg {
  width: 16px;
  height: 16px;
}

.backlink:hover {
  color: var(--accent-hover);
}

.backlink:focus-visible {
  outline: none;
  color: var(--accent-hover);
}


/* Vollbild-/Fokusmodus (mobile) --------------------------------------- */
:root {
  --avail: calc(100svh - 280px);
}

html.is-fs {
  --avail: calc(100dvh - 72px);
}

/* Info-Leiste liegt im Fokusmodus über dem Spielfeld, damit dieses größer wird */
html.is-fs .screen--game {
  position: relative;
}

html.is-fs .gamebar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 6px 6px 0;
  background: linear-gradient(to bottom, rgba(20, 20, 20, 0.72), transparent);
}

/* Kurzer Steuerungshinweis beim Levelstart (nur Touch) */
.gesture-hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translate(-50%, 12px);
  z-index: 30;
  max-width: 88vw;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.gesture-hint.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}
