/* ------------------------------------------------------------------ *
   Hlaupadagskrá — personal running calendar
   Aurora-inspired palette · trail = teal/green · road = amber
 * ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Theme tokens ---------- */
:root, body[data-theme="dark"] {
  --bg: #0c1118;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #12303a 0%, transparent 55%),
             radial-gradient(1000px 500px at 0% 0%, #1a1440 0%, transparent 50%);
  --surface: #141b26;
  --surface-2: #1b2432;
  --surface-hover: #212c3d;
  --border: #263140;
  --fg: #e7edf5;
  --fg-dim: #9fb0c3;
  --fg-faint: #6b7c90;
  --accent: #38e0b0;
  --accent-fg: #04120d;
  --trail: #38e0b0;
  --trail-soft: rgba(56, 224, 176, 0.14);
  --road: #ffb057;
  --road-soft: rgba(255, 176, 87, 0.16);
  --other: #9d8cff;
  --other-soft: rgba(157, 140, 255, 0.16);
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
}
body[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, #d5f3ea 0%, transparent 55%),
             radial-gradient(1000px 500px at -5% 0%, #e6e2ff 0%, transparent 50%);
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --surface-hover: #e9eff6;
  --border: #dbe3ee;
  --fg: #16202e;
  --fg-dim: #52627a;
  --fg-faint: #8494a8;
  --accent: #109e78;
  --accent-fg: #ffffff;
  --trail: #109e78;
  --trail-soft: rgba(16, 158, 120, 0.12);
  --road: #d9820f;
  --road-soft: rgba(217, 130, 15, 0.13);
  --other: #6c5cd6;
  --other-soft: rgba(108, 92, 214, 0.12);
  --danger: #d64545;
  --shadow: 0 12px 30px rgba(40, 60, 90, 0.14);
  --shadow-sm: 0 2px 10px rgba(40, 60, 90, 0.08);
}
body { background-image: var(--bg-grad); background-attachment: fixed; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 26px; width: 46px; height: 46px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--trail), #2bb5d8); border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.brand-text h1 { margin: 0; font-size: clamp(20px, 3vw, 26px); letter-spacing: -0.02em; }
.tagline { margin: 0; font-size: 13px; color: var(--fg-dim); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.updated { font-size: 12px; color: var(--fg-faint); margin-right: 4px; white-space: nowrap; }
.icon-btn {
  background: var(--surface-2); color: var(--fg); border: 1px solid var(--border);
  border-radius: 10px; height: 38px; min-width: 38px; padding: 0 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-hover); }
.icon-btn:active { transform: scale(0.96); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 16px clamp(16px, 4vw, 40px);
  max-width: 1200px; margin: 0 auto;
}
.search-wrap { position: relative; flex: 1 1 260px; min-width: 200px; }
.search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--fg-faint); }
#search {
  width: 100%; height: 42px; padding: 0 14px 0 38px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg); font-size: 14px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select {
  height: 42px; padding: 0 32px 0 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238494a8' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--fg); font-size: 14px; cursor: pointer; -webkit-appearance: none; appearance: none;
}
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.segmented button {
  border: none; background: transparent; color: var(--fg-dim); cursor: pointer;
  padding: 7px 13px; border-radius: 9px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px; transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--fg); }
.segmented button.active { background: var(--surface-hover); color: var(--fg); box-shadow: var(--shadow-sm); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-trail { background: var(--trail); }
.dot-road { background: var(--road); }

/* ---------- Main ---------- */
#main { max-width: 1200px; margin: 0 auto; padding: 4px clamp(16px, 4vw, 40px) 60px; }
.result-count { color: var(--fg-faint); font-size: 13px; margin: 6px 2px 14px; }

/* ---------- Month groups + cards ---------- */
.month-group { margin-bottom: 26px; }
.month-head {
  position: sticky; top: 74px; z-index: 10;
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--fg-dim); padding: 6px 2px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px);
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.card {
  position: relative; text-align: left; cursor: pointer; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 16px 14px 18px; transition: transform .13s ease, border-color .15s, box-shadow .15s;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--type-color, var(--trail)); }
.card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--type-color) 55%, var(--border)); box-shadow: var(--shadow); }
.card.type-trail { --type-color: var(--trail); }
.card.type-road  { --type-color: var(--road); }
.card.type-other { --type-color: var(--other); }

