:root {
  --bg: #0e1022;
  --glass: rgba(24, 20, 48, 0.3);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text: #f5f3f0;
  --muted: rgba(245, 243, 240, 0.6);
  --faint: rgba(245, 243, 240, 0.12);
  --sunrise: #ffb36b;
  --sunset: #ff8a8a;
  --radius: 22px;
  --ring-circumference: 326.73; /* 2π × 52 */
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Dusk-sky backdrop */
.sky {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(120% 60% at 15% -10%, rgba(255, 150, 90, 0.28), transparent 60%),
    radial-gradient(90% 50% at 100% 0%, rgba(200, 107, 214, 0.22), transparent 60%),
    linear-gradient(180deg, #1c1a3a 0%, #0e1022 55%);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 28px)
    max(20px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 24px)
    max(20px, env(safe-area-inset-left));
}

/* Background photo */
.photo {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("photos/IMG_2998.jpg") center / cover no-repeat;
}

/* Darken the photo so white text stays readable on the pale sky. */
.photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(14, 16, 34, 0.35) 0%, rgba(14, 16, 34, 0.05) 45%, rgba(14, 16, 34, 0.3) 100%);
}

/* Text sitting directly on the photo */
.topbar, .footer {
  text-shadow: 0 1px 10px rgba(20, 16, 40, 0.5);
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sunrise);
}

.eyebrow svg { width: 14px; height: 14px; fill: currentColor; }

h1 {
  margin: 0;
  font-size: clamp(1.9rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.date {
  margin: 4px 0 0;
  color: rgba(245, 243, 240, 0.88);
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Next event pill */
.next {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding: 8px 14px 8px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  font-size: 0.9rem;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.next::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sunrise);
  box-shadow: 0 0 10px var(--sunrise);
}

.next-label { color: var(--muted); }
.next-countdown { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
  margin-top: 24px;
}

.card {
  --accent: var(--sunrise);
  padding: 20px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  text-shadow: 0 1px 6px rgba(20, 16, 40, 0.45);
  transition: opacity 0.3s ease;
}

#sunset { --accent: var(--sunset); }

.card { container-type: inline-size; }

.card.is-past { opacity: 0.55; }
.card.is-loading .gauge-value,
.card.is-loading .summary { animation: pulse 1.4s ease-in-out infinite; }

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

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.event {
  display: flex;
  align-items: center;
  gap: 12px;
}

.event-icon {
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card-head h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.time {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--faint);
  color: var(--muted);
}

.chip[data-rating="excellent"] { background: rgba(255, 179, 107, 0.2); color: #ffc98f; }
.chip[data-rating="good"]      { background: rgba(126, 211, 160, 0.18); color: #9be3b8; }
.chip[data-rating="fair"]      { background: rgba(245, 214, 110, 0.16); color: #f2d98a; }
.chip[data-rating="poor"]      { background: var(--faint); color: var(--muted); }

/* Gauge */
.gauge-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 20px 0;
}

.gauge {
  position: relative;
  flex: none;
  width: 128px;
  height: 128px;
}

.gauge svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.gauge-track { stroke: var(--faint); }

.gauge-fill {
  stroke-dasharray: var(--ring-circumference);
  stroke-dashoffset: var(--ring-circumference);
  transition: stroke-dashoffset 1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.gauge-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge-value {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.gauge-value::after {
  content: "%";
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  margin-left: 1px;
}

.gauge-unit {
  margin-top: 4px;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.45;
}

/* Factor breakdown */
.factors {
  list-style: none;
  margin: 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--faint);
  display: grid;
  gap: 12px;
}

.factor {
  display: grid;
  grid-template-columns: 1fr auto 9.5rem;
  align-items: center;
  column-gap: 12px;
  font-size: 0.98rem;
}

.factor-name { color: var(--muted); }
.factor-value { font-variant-numeric: tabular-nums; text-align: right; }

.factor-verdict {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
}

.factor-verdict { --q: var(--faint); }

.factor-verdict::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--q);
}

.factor-verdict[data-q="good"] { --q: #7fd8a4; }
.factor-verdict[data-q="ok"]   { --q: #f0c96a; }
.factor-verdict[data-q="bad"]  { --q: #f08c8c; }

/* Sweet-spot range bar for mid/high cloud */
.range {
  grid-column: 1 / -1;
  position: relative;
  height: 6px;
  margin-top: 10px;
  border-radius: 3px;
  background: var(--faint);
}

.range-zone {
  position: absolute;
  left: 30%;
  width: 40%;
  height: 100%;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}

.range-marker {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--bg);
  transform: translate(-50%, -50%);
  transition: left 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.range-scale {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Footer */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 24px;
  font-size: 0.78rem;
  color: rgba(245, 243, 240, 0.85);
}

.footer a { color: inherit; }
#status.error { color: var(--sunset); }

/* Narrow cards (e.g. iPad portrait) — tighten factor rows so labels stay on one line. */
@container (max-width: 380px) {
  .factor {
    grid-template-columns: 1fr auto 8.2rem;
    column-gap: 8px;
    font-size: 0.92rem;
  }
}

@media (max-width: 420px) {
  .gauge { width: 112px; height: 112px; }
  .gauge-value { font-size: 2.1rem; }
  .gauge-row { gap: 16px; }
  .summary { font-size: 1.03rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
