:root {
  --berg: #2f7d4f;
  --berg-dark: #1f5a37;
  --berg-light: #e4f3ea;
  --himmel: #3a93d6;
  --himmel-light: #e2f0fb;
  --bg: #f3f8f5;
  --bg-grad-1: #e6f3ec;
  --bg-grad-2: #e2f0fb;
  --surface: #ffffff;
  --surface-2: #f6faf7;
  --text: #18261d;
  --text-soft: #4d6155;
  --border: #d6e6dc;
  --shadow: 0 6px 22px rgba(31, 90, 55, 0.10);
  --good: #2f9e57;
  --ok: #d99a17;
  --bad: #c0492f;
  --radius: 16px;
  --radius-sm: 10px;
  --focus: #1f5a37;
}

[data-theme="dark"] {
  --berg: #56c486;
  --berg-dark: #3da76d;
  --berg-light: #173527;
  --himmel: #6cb6ec;
  --himmel-light: #16293a;
  --bg: #0e1813;
  --bg-grad-1: #0f1c15;
  --bg-grad-2: #0d1822;
  --surface: #16241c;
  --surface-2: #1b2c22;
  --text: #e7f2ea;
  --text-soft: #a7bcae;
  --border: #294638;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  --good: #4fc07a;
  --ok: #e6b53f;
  --bad: #ef7359;
  --focus: #8ad9aa;
}

* { box-sizing: border-box; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 480px at 100% -10%, var(--bg-grad-2), transparent 60%),
    radial-gradient(1000px 460px at -10% 0%, var(--bg-grad-1), transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overflow-wrap: break-word;
  word-break: break-word;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--berg);
  color: #fff;
  padding: 10px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 8px;
  max-width: 760px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 14px;
  color: var(--berg);
  background: linear-gradient(160deg, var(--berg-light), var(--himmel-light));
  flex: 0 0 auto;
}
.brand-text { min-width: 0; }
.brand-text h1 {
  font-size: 1.25rem;
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.tagline { margin: 2px 0 0; font-size: 0.82rem; color: var(--text-soft); }

.icon-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }

.field-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--text-soft); }

.search-row { display: flex; gap: 8px; flex-wrap: wrap; }

.text-input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.text-input:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.hint { font-size: 0.78rem; color: var(--text-soft); margin: 8px 0 0; }
.hint code, code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.85em;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn[disabled] { opacity: 0.55; cursor: progress; }

.btn-primary { background: var(--berg); color: #fff; }
.btn-primary:hover { background: var(--berg-dark); }
.btn-secondary {
  background: var(--himmel-light);
  color: var(--himmel);
  border-color: var(--border);
}
[data-theme="dark"] .btn-secondary { color: var(--himmel); }
.btn-secondary:hover { filter: brightness(0.97); }
.btn-ghost { background: transparent; color: var(--berg); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

.loc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.city-results {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.city-results li { border-top: 1px solid var(--border); }
.city-results li:first-child { border-top: none; }
.city-option {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: none;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.city-option:hover { background: var(--surface-2); }
.city-option:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.city-option .opt-name { font-weight: 600; }
.city-option .opt-detail { font-size: 0.8rem; color: var(--text-soft); }

.current-loc {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--berg-light);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
}
.current-loc a { color: var(--berg-dark); }
[data-theme="dark"] .current-loc a { color: var(--berg); }

.status-bar {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status-bar.is-offline { background: #fff4e0; border-color: #f0d28a; color: #7a5512; }
[data-theme="dark"] .status-bar.is-offline { background: #2e2410; border-color: #5a4a1c; color: #f0cf86; }
.status-bar.is-error { background: #fde7e2; border-color: #f1b7aa; color: #8c3422; }
[data-theme="dark"] .status-bar.is-error { background: #2e1612; border-color: #5a2920; color: #f0a692; }
.status-bar.is-loading { background: var(--himmel-light); border-color: var(--border); }

.results { display: flex; flex-direction: column; gap: 16px; }

.best-window {
  background: linear-gradient(155deg, var(--berg), var(--berg-dark));
  color: #fff;
  border: none;
}
.best-window h2 { color: #fff; }
.best-window-body .bw-headline { font-size: 1.15rem; font-weight: 700; margin: 0 0 8px; line-height: 1.25; }
.best-window-body .bw-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 0.92rem; opacity: 0.95; }
.best-window-body .bw-meta span { display: inline-flex; align-items: center; gap: 5px; }
.best-window-body .bw-none { font-size: 1rem; margin: 0; }

.day-cards { display: flex; flex-direction: column; gap: 14px; }

.day-card { padding: 16px; }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.day-head h3 { margin: 0; font-size: 1.02rem; }
.day-head .day-date { font-size: 0.8rem; color: var(--text-soft); }
.day-summary { font-size: 0.9rem; color: var(--text-soft); margin: 0 0 12px; }

.day-windows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.window-chip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--berg-light);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}
.window-chip .wc-time { font-weight: 700; color: var(--berg-dark); }
[data-theme="dark"] .window-chip .wc-time { color: var(--berg); }
.window-chip .wc-detail { color: var(--text-soft); }
.no-window { font-size: 0.88rem; color: var(--text-soft); margin: 0 0 12px; font-style: italic; }

.hours-toggle {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  cursor: pointer;
  color: var(--berg);
  font-size: 0.85rem;
  font-weight: 600;
  width: 100%;
}
.hours-toggle:hover { background: var(--surface-2); }
.hours-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.hours-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
}
.hour-cell {
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.72rem;
  line-height: 1.3;
}
.hour-cell .hc-time { font-weight: 700; display: block; }
.hour-cell .hc-temp { display: block; }
.hour-cell .hc-rain { display: block; color: var(--himmel); }
.hour-cell .hc-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-top: 3px;
}
.score-good { box-shadow: inset 0 0 0 2px var(--good); }
.dot-good { background: var(--good); }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }

.empty-state { text-align: center; }
.empty-state .empty-emoji { font-size: 2.6rem; margin: 0 0 6px; }
.empty-state h2 { margin: 0 0 6px; }
.empty-state p { color: var(--text-soft); margin: 0; }

.about p { margin: 0 0 10px; font-size: 0.92rem; }
.about a { color: var(--berg-dark); }
[data-theme="dark"] .about a { color: var(--berg); }
.about-list { margin: 0; padding-left: 20px; font-size: 0.86rem; color: var(--text-soft); display: flex; flex-direction: column; gap: 4px; }

.install-btn {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--berg);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 40;
}
.install-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: calc(100% - 32px);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.app-footer {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-soft);
}

@media (max-width: 400px) {
  .brand-text h1 { font-size: 1.1rem; }
  .card { padding: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