.card-top { display: flex; gap: 14px; align-items: flex-start; }
.date-badge {
  flex: 0 0 auto; width: 54px; text-align: center; border-radius: 12px; padding: 7px 0;
  background: var(--surface-2); border: 1px solid var(--border);
}
.date-badge .d { font-size: 20px; font-weight: 800; line-height: 1; }
.date-badge .m { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-dim); }
.date-badge.tbd .d { font-size: 15px; padding: 4px 0; }
.card-title { margin: 0; font-size: 16.5px; letter-spacing: -0.01em; }
.card-loc { margin: 3px 0 0; font-size: 13px; color: var(--fg-dim); display: flex; align-items: center; gap: 5px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--fg-dim); border: 1px solid var(--border);
}
.chip.dist { background: var(--type-color-soft, var(--trail-soft)); color: var(--fg); border-color: transparent; }
.card.type-trail { --type-color-soft: var(--trail-soft); }
.card.type-road  { --type-color-soft: var(--road-soft); }
.card.type-other { --type-color-soft: var(--other-soft); }

.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 7px; display: inline-flex; align-items: center; gap: 5px; }
.badge.reg  { background: var(--trail-soft); color: var(--trail); }
.badge.conf { background: var(--surface-2); color: var(--fg-dim); }
.badge.unconf { background: var(--road-soft); color: var(--road); }
.badge.cancel { background: rgba(255,107,107,.15); color: var(--danger); }
.type-pill { position: absolute; top: 14px; right: 14px; font-size: 11px; font-weight: 700; color: var(--type-color); }

/* ---------- Overview map ---------- */
.map-view { margin-top: 8px; }
#overviewMap { height: min(70vh, 640px); border-radius: 16px; border: 1px solid var(--border); overflow: hidden; }

/* ---------- Empty ---------- */
.empty { text-align: center; color: var(--fg-dim); padding: 60px 20px; font-size: 16px; }
.hidden { display: none !important; }

/* ---------- Detail slide-over ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(4,8,14,.55); z-index: 40; opacity: 0; transition: opacity .2s; }
.backdrop.show { opacity: 1; }
.detail-panel {
  position: fixed; top: 0; right: 0; height: 100dvh; width: min(500px, 100vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .26s cubic-bezier(.22,.61,.36,1);
  overflow-y: auto; overscroll-behavior: contain;
}
.detail-panel.open { transform: translateX(0); }
.close-btn {
  position: absolute; top: 14px; right: 14px; z-index: 2; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(6px); color: var(--fg); font-size: 16px; cursor: pointer;
}
.close-btn:hover { background: var(--surface-hover); }

.detail-hero { padding: 26px 24px 20px; color: #fff; position: relative; }
.detail-hero.type-trail { background: linear-gradient(135deg, #0e7c5f, #17b489); }
.detail-hero.type-road  { background: linear-gradient(135deg, #b5610a, #ff9e3d); }
.detail-hero.type-other { background: linear-gradient(135deg, #4b3fb0, #8a79ff); }
.detail-hero .type-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; opacity: .9; }
.detail-hero h2 { margin: 8px 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.detail-hero .hero-date { font-size: 14px; opacity: .95; }
.detail-hero .hero-loc { font-size: 14px; opacity: .9; margin-top: 2px; }

.detail-body { padding: 18px 24px 40px; }
.detail-section { margin-bottom: 22px; }
.detail-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); margin: 0 0 9px; }
.detail-desc { color: var(--fg); font-size: 15px; margin: 0; }

.dist-list { display: flex; flex-wrap: wrap; gap: 8px; }
.dist-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.dist-item b { font-size: 15px; }

.link-btns { display: flex; flex-direction: column; gap: 8px; }
.link-btn {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; color: var(--fg); font-weight: 600; font-size: 14px; transition: background .15s, border-color .15s;
}
.link-btn:hover { background: var(--surface-hover); border-color: var(--accent); }
.link-btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.link-btn.primary:hover { filter: brightness(1.05); }
.link-btn .lb-ico { font-size: 17px; }
.link-btn .lb-sub { margin-left: auto; font-size: 12px; color: var(--fg-faint); font-weight: 500; }

#detailMap { height: 240px; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; }
.route-stats { display: flex; gap: 18px; margin: 10px 2px 0; font-size: 13px; color: var(--fg-dim); }
.route-stats b { color: var(--fg); font-size: 15px; }
.elev-wrap { margin-top: 12px; }
.elev-svg { width: 100%; height: 110px; display: block; }
.no-route { color: var(--fg-dim); font-size: 14px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 12px; padding: 16px; text-align: center; }

.runners { display: flex; flex-direction: column; gap: 6px; }
.runner-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 9px; font-size: 14px; }
.runner-row .r-club { margin-left: auto; font-size: 12px; color: var(--fg-faint); }
.runner-row .r-dist { font-size: 11px; color: var(--fg-dim); background: var(--surface); padding: 2px 7px; border-radius: 6px; }
.runners-note { font-size: 13px; color: var(--fg-dim); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .toolbar { gap: 8px; }
  .updated { display: none; }
  .month-head { top: 66px; }
  .cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Prevent long unbroken scraped strings from overflowing their containers */
.card-title, .card-loc, .detail-hero h2, .detail-hero .hero-loc,
.detail-desc, .dist-item, .runner-row span, .lb-sub, .link-btn span {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
