/* =========================================================
   Weather Glass — Styles
   ========================================================= */

/* --- Reset & Base ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-top: #1a4855;
  --bg-bottom: #0d2b38;
  --orb-color: rgba(240,192,64,0.55);
  --orb-size: 55vw;
  --orb-x: 55%;
  --orb-y: 38%;
  --orb-blur: 80px;
  --chart-top: #e8b820;
  --chart-bottom: #1a6010;
  --text-primary: #ffffff;
  --text-secondary: rgba(255,255,255,0.72);
  --text-muted: rgba(255,255,255,0.48);
  --accent: rgba(255,255,255,0.14);
  --transition-speed: 1.2s;
}

html { height: 100%; }

body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text-primary);
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  transition: background var(--transition-speed) ease;
  -webkit-font-smoothing: antialiased;
}

/* --- Condition theming ------------------------------------ */
[data-condition="clear-day"] {
  --bg-top: #1a5c6e; --bg-bottom: #0a2a3a;
  --orb-color: rgba(255,210,60,0.65); --orb-size: 52vw;
  --chart-top: #f0c820; --chart-bottom: #2a7020;
}
[data-condition="clear-night"] {
  --bg-top: #0a1828; --bg-bottom: #050d1a;
  --orb-color: rgba(200,220,255,0.45); --orb-size: 40vw;
  --chart-top: #6080c0; --chart-bottom: #0a1840;
}
[data-condition="partly-cloudy"] {
  --bg-top: #1c4f5e; --bg-bottom: #0e2e3a;
  --orb-color: rgba(220,170,40,0.45); --orb-size: 50vw;
  --chart-top: #d8a820; --chart-bottom: #1e6818;
}
[data-condition="cloudy"] {
  --bg-top: #1a4855; --bg-bottom: #0d2b38;
  --orb-color: rgba(180,200,220,0.25); --orb-size: 45vw;
  --chart-top: #90b0c0; --chart-bottom: #203040;
}
[data-condition="fog"] {
  --bg-top: #2a3a42; --bg-bottom: #161f26;
  --orb-color: rgba(200,210,215,0.3); --orb-size: 60vw;
  --chart-top: #7898a8; --chart-bottom: #182028;
}
[data-condition="drizzle"] {
  --bg-top: #0e2240; --bg-bottom: #060f22;
  --orb-color: rgba(100,130,180,0.2); --orb-size: 50vw;
  --chart-top: #4070c0; --chart-bottom: #0a2050;
}
[data-condition="rain"] {
  --bg-top: #0a1e3a; --bg-bottom: #050f1e;
  --orb-color: transparent; --orb-size: 0;
  --chart-top: #3060b0; --chart-bottom: #081840;
}
[data-condition="snow"] {
  --bg-top: #2a3550; --bg-bottom: #151a30;
  --orb-color: rgba(180,200,240,0.35); --orb-size: 48vw;
  --chart-top: #90b0e0; --chart-bottom: #182848;
}
[data-condition="storm"] {
  --bg-top: #0a0f25; --bg-bottom: #050810;
  --orb-color: transparent; --orb-size: 0;
  --chart-top: #5040a0; --chart-bottom: #100820;
}

/* --- Atmospheric orb ------------------------------------- */
.atmo-orb {
  position: fixed;
  width: var(--orb-size);
  height: var(--orb-size);
  left: var(--orb-x);
  top: var(--orb-y);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, var(--orb-color) 0%, transparent 70%);
  filter: blur(var(--orb-blur));
  pointer-events: none;
  z-index: 0;
  transition:
    width var(--transition-speed) ease,
    height var(--transition-speed) ease,
    background var(--transition-speed) ease,
    opacity var(--transition-speed) ease;
}

/* Grain texture */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
}

/* --- Layout ---------------------------------------------- */
.app {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(20px, 5vw, 32px) clamp(20px, 5vw, 32px) 24px;
  gap: 0;
}

/* --- Header ---------------------------------------------- */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.location-name {
  font-size: clamp(22px, 5.5vw, 30px);
  font-weight: 400;
  letter-spacing: -0.3px;
}

