:root {
  --paper: #e8f0ea;
  --paper-strong: #f8f5e9;
  --ink: #151515;
  --muted: #59625c;
  --line: #c9d1c8;
  --red: #e54835;
  --amber: #e1a32d;
  --green: #25895c;
  --cyan: #267b87;
  --field: #fff;
  --panel-bg: rgba(248, 245, 233, 0.88);
  --primary-text: #fff8e8;
  --shadow: 0 18px 46px rgba(21, 21, 21, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: "Aptos", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  opacity: 0;
  transition: opacity 0.15s;
}
.app-shell.ready {
  opacity: 1;
}

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 0 18px;
  flex-wrap: nowrap;
}

.brand-home {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  margin-right: auto;
  -webkit-tap-highlight-color: transparent;
}

.brand-home:active {
  opacity: 0.7;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--paper-strong);
  background: var(--red);
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-weight: 900;
  box-shadow: 5px 5px 0 var(--ink);
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.signal-band h2,
.timeline-section h2 {
  margin: 0;
}

.brand-copy h1 {
  font-size: 28px;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

/* Icon buttons — same size */
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper-strong);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}

/* Status pill — left of buttons */
.status-pill {
  padding: 8px 10px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-ok {
  background: rgba(37, 137, 92, 0.15);
  color: var(--green);
}

.status-warn {
  background: rgba(229, 72, 53, 0.13);
  color: var(--red);
}

.status-warn-yellow {
  background: rgba(225, 163, 45, 0.18);
  color: var(--amber);
}

.status-muted {
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
}

/* --- Layout --- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  max-width: 1120px;
  margin: 0 auto;
}

.signal-band,
.settings-panel,
.about-panel,
.timeline-section {
  border: 2px solid var(--ink);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.signal-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  padding: 18px;
  min-height: 164px;
}

.signal-band h2 {
  font-size: clamp(26px, 6vw, 60px);
  line-height: 0.95;
  overflow-wrap: anywhere;
}

.latest-text {
  max-width: 820px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

/* --- Setup banner (first launch) --- */
.setup-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--amber);
  border-radius: 8px;
  background: rgba(225, 163, 45, 0.12);
  animation: fadeIn 0.3s ease;
}

.setup-banner-icon {
  font-size: 24px;
  flex-shrink: 0;
}

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

.setup-banner-text strong {
  display: block;
  font-size: 14px;
}

.setup-banner-text span {
  color: var(--muted);
  font-size: 12px;
}

.setup-banner-action {
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--amber);
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}

.setup-banner-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 16px;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
}

/* --- Panel open animation --- */
@keyframes panelOpen {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.settings-panel:not(.hidden),
.about-panel:not(.hidden) {
  animation: panelOpen 0.22s ease-out;
}

/* Active toggle button — shows panel is open */
.icon-btn.active {
  background: var(--ink);
  color: var(--paper-strong);
  border-color: var(--ink);
}

/* --- Settings panel --- */
.settings-panel {
  padding: 14px;
}

.settings-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.settings-panel-head h2 {
  margin: 0;
  font-size: 22px;
}

/* Single column grid */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: 480px;
  margin-inline: auto;
}

/* --- About panel --- */
.about-panel {
  padding: 14px;
}

.about-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.about-panel-head h2 {
  margin: 0;
  font-size: 22px;
}

