:root {
  --bg: #eef6fb;
  --card: #ffffff;
  --ink: #14384a;
  --accent: #1f9b9b;
  --warning: #f2a14a;
  --danger: #cc4d4d;
  --line: #cfe1ea;
  --muted: #4e6f7f;
  --top-nav: rgba(238, 246, 251, 0.9);
}

[data-theme="dark"] {
  --bg: #0b1c26;
  --card: #132b38;
  --ink: #ddf4ff;
  --accent: #43b6c2;
  --warning: #f3b06a;
  --danger: #ff6f6f;
  --line: #2b4758;
  --muted: #9cc2d4;
  --top-nav: rgba(9, 25, 34, 0.9);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(139, 220, 206, 0.42) 0, transparent 50%),
    radial-gradient(circle at 80% 0%, rgba(143, 196, 234, 0.4) 0, transparent 40%),
    var(--bg);
  padding-top: 48px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  backdrop-filter: blur(6px);
  background: var(--top-nav);
  border-bottom: 1px solid var(--line);
}

.top-nav-row {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.35rem 1rem 0.45rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.55rem;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.ctrl-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.ctrl-select,
.ctrl-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  min-height: 34px;
  padding: 0.2rem 0.65rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-btn,
.nav-link,
.best-pill,
.chip-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.86rem;
  text-decoration: none;
  cursor: pointer;
  min-height: 42px;
}

.nav-btn {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.best-pill {
  background: #eaf6f1;
  border-color: #c6e4d9;
  color: #1c6f5a;
  cursor: default;
}

.spot-chips {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0.1rem 0 0.2rem;
  display: flex;
  gap: 0.38rem;
  overflow-x: auto;
}

.chip-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chip-main {
  font-weight: 700;
}

.chip-meta {
  display: inline-block;
  margin-left: 0.35rem;
  opacity: 0.85;
  font-size: 0.78rem;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem 1rem 1.4rem;
  display: grid;
  gap: 0.75rem;
}

.hero h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.15;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.hero p {
  margin: 0.12rem 0 0;
  line-height: 1.25;
  opacity: 0.8;
}

.hero {
  margin-top: 0.52rem;
  margin-bottom: 0.2rem;
}

.hero .context-line {
  margin: 0.2rem 0 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.15rem;
  box-shadow: 0 16px 28px rgba(15, 43, 70, 0.09);
  min-height: 240px;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.install-popup {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
  z-index: 80;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(13, 33, 27, 0.2);
  padding: 0.9rem;
}

.install-popup h3 {
  margin: 0.25rem 0 0.35rem;
}

.install-popup p {
  margin: 0;
}

.install-close-btn {
  position: absolute;
  right: 0.5rem;
  top: 0.4rem;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  line-height: 1;
  cursor: pointer;
}

.install-btn {
  margin-top: 0.75rem;
  border: 1px solid #166d57;
  background: linear-gradient(135deg, #1f8f74, #176ca1);
  color: #fff;
  border-radius: 10px;
  padding: 0.7rem 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

@media (min-width: 820px) {
  .install-popup {
    display: none !important;
  }
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  color: var(--accent);
  margin: 0;
}

.score {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0.35rem 0;
}

.vibe-card {
  position: relative;
  overflow: hidden;
  min-height: 170px;
  background-image:
    linear-gradient(120deg, rgba(12, 39, 45, 0.75), rgba(9, 20, 35, 0.56)),
    url("https://images.unsplash.com/photo-1507525428034-b723cf961d3e?auto=format&fit=crop&w=1200&q=80");
  background-size: cover;
  background-position: center;
  color: #ecfffb;
}

.vibe-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(4, 14, 20, 0.18), rgba(4, 14, 20, 0.28));
  pointer-events: none;
}

.vibe-overlay h3 {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.35rem;
}

.vibe-overlay p {
  margin: 0;
}

.vibe-overlay {
  position: relative;
  z-index: 1;
  max-width: 80%;
}

.vibe-overlay .eyebrow {
  color: #b9f7e7;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.vibe-overlay h3,
.vibe-overlay p {
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.65);
}

.vibe-card.vibe-good {
  filter: saturate(1.08);
}

.vibe-card.vibe-mid {
  filter: saturate(0.92) contrast(0.92);
}

.vibe-card.vibe-bad {
  filter: grayscale(0.72) saturate(0.55) contrast(0.9);
}

.spot-map {
  width: 100%;
  height: 320px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #e7eef2;
  margin-top: auto;
}

.map-popup-title {
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.leaflet-container,
.leaflet-pane,
.leaflet-top,
.leaflet-bottom {
  z-index: 20 !important;
}

.webcam-drawer {
  position: fixed;
  left: 0;
  top: 50%;
  display: flex;
  flex-direction: row-reverse;
  transform: translateY(-50%) translateX(calc(-100% + 44px));
  transition: transform 0.22s ease;
  z-index: 120;
  filter: drop-shadow(0 10px 20px rgba(23, 59, 48, 0.15));
}

.webcam-drawer:hover,
.webcam-drawer:focus-within {
  transform: translateY(-50%) translateX(0);
}

.webcam-drawer.no-webcam {
  display: none;
}

.webcam-handle {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: none;
  background: #176ca1;
  color: #fff;
  font-weight: 700;
  border-radius: 0 10px 10px 0;
  padding: 0.8rem 0.45rem;
  letter-spacing: 0.05em;
}

.webcam-content {
  width: min(380px, 88vw);
  max-height: 72vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 10px 0 0 10px;
  padding: 0.9rem;
}

.webcam-content h3 {
  margin: 0 0 0.3rem;
}

.drawer-sep {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.8rem 0;
}

.favorite-block h3 {
  margin: 0 0 0.35rem;
}

.favorite-row strong {
  font-size: 0.95rem;
}

.cam-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.02rem 0.35rem;
  font-size: 0.62rem;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, var(--card));
}

.spot-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  background: var(--card);
  color: var(--ink);
  margin-bottom: 0.6rem;
}

