:root {
  color-scheme: dark;
  --bg: #0B111A;
  --bg-glow: #142238;
  --surface: #141F30;
  --surface-border: rgba(255, 255, 255, 0.14);

  --text: #F8FAFC;
  --text-muted: #CBD5E1;

  --blue-top: #2563EB;
  --blue-bottom: #1A45B8;
  --blue-border: rgba(147, 197, 253, 0.45);
  --blue-shadow: rgba(29, 78, 216, 0.36);

  --green-top: #169B46;
  --green-bottom: #117435;
  --green-border: #4ADE80;
  --green-ring: rgba(74, 222, 128, 0.42);
  --green-shadow: rgba(22, 163, 74, 0.42);

  --red-top: #DC2626;
  --red-bottom: #B01919;
  --red-border: rgba(252, 165, 165, 0.42);
  --red-shadow: rgba(220, 38, 38, 0.36);

  --slate-top: #243247;
  --slate-bottom: #192434;
  --slate-border: rgba(148, 163, 184, 0.35);

  --dot-idle: #64748B;
  --dot-loading: #F59E0B;
  --dot-playing: #22C55E;
  --dot-error: #EF4444;

  --radius-card: 20px;
  --radius-tile: 22px;
  --radius-btn: 20px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background:
    radial-gradient(ellipse 90% 45% at 50% 0%, var(--bg-glow) 0%, var(--bg) 68%);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.app {
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.2dvh, 18px);
  padding:
    max(14px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* Header */
.app-header {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 2px 48px 0;
}

.app-title {
  margin: 0;
  font-size: clamp(1.65rem, 6vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}

/* Unauffälliges Menü-Icon oben rechts */
.menu-btn {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: rgba(203, 213, 225, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.menu-btn svg {
  width: 24px;
  height: 24px;
}

.menu-btn:hover,
.menu-btn:active,
.menu-btn:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
}

.menu-btn:focus-visible {
  outline: 2px solid #FFFFFF;
  outline-offset: 2px;
}

/* Status card */
.status-card {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: clamp(12px, 2dvh, 18px) 18px;
  background: var(--surface);
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.status-card[data-state="playing"] {
  border-color: rgba(74, 222, 128, 0.55);
  background: #10251F;
}

.status-card[data-state="loading"],
.status-card[data-state="reconnecting"] {
  border-color: rgba(245, 158, 11, 0.55);
}

.status-card[data-state="error"],
.status-card[data-state="offline"] {
  border-color: rgba(239, 68, 68, 0.65);
  background: #241319;
}

.status-dot {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dot-idle);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.status-card[data-state="playing"] .status-dot {
  background: var(--dot-playing);
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.24);
}

.status-card[data-state="loading"] .status-dot,
.status-card[data-state="reconnecting"] .status-dot {
  background: var(--dot-loading);
  box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.22);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-card[data-state="error"] .status-dot,
.status-card[data-state="offline"] .status-dot {
  background: var(--dot-error);
  box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.22);
}

.status-text {
  min-width: 0;
  flex: 1;
}

.status-station {
  font-size: clamp(1.2rem, 4.6vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-detail {
  margin-top: 3px;
  font-size: clamp(0.95rem, 3.6vw, 1.12rem);
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-muted);
}

/* 2x2 Station Grid */
.station-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(12px, 3vw, 16px);
}

.station-btn {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: clamp(12px, 2.5vw, 20px) 8px;
  border: 2px solid var(--blue-border);
  border-radius: var(--radius-tile);
  background: linear-gradient(180deg, var(--blue-top) 0%, var(--blue-bottom) 100%);
  color: #FFFFFF;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2dvh, 16px);
  text-align: center;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 10px 22px var(--blue-shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.station-btn:active {
  transform: scale(0.965);
}

.station-btn:focus-visible,
.stop-btn:focus-visible,
.output-btn:focus-visible {
  outline: 3px solid #FFFFFF;
  outline-offset: 3px;
}

.station-btn.is-active {
  background: linear-gradient(180deg, var(--green-top) 0%, var(--green-bottom) 100%);
  border-color: var(--green-border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 0 0 3px var(--green-ring),
    0 12px 26px var(--green-shadow);
}

.station-icon {
  width: clamp(40px, 11vw, 58px);
  height: clamp(40px, 11vw, 58px);
  flex: 0 0 auto;
  color: #FFFFFF;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.22));
}

.station-btn.is-loading .station-icon {
  animation: pulse-icon 1.2s ease-in-out infinite;
}

.station-btn.is-playing .wave-outer {
  animation: wave-pulse 1.6s ease-in-out infinite;
}

.station-name {
  font-size: clamp(0.98rem, 4.1vw, 1.48rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  max-width: 100%;
  text-wrap: balance;
  overflow-wrap: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}

/* Bottom controls */
.controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.5dvh, 14px);
}

.stop-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: clamp(64px, 10dvh, 84px);
  padding: 14px 20px;
  border: 2px solid var(--red-border);
  border-radius: var(--radius-btn);
  background: linear-gradient(180deg, var(--red-top) 0%, var(--red-bottom) 100%);
  color: #FFFFFF;
  font-family: inherit;
  font-size: clamp(1.3rem, 5vw, 1.65rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 10px 22px var(--red-shadow);
  transition: transform 0.12s ease, opacity 0.2s ease;
}

.stop-btn:active {
  transform: scale(0.975);
}

.output-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: clamp(50px, 7.2dvh, 62px);
  padding: 10px 18px;
  border: 1.5px solid var(--slate-border);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--slate-top) 0%, var(--slate-bottom) 100%);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease;
}

.output-btn.is-wireless {
  border-color: rgba(56, 189, 248, 0.7);
  color: #E0F2FE;
}

.output-btn:active {
  transform: scale(0.98);
}

.output-btn[hidden] {
  display: none !important;
}

.btn-icon {
  width: clamp(24px, 6vw, 30px);
  height: clamp(24px, 6vw, 30px);
  flex: 0 0 auto;
}

/* Animations */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.86); }
}

@keyframes pulse-icon {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes wave-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot,
  .station-icon,
  .wave-outer {
    animation: none !important;
  }
  .station-btn,
  .stop-btn,
  .output-btn {
    transition: none !important;
  }
}

/* Einstellungen-Dialog (Senderbelegung) */
.settings-dialog {
  width: min(92vw, 440px);
  max-height: 88dvh;
  margin: auto;
  padding: 0;
  border: 1.5px solid var(--surface-border);
  border-radius: 22px;
  background: #111A28;
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}

.settings-dialog::backdrop {
  background: rgba(3, 7, 18, 0.78);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.settings-sheet {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 20px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--text);
}

.settings-close-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.settings-close-btn svg {
  width: 20px;
  height: 20px;
}

.settings-close-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.settings-hint {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.slot-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.slot-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.slot-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 10px 40px 10px 14px;
  border: 1.5px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  background-color: #1A2639;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23CBD5E1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.slot-select:focus-visible {
  outline: 2px solid #60A5FA;
  outline-offset: 2px;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.settings-save-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 1.5px solid var(--blue-border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--blue-top) 0%, var(--blue-bottom) 100%);
  color: #FFFFFF;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.settings-save-btn:active {
  transform: scale(0.98);
}

.settings-reset-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
}

.settings-reset-btn:active {
  background: rgba(255, 255, 255, 0.06);
}

/* Compact landscape fallback if device is rotated */
@media (max-height: 520px) {
  body {
    overflow-y: auto;
  }
  .app {
    height: auto;
    min-height: 100dvh;
  }
  .station-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: 1fr;
    min-height: 140px;
  }
}
