:root {
  --bg-top: #4aa3f0;
  --bg-bottom: #dcebfa;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --ink: #1a2b3c;
  --ink-soft: #5b7186;
  --ink-faint: #8aa0b4;
  --accent: #2f7fd1;
  --accent-soft: #e3f0fc;
  --divider: rgba(26, 43, 60, 0.08);
  --danger: #d64545;
  --radius: 20px;
  --shadow: 0 8px 30px rgba(30, 70, 120, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 55%, #eef5fc 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }

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

.hidden { display: none !important; }

.ic { width: 20px; height: 20px; fill: currentColor; display: block; }
.ic.chev { width: 18px; height: 18px; opacity: 0.7; }

/* ---- Topbar ------------------------------------------------------------- */
.app { max-width: 520px; margin: 0 auto; padding: 0 16px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 0 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.location-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 9px 14px;
  border-radius: 999px;
  font: 600 16px/1 'Inter', sans-serif;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(30, 70, 120, 0.15);
  max-width: 70%;
}
.location-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  color: #fff; cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(30, 70, 120, 0.15);
}
.icon-btn.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Popup / Sheet ------------------------------------------------------- */
.popup { position: fixed; inset: 0; z-index: 50; }
.popup-backdrop { position: absolute; inset: 0; background: rgba(20, 40, 70, 0.4); backdrop-filter: blur(2px); }
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
  animation: rise 0.25s ease;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-head .icon-btn { background: #eef3f8; color: var(--ink); box-shadow: none; }

.location-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.loc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  background: #f4f7fb; cursor: pointer; border: 0; width: 100%;
  font: 500 15px 'Inter', sans-serif; color: var(--ink); text-align: left;
}
.loc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.loc-item .check { margin-left: auto; color: var(--accent); font-weight: 700; }
.loc-item .del {
  border: 0; background: transparent; color: var(--ink-faint);
  font-size: 20px; line-height: 1; padding: 4px 6px; cursor: pointer;
}
.loc-item .del:hover { color: var(--danger); }
.loc-empty { color: var(--ink-faint); font-size: 14px; text-align: center; padding: 8px; }

.add-location { position: relative; }
.add-location input {
  width: 100%; padding: 13px 16px; border-radius: 14px;
  border: 1.5px solid var(--divider); background: #f4f7fb;
  font: 500 15px 'Inter', sans-serif; color: var(--ink); outline: none;
}
.add-location input:focus { border-color: var(--accent); background: #fff; }

.search-results {
  position: absolute; left: 0; right: 0; top: 54px;
  background: #fff; border-radius: 14px; box-shadow: var(--shadow);
  overflow: hidden; z-index: 5; max-height: 260px; overflow-y: auto;
}
.search-result {
  padding: 12px 16px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--divider);
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--accent-soft); }
.search-result small { color: var(--ink-faint); }

.sheet-hint { margin: 12px 0 0; color: var(--ink-faint); font-size: 12.5px; text-align: center; }

/* ---- Now card ----------------------------------------------------------- */
.now-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 24px 22px;
  margin: 6px 0 18px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.now-main { display: flex; align-items: center; gap: 18px; }
.now-icon { width: 96px; height: 96px; flex: 0 0 auto; }
.now-icon img { width: 100%; height: 100%; }
.now-temp { font-size: 64px; font-weight: 300; line-height: 1; letter-spacing: -2px; }
.now-temp .deg { font-size: 34px; vertical-align: super; margin-left: 2px; }
.now-desc { font-size: 16px; font-weight: 500; color: var(--ink-soft); margin-top: 4px; }
.now-loc { font-size: 14px; color: var(--ink-faint); }