.popular-row {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.popular-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.popular-row-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.country-group-title {
  margin: 0.3rem 0 0.1rem;
  padding: 0.2rem 0.1rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.fav-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  min-width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.85rem;
}

.fav-btn.active {
  border-color: #f4b400;
  color: #f4b400;
}

.webcam-embed {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  margin-bottom: 0.7rem;
  background: var(--card);
}

.webcam-embed h4 {
  margin: 0 0 0.4rem;
}

.webcam-embed iframe {
  width: 100%;
  height: 210px;
  border: 0;
  border-radius: 8px;
  background: #eef4f9;
}

.webcam-frame-wrap {
  position: relative;
}

.webcam-full-btn {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: rgba(11, 22, 36, 0.7);
  color: #fff;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
}

[data-theme="dark"] .webcam-embed iframe {
  background: #13283c;
}

[data-theme="dark"] .webcam-full-btn {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(6, 14, 24, 0.78);
}

.webcam-frame-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  background: #000;
}

.webcam-frame-wrap:fullscreen iframe {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.spot-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.spot-link:hover {
  text-decoration: underline;
}

.context-line {
  margin: 0 0 0.8rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.live-meta {
  font-weight: 700;
  color: var(--accent);
}

.reason-list,
.risk-list {
  margin: 0;
  padding-left: 1rem;
}

.reason-list li,
.risk-list li {
  margin-bottom: 0.45rem;
}

.risk-title {
  margin: 0.7rem 0 0.5rem;
  font-weight: 700;
  color: #7e4a34;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.45rem;
  background: var(--card);
  color: var(--ink);
}

.list {
  display: grid;
  gap: 0.6rem;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  min-height: 44px;
}

.day-row {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.day-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 143, 116, 0.14);
}

.spot-row {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.spot-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 143, 116, 0.18);
}

.badge {
  font-weight: 700;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  color: #fff;
}

.good {
  background: var(--accent);
}

.mid {
  background: var(--warning);
}

.low {
  background: var(--danger);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.5rem;
}

#hourly-body tr.hour-best td {
  background: #e5f8ef;
}

[data-theme="dark"] #hourly-body tr.hour-best td {
  background: #1f4c42;
  color: #ecfff8;
  border-bottom-color: #2f6a5d;
}

.ranking-drawer {
  position: fixed;
  right: 0;
  top: 45%;
  transform: translateY(-45%) translateX(calc(100% - 44px));
  transition: transform 0.22s ease;
  z-index: 30;
  display: flex;
  filter: drop-shadow(0 10px 20px rgba(23, 59, 48, 0.15));
  pointer-events: auto;
}