.location-time {
  font-size: 14px;
  font-weight: 300;
  color: var(--text-secondary);
  margin-top: 3px;
}

.btn-search {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: color 0.2s, background 0.2s;
}
.btn-search:hover { color: var(--text-primary); background: var(--accent); }
.btn-search:focus-visible { outline: 2px solid rgba(255,255,255,0.6); outline-offset: 2px; }

/* --- Hero ------------------------------------------------ */
.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.hero-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-icon {
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
}
.hero-icon svg { width: 100%; height: 100%; }

.hero-condition {
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 300;
  color: var(--text-secondary);
}

.hero-phrase {
  font-size: 13px;
  font-style: italic;
  color: var(--text-muted);
  max-width: 180px;
}

.hero-right {
  text-align: right;
}

.hero-temp {
  font-size: clamp(68px, 18vw, 96px);
  font-weight: 100;
  letter-spacing: -4px;
  line-height: 1;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.temp-unit {
  font-size: 0.45em;
  font-weight: 200;
  margin-top: 0.08em;
  letter-spacing: 0;
}

/* --- Metrics --------------------------------------------- */
.metrics {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.metric {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  background: var(--accent);
  border-radius: 20px;
  padding: 7px 13px 7px 10px;
  flex: 0 0 auto;
}

.metric-icon { color: var(--text-secondary); display: flex; }
.metric-val { font-weight: 500; }
.metric-unit { color: var(--text-secondary); font-size: 12px; }
.metric-label { color: var(--text-muted); font-size: 11px; margin-left: 2px; }

/* --- Graph ----------------------------------------------- */
.graph-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.graph-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
}

.graph-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.graph-overlay {
  position: absolute;
  inset: 0;
  cursor: ew-resize;
  touch-action: pan-y;
  border-radius: 12px;
}
.graph-overlay:focus-visible {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 2px;
}

/* Graph SVG elements */
.graph-area { transition: d 0.4s ease, fill 0.6s ease; }
.graph-curve { fill: none; stroke: white; stroke-width: 2; stroke-linecap: round; transition: d 0.4s ease; }
.graph-cursor-line { stroke: white; stroke-width: 1.5; stroke-opacity: 0.75; }
.graph-cursor-dot { fill: white; filter: drop-shadow(0 0 6px rgba(255,255,255,0.5)); }
.graph-cursor-halo { fill: white; opacity: 0; }
.graph-cursor-halo.active { animation: halo-pulse 1.6s ease-out forwards; }
.graph-time-label { fill: rgba(255,255,255,0.6); font-size: 11px; text-anchor: middle; }
.graph-temp-label { fill: white; font-size: 11px; text-anchor: middle; font-weight: 500; }
.graph-precip-label { fill: #60c0ff; font-size: 10px; text-anchor: middle; }

/* --- Daily strip ----------------------------------------- */
.daily-section { padding-top: 16px; }

.daily-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.daily-strip::-webkit-scrollbar { display: none; }

.day-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  border-radius: 16px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  scroll-snap-align: start;
  min-width: 64px;
}
.day-card:hover { background: var(--accent); }
.day-card.selected {
  background: rgba(255,255,255,0.16);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.25);
  backdrop-filter: blur(8px);
}
.day-card:focus-visible { outline: 2px solid rgba(255,255,255,0.6); outline-offset: 2px; }

