:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --border: rgba(230, 237, 243, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
}

.main {
  width: 100%;
  max-width: 32.5rem;
  margin: 0 auto;
  /* top, right, bottom, left — respect notches and home indicator */
  padding:
    1rem
    max(1rem, env(safe-area-inset-right, 0))
    calc(2rem + env(safe-area-inset-bottom, 0))
    max(1rem, env(safe-area-inset-left, 0));
}

.header-top {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.header-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
}

.header-title-wrap {
  flex: 1;
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.tagline {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
}

.lang-select {
  margin-left: auto;
  padding: 0.4rem 0.55rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  /* ≥16px avoids iOS zoom-on-focus on the language control */
  font-size: max(16px, 0.85rem);
  touch-action: manipulation;
}

.intro-content p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.app-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.15rem;
  margin-bottom: 1.25rem;
}

.app-section-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.app-section-intro {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.app-feature-list {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  font-size: 0.88rem;
  color: var(--text);
}

.app-feature-list li {
  margin-bottom: 0.45rem;
}

.app-web-note {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.store-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.store-link {
  text-align: center;
  padding: 0.65rem 1rem;
  min-height: 44px;
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
  font-weight: 600;
  font-size: max(16px, 0.9rem);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.store-link:hover {
  background: var(--accent-hover);
}

.store-link:active {
  filter: brightness(1.08);
}

.store-link:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.ad-slot {
  margin: 1rem 0;
  min-height: 50px;
}

.lcd-panel {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-family: ui-monospace, monospace;
}

.lcd-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.lcd-display {
  font-size: 1rem;
  margin-top: 0.35rem;
  word-break: break-word;
}

.lcd-meta,
.lcd-data {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn {
  border: none;
  cursor: pointer;
  border-radius: 10px;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-icon {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.country-select-wrap {
  margin-bottom: 0.75rem;
}

.country-select-wrap label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.country-select {
  width: 100%;
  max-width: 100%;
  padding: 0.6rem 0.75rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: max(16px, 0.95rem);
}

.stations-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.stations-header {
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.stations-list-scroll {
  max-height: min(55dvh, 55vh, 420px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.loading {
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading.error-msg {
  color: #f87171;
}

.loading-progress {
  padding: 0.75rem 1rem;
}

.progress-bar {
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

.progress-text {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.station-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.station-item.playing {
  background: rgba(99, 102, 241, 0.12);
}

.station-favicon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.station-info {
  flex: 1;
  min-width: 0;
}

.station-name {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-word;
}

.station-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.station-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.station-actions button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  border-radius: 8px;
  color: inherit;
}

.station-actions button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.2rem 0.35rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.footer a:hover {
  text-decoration: underline;
}

.footer-sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top, 0)) max(1rem, env(safe-area-inset-right, 0)) max(1rem, env(safe-area-inset-bottom, 0)) max(1rem, env(safe-area-inset-left, 0));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.modal-visible {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 400px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  touch-action: manipulation;
}

.modal-body {
  padding: 1rem;
}

.station-info-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.88rem;
}

.station-info-dl dt {
  color: var(--muted);
  margin: 0;
}

.station-info-dl dd {
  margin: 0;
  word-break: break-all;
}

.station-info-url {
  color: var(--accent);
}

html[dir="rtl"] .header-top {
  flex-direction: row-reverse;
}

html[dir="rtl"] .app-feature-list {
  padding-right: 1.2rem;
  padding-left: 0;
}

@media (min-width: 480px) {
  .store-links {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .store-link {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: min(100%, 10rem);
  }
}

@media (min-width: 768px) {
  .main {
    max-width: 40rem;
    padding-top: 1.25rem;
  }

  .header h1 {
    font-size: 1.65rem;
  }

  .app-section-title {
    font-size: 1.15rem;
  }

  .stations-list-scroll {
    max-height: min(50dvh, 50vh, 480px);
  }
}

@media (min-width: 1024px) {
  .main {
    max-width: 44rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar {
    animation: none;
  }
}