.about-panel-body p {
  margin: 6px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* --- Form elements --- */
.setting-block,
.switch-line {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.setting-block label,
.switch-line span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.setting-block input,
.setting-block select {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

.setting-block input:focus,
.setting-block select:focus {
  box-shadow: 0 0 0 3px rgba(229, 72, 53, 0.2);
}

.custom-sound-name {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: -4px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-block {
  position: relative;
}

.city-results {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: grid;
  max-height: 220px;
  overflow: auto;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
  box-shadow: var(--shadow);
}

.city-result {
  display: block;
  width: 100%;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: var(--field);
  text-align: left;
}

.city-result strong,
.city-result span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.city-result span {
  color: var(--muted);
  font-size: 12px;
}

.switch-line {
  align-items: center;
  grid-template-columns: auto 1fr;
  min-height: 62px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
}

.switch-line input {
  width: 24px;
  height: 24px;
  accent-color: var(--red);
}

.secondary-action,
.refresh-action,
.feed-toggle-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-strong);
  font-weight: 900;
}

.secondary-action {
  background: var(--field);
}

.secondary-action.is-active {
  background: var(--red);
  color: var(--primary-text);
}

.secondary-action:disabled,
.refresh-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.full-width {
  width: 100%;
}

/* --- Timeline section --- */
.timeline-section {
  padding: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
}

.section-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.feed-scope-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
  padding: 2px 8px;
  border-radius: 4px;
}

.feed-scope-mine {
  color: var(--green);
  background: rgba(37, 137, 92, 0.12);
}

.feed-scope-city {
  color: var(--green);
  background: rgba(37, 137, 92, 0.18);
}

.section-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* Siren row: select + preview button */
.siren-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.siren-row select {
  flex: 1;
  min-width: 0;
}
.siren-row .vib-select {
  flex: 0 0 auto;
  width: auto;
  max-width: 90px;
  font-size: 12px;
  padding: 4px 2px;
}
.preview-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--ink);
}

/* Circle buttons for refresh + feed toggle */
.circle-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.circle-btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.refresh-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.timeline {
  display: grid;
  gap: 10px;
}

.alert-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
}

.alert-stripe {
  width: 8px;
  height: 100%;
  min-height: 62px;
  border-radius: 4px;
  background: var(--amber);
}

.alert-row.drone .alert-stripe,
.alert-row.air_raid .alert-stripe,
.alert-row.artillery .alert-stripe {
  background: var(--red);
}

.alert-row.cancel .alert-stripe {
  background: var(--green);
}

.alert-row h3 {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.25;
}

.alert-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.alert-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: var(--paper-strong);
  background: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 800;
}

/* --- Offline banner --- */
.offline-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  border: 2px solid var(--amber);
  border-radius: 8px;
  background: rgba(225, 163, 45, 0.15);
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  animation: offline-pulse 2s ease-in-out infinite;
}

.offline-icon {
  font-size: 20px;
}

@keyframes offline-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.hidden {
  display: none !important;
}

/* --- Share section --- */
.share-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px solid var(--line);
}

.share-section h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.share-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.share-buttons .secondary-action {
  flex: 1;
  min-width: 140px;
  text-align: center;
}

/* --- Feedback section --- */
.feedback-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px solid var(--line);
}

.feedback-section h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.feedback-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
}

.feedback-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: 480px;
  margin-inline: auto;
}

.feedback-form textarea {
  width: 100%;
  min-height: 80px;
  padding: 9px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  resize: vertical;
  outline: none;
}

.feedback-form textarea:focus {
  box-shadow: 0 0 0 3px rgba(229, 72, 53, 0.2);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Dark mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111614;
    --paper-strong: #20261f;
    --ink: #f3f0e8;
    --muted: #b4beb6;
    --line: #3a453e;
    --red: #ff5948;
    --amber: #efb23e;
    --green: #55c78f;
    --cyan: #67c3d0;
    --field: #171d19;
    --panel-bg: rgba(27, 32, 28, 0.92);
    --primary-text: #fff8e8;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  }

  body {
    background:
      linear-gradient(90deg, rgba(243, 240, 232, 0.035) 1px, transparent 1px),
      linear-gradient(0deg, rgba(243, 240, 232, 0.035) 1px, transparent 1px),
      var(--paper);
  }

  .icon-btn {
    background: rgba(255, 255, 255, 0.08);
  }

  .status-muted {
    background: rgba(255, 255, 255, 0.08);
  }

  .feed-scope-label {
    background: rgba(255, 255, 255, 0.08);
  }
}