.day-name { font-size: 12px; font-weight: 500; letter-spacing: 0.3px; }
.day-icon { width: 28px; height: 28px; }
.day-icon svg { width: 100%; height: 100%; }
.day-high { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.day-precip { font-size: 11px; color: #60c0ff; }

/* --- Search overlay --------------------------------------- */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 15, 28, 0.85);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  padding: clamp(20px,5vw,40px);
  gap: 16px;
  animation: fade-in 0.2s ease;
}
.search-overlay[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.search-box {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-input {
  flex: 1;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 18px;
  color: white;
  outline: none;
  transition: border-color 0.2s;
}
.search-input::placeholder { color: rgba(255,255,255,0.4); }
.search-input:focus { border-color: rgba(255,255,255,0.5); }

.search-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.search-close:hover { background: rgba(255,255,255,0.2); }
.search-close:focus-visible { outline: 2px solid rgba(255,255,255,0.6); }

.search-results {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-result-item {
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover,
.search-result-item[aria-selected="true"] { background: rgba(255,255,255,0.16); }
.search-result-item:focus-visible { outline: 2px solid rgba(255,255,255,0.6); }

.result-name { font-size: 16px; font-weight: 400; }
.result-country { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.btn-locate {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-secondary);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  align-self: flex-start;
}
.btn-locate:hover { background: var(--accent); color: var(--text-primary); }
.btn-locate:focus-visible { outline: 2px solid rgba(255,255,255,0.6); }

/* --- Offline banner --------------------------------------- */
.offline-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.offline-banner[hidden] { display: none; }

/* --- Skeleton --------------------------------------------- */
.skeleton-overlay {
  padding: inherit;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.skeleton-overlay[hidden] { display: none; }

.skel {
  background: linear-gradient(90deg, rgba(255,255,255,0.08) 25%, rgba(255,255,255,0.16) 50%, rgba(255,255,255,0.08) 75%);
  background-size: 300% 100%;
  border-radius: 12px;
  animation: shimmer 1.5s linear infinite;
}
.skel-location { height: 36px; width: 55%; }
.skel-temp { height: 90px; width: 40%; align-self: flex-end; }
.skel-graph { height: 220px; }

/* --- Error state ------------------------------------------ */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  text-align: center;
  padding: 40px;
}
.error-state[hidden] { display: none; }
.error-icon { font-size: 48px; }
.error-msg { color: var(--text-secondary); font-size: 16px; }
.btn-retry {
  background: var(--accent);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-retry:hover { background: rgba(255,255,255,0.22); }
.btn-retry:focus-visible { outline: 2px solid rgba(255,255,255,0.6); }

/* --- Content -------------------------------------------- */
.content { display: flex; flex-direction: column; flex: 1; gap: 0; }
.content[hidden] { display: none; }

/* --- Utilities ------------------------------------------ */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* --- Animations ----------------------------------------- */
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@keyframes halo-pulse {
  0% { opacity: 0.15; r: 8; }
  100% { opacity: 0; r: 28; }
}

/* --- Panel defaults (mobile: stacked, desktop: side-by-side) */
.left-panel { display: flex; flex-direction: column; }
.right-panel { display: flex; flex-direction: column; flex: 1; }
.graph-section { flex: 1; }

/* --- Desktop layout (≥ 1024px) -------------------------- */
@media (min-width: 1024px) {
  .app {
    padding: clamp(32px, 4vw, 56px);
    min-height: 100vh;
  }

  .content {
    flex-direction: row;
    align-items: stretch;
    gap: 52px;
    flex: 1;
    min-height: calc(100vh - clamp(64px, 8vw, 112px));
  }

  .left-panel {
    flex: 0 0 320px;
    justify-content: flex-start;
    gap: 0;
  }

  .right-panel {
    gap: 16px;
    min-height: 400px;
  }

  .header { margin-bottom: 40px; }
  .hero { flex-direction: column; gap: 8px; margin-bottom: 24px; }
  .hero-right { align-self: flex-start; text-align: left; }
  .hero-temp { font-size: 88px; }
  .metrics { margin-bottom: 0; }
  .graph-section { min-height: 320px; }
  .daily-section { padding-top: 8px; }
}

/* --- Reduced motion --------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .skel { animation: none; background: rgba(255,255,255,0.1); }
}

/* --- Minimum 320px support -------------------------------- */
@media (max-width: 360px) {
  .metrics { gap: 6px; }
  .metric { padding: 6px 10px; font-size: 13px; }
  .hero-temp { font-size: clamp(60px, 17vw, 80px); }
  .hero-icon { width: 56px; height: 56px; }
}