.now-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 20px;
}
.now-cell {
  background: rgba(255,255,255,0.65); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.now-cell .ico { width: 22px; height: 22px; color: var(--accent); flex: 0 0 auto; }
.now-cell .lbl { font-size: 12px; color: var(--ink-faint); }
.now-cell .val { font-size: 15px; font-weight: 600; }
.now-placeholder { color: #fff; text-align: center; padding: 40px 0; font-weight: 500; }

/* ---- Sections ------------------------------------------------------------ */
.section { margin: 0 0 20px; }
.section-title { margin: 0 4px 10px; font-size: 15px; font-weight: 700; color: rgba(255,255,255,0.95); text-shadow: 0 1px 3px rgba(30,70,120,0.2); }

/* ---- Hourly -------------------------------------------------------------- */
.hourly-strip {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 2px 8px; -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}
.hourly-strip::-webkit-scrollbar { display: none; }
.hour-item {
  flex: 0 0 74px; scroll-snap-align: start;
  background: var(--card); border-radius: 18px;
  padding: 12px 6px 10px; text-align: center; box-shadow: var(--shadow);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.hour-time { font-size: 12px; color: var(--ink-faint); font-weight: 500; }
.hour-item img { width: 40px; height: 40px; margin: 6px auto 4px; }
.hour-temp { font-size: 16px; font-weight: 600; }
.hour-prob { font-size: 11px; color: #3b82c4; margin-top: 3px; display: flex; align-items: center; justify-content: center; gap: 3px; }
.hour-prob .drop { display: inline-block; }

/* ---- Daily --------------------------------------------------------------- */
.daily-list {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  overflow: hidden; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.day-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--divider);
}
.day-row:last-child { border-bottom: 0; }
.day-name { flex: 0 0 44px; font-weight: 600; font-size: 15px; }
.day-date { flex: 0 0 40px; color: var(--ink-faint); font-size: 12.5px; }
.day-row img { width: 40px; height: 40px; }
.day-temps { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.day-temps .lo { color: var(--ink-faint); font-weight: 500; }
.day-temps .hi { font-weight: 700; }
.day-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.day-meta .sun { font-size: 12px; color: #e6a23c; font-weight: 600; }
.day-meta .rain { font-size: 12px; color: #3b82c4; font-weight: 600; }

/* ---- Radar --------------------------------------------------------------- */
.radar-wrap {
  background: #0b1020; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden;
}
.radar-tabs { display: flex; background: #0b1020; }
.radar-tab {
  flex: 1; border: 0; background: transparent; color: rgba(232,237,245,0.55);
  padding: 11px 8px; font: 600 13px 'Inter', sans-serif; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.radar-tab.active { color: #e8edf5; border-bottom-color: #4aa3f0; }
#radarFrame {
  width: 100%; height: 420px; border: 0; display: block; background: #0b1020;
}
.radar-credit { color: rgba(232,237,245,0.5); font-size: 11px; text-align: right; padding: 6px 12px 8px; }

/* ---- Attribution / Toast ------------------------------------------------- */
.attribution {
  text-align: center; color: rgba(255,255,255,0.85); font-size: 12px;
  padding: 8px 16px 4px; line-height: 1.6;
}
.attribution a { color: #fff; font-weight: 600; }
.update-note { display: block; color: rgba(255,255,255,0.65); font-size: 11px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: rgba(26,43,60,0.95); color: #fff;
  padding: 12px 18px; border-radius: 999px; font-size: 14px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3); z-index: 100; max-width: 90%;
  animation: rise 0.2s ease;
}

/* ---- Login --------------------------------------------------------------- */
.login-app {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 0 24px; max-width: 440px;
}
.login-hero { text-align: center; margin-bottom: 28px; color: #fff; }
.login-icon { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.login-hero h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.login-sub { margin: 6px 0 0; opacity: 0.9; font-size: 15px; }

.login-card {
  background: #fff; border-radius: 24px; padding: 24px;
  box-shadow: 0 16px 50px rgba(30,70,120,0.25);
  display: flex; flex-direction: column; gap: 14px;
}
.error-message {
  background: #fdecec; color: var(--danger); padding: 11px 14px;
  border-radius: 12px; font-size: 14px; font-weight: 500;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input {
  padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--divider);
  font: 500 16px 'Inter', sans-serif; color: var(--ink); outline: none; background: #f6f9fc;
}
.field input:focus { border-color: var(--accent); background: #fff; }

.checkbox-label {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  font-size: 14px; color: var(--ink-soft); user-select: none;
}
.checkbox-label input { position: absolute; opacity: 0; }
.checkbox-custom {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--ink-faint);
  display: inline-block; position: relative; flex: 0 0 auto;
}
.checkbox-label input:checked + .checkbox-custom { background: var(--accent); border-color: var(--accent); }
.checkbox-label input:checked + .checkbox-custom::after {
  content: ''; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.btn-primary {
  border: 0; border-radius: 14px; background: var(--accent); color: #fff;
  padding: 15px; font: 700 16px 'Inter', sans-serif; cursor: pointer;
  box-shadow: 0 6px 16px rgba(47,127,209,0.35);
}
.btn-primary:active { transform: scale(0.99); }

@media (max-width: 380px) {
  .now-temp { font-size: 54px; }
  .now-icon { width: 78px; height: 78px; }
  #radarFrame { height: 340px; }
}