/* --- Manual theme override --- */
[data-theme="dark"] {
  --paper: #111614;
  --paper-strong: #20261f;
  --ink: #f3f0e8;
  --muted: #b4beb6;
  --line: #3a453e;
  --red: #ff5948;
  --amber: #efb23e;
  --green: #55c78f;
  --cyan: #67c3d0;
  --field: #171d19;
  --panel-bg: rgba(27, 32, 28, 0.92);
  --primary-text: #fff8e8;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
}

[data-theme="dark"] body {
  background:
    linear-gradient(90deg, rgba(243, 240, 232, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(243, 240, 232, 0.035) 1px, transparent 1px),
    var(--paper);
}

[data-theme="dark"] .icon-btn {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .status-muted {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .feed-scope-label {
  background: rgba(255, 255, 255, 0.08);
}

/* Force light when system is dark but user chose light */
[data-theme="light"] {
  --paper: #e8f0ea;
  --paper-strong: #f8f5e9;
  --ink: #151515;
  --muted: #59625c;
  --line: #c9d1c8;
  --red: #e54835;
  --amber: #e1a32d;
  --green: #25895c;
  --cyan: #267b87;
  --field: #fff;
  --panel-bg: rgba(248, 245, 233, 0.88);
  --primary-text: #fff8e8;
  --shadow: 0 18px 46px rgba(21, 21, 21, 0.14);
}

[data-theme="light"] body {
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    var(--paper);
}

[data-theme="light"] .icon-btn {
  background: var(--paper-strong);
}

[data-theme="light"] .status-muted {
  background: rgba(255, 255, 255, 0.45);
}

/* --- Mobile --- */
@media (max-width: 760px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .brand-copy h1 {
    font-size: 22px;
  }

  .eyebrow {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 18px;
    box-shadow: 3px 3px 0 var(--ink);
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .status-pill {
    padding: 6px 8px;
    font-size: 11px;
  }

  .signal-band {
    grid-template-columns: 1fr;
  }

  .alert-row {
    grid-template-columns: 8px minmax(0, 1fr);
  }

  .alert-time {
    grid-column: 2;
  }
}

/* === iOS Install Banner === */
.ios-install-banner {
  margin: 0 0 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, rgba(0,0,0,0.08));
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  animation: iosBannerSlide 0.3s ease;
}

[data-theme="dark"] .ios-install-banner,
:root:not([data-theme]) .ios-install-banner {
  /* will inherit from dark mode variables */
}

@keyframes iosBannerSlide {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ios-install-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ios-install-icon {
  font-size: 24px;
  line-height: 1;
  flex-shrink: 0;
}

.ios-install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  line-height: 1.4;
}

.ios-install-text strong {
  font-size: 14px;
}

.ios-install-sub {
  font-size: 11px;
  opacity: 0.7;
}

.ios-share, .ios-plus {
  display: inline-block;
  font-size: 12px;
}

.ios-install-close {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 16px;
  opacity: 0.5;
  cursor: pointer;
  padding: 0 0 0 4px;
  color: inherit;
}

.ios-install-close:hover { opacity: 1; }

.ios-install-help {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 18px;
  color: #2196f3;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

/* === iOS Push Status === */
.ios-push-status {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.ios-push-status.ok {
  background: rgba(76, 175, 80, 0.12);
  color: #4caf50;
}

.ios-push-status.warning {
  background: rgba(255, 193, 7, 0.12);
  color: #b8860b;
}

.ios-push-status.error {
  background: rgba(244, 67, 54, 0.12);
  color: #e54835;
}

.ios-push-status.info {
  background: rgba(33, 150, 243, 0.10);
  color: #2196f3;
}

.ios-push-status.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
  font-weight: 600;
}
.ios-push-status.clickable:active { opacity: 0.7; }

/* === iOS Safe Area Fixes === */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .settings-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .about-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