.ranking-handle {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: none;
  background: var(--accent);
  border: 0;
  color: #fff;
  font-weight: 700;
  border-radius: 10px 0 0 10px;
  padding: 0.8rem 0.45rem;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.ranking-content {
  width: 290px;
  max-height: 70vh;
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 10px 10px 0;
  padding: 0.9rem;
}

.spot-row strong,
.spot-row div {
  color: inherit;
}

.ranking-content h3 {
  margin: 0 0 0.3rem;
}

.ranking-drawer.open {
  transform: translateY(-45%) translateX(0);
  pointer-events: auto;
}

.ranking-drawer:hover,
.ranking-drawer:focus-within {
  transform: translateY(-45%) translateX(0);
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0.45rem 1rem 1rem;
}

#footer-version-value {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.08rem 0.52rem;
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.app-footer a:hover {
  text-decoration: underline;
}

@media (min-width: 820px) {
  .app {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .hero {
    grid-column: span 2;
    align-self: start;
  }

  .card {
    height: 100%;
  }
}

@media (min-width: 1100px) {
  .app {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hero {
    grid-column: 1 / -1;
  }

  #best-spot-card,
  #map-card,
  #why-card,
  #days-card {
    grid-column: span 1;
  }

  #vibe-card {
    grid-column: span 2;
  }

  #hourly-card {
    grid-column: 1 / -1;
    min-height: 360px;
  }
}

@media (max-width: 819px) {
  body {
    padding-top: 0;
  }

  .top-nav {
    position: sticky;
    top: 0;
    z-index: 60;
  }

  .top-nav-row {
    padding: 0.25rem 0.5rem 0.2rem;
    gap: 0.35rem;
  }

  .ctrl-label {
    display: none;
  }

  .ctrl-select,
  .ctrl-btn {
    min-height: 28px;
    font-size: 0.74rem;
    padding: 0.1rem 0.42rem;
  }

  .app {
    padding: 0.65rem 0.5rem 0.8rem;
    gap: 0.35rem;
  }

  .hero h1 {
    font-size: 1rem;
  }

  .brand-logo {
    width: 30px;
    height: 30px;
  }

  .card {
    min-height: 0;
    padding: 0.58rem;
    border-radius: 11px;
  }

  .app > * {
    min-width: 0;
    max-width: 100%;
  }

  .spot-chips {
    display: none;
  }

  .chip-btn {
    padding: 0.2rem 0.45rem;
    min-height: 30px;
    font-size: 0.72rem;
  }

  .row {
    padding: 0.42rem;
    min-height: 36px;
  }

  table {
    min-width: 520px;
  }

  th,
  td {
    padding: 0.4rem;
    font-size: 0.82rem;
  }

  .spot-map {
    height: 170px;
  }

  .vibe-card {
    min-height: 130px;
  }

  .best-pill {
    display: none;
  }

  .webcam-drawer {
    position: static;
    transform: none;
    width: 100vw;
    margin: 0.3rem calc(50% - 50vw) 0.4rem;
    filter: none;
  }

  .webcam-drawer:hover,
  .webcam-drawer:focus-within {
    transform: none;
  }

  .webcam-handle {
    display: none;
  }

  .webcam-content {
    width: 100%;
    max-height: none;
    border-right: 1px solid var(--line);
    border-radius: 0;
    padding: 0.8rem;
  }

  .ranking-drawer {
    position: fixed;
    right: 0;
    left: auto;
    bottom: env(safe-area-inset-bottom, 0);
    top: auto;
    transform: none;
    width: min(88vw, 360px);
    margin: 0;
    z-index: 130;
    filter: drop-shadow(0 14px 22px rgba(17, 47, 64, 0.24));
    pointer-events: auto;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
  }

  .ranking-handle {
    display: inline-flex;
    min-height: 42px;
    min-width: 102px;
    align-items: center;
    justify-content: center;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    padding: 0.48rem 0.95rem;
    margin: 0;
  }

  .ranking-content {
    width: 100%;
    max-height: 68vh;
    border: 1px solid var(--line);
    border-right: 0;
    border-bottom: 0;
    border-radius: 14px 0 0 0;
    padding: 0.8rem;
    margin: 0;
    display: none;
  }

  .ranking-drawer:hover,
  .ranking-drawer:focus-within {
    transform: none;
  }

  .ranking-drawer.open {
    transform: none;
  }

  .ranking-drawer.open .ranking-content {
    display: block;
  }
}
