body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--gap-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ---------- Bottom navigation ---------- */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 15;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.navbtn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  color: var(--text-tertiary);
}
.navbtn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.navbtn.is-active { color: var(--accent); }

/* ---------- Calendar (month grid) ---------- */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--gap-md);
  margin-bottom: var(--gap-md);
}
.cal-nav__title { font-size: 1rem; font-weight: 600; }
.cal-nav .btn { padding: 4px 12px; font-size: 1rem; line-height: 1; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-wd {
  background: var(--bg);
  padding: 6px 0;
  text-align: center;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.cal-cell {
  background: var(--surface);
  min-height: 78px;
  min-width: 0;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
/* All empty cells (leading + trailing) share the same dark surface. */
.cal-cell--empty { background: var(--surface); }
/* Days with events are tappable anywhere in the cell. */
.cal-cell--has-events { cursor: pointer; }
.cal-cell__num {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.cal-cell--today .cal-cell__num {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Mobile: events show as colored dots (cells are too small for text). */
.cal-cell__events {
  display: flex;
  flex-flow: row wrap;
  gap: 3px;
  overflow: hidden;
}
.cal-ev {
  --ev-color: var(--text-tertiary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.cal-ev__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ev-color);
}
.cal-ev__label { display: none; }
.cal-ev--rates { --ev-color: #ff5c00; }
.cal-ev--earnings { --ev-color: #4caf50; }
.cal-ev--expiry { --ev-color: #e040fb; }
.cal-ev--data { --ev-color: #29b6f6; }
.cal-ev--crypto { --ev-color: #ffb300; }

/* ---------- GAP row: clock box (left) + AI Brief box (right) ---------- */
.gaprow {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--gap-lg) var(--gap-md) var(--gap-sm);
  display: flex;
  align-items: stretch;
  gap: var(--gap-sm);
}
.gapbar { flex: 1 1 auto; min-width: 0; }

/* Flip-clock button fills the clock box. */
.gapclock {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-sm) var(--gap-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  overflow: hidden;
}
.gapclock:hover { border-color: var(--accent); }
.gapclock__seg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.gapclock__date {
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.gapclock__time {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  white-space: nowrap;
}
/* Timezone rides next to the TO date, contained inside the box. */
.gapclock__tz {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}
.gapclock__arrow {
  flex: 0 0 auto;
  font-size: 1rem;
  color: var(--text-tertiary);
  margin: 0 2px;
}
.gapclock__edit {
  margin-left: auto;
  color: var(--accent);
  display: flex;
  align-items: center;
}
.gapclock__edit svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* AI Brief box — two square icon buttons (script + listen), clock height. */
.brief {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--accent-soft);
}
.brief__btn {
  flex: 0 0 3.25rem;
  width: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.brief__btn:hover { background: var(--accent); color: #fff; }
.brief__btn:first-child { border-right: 1px solid var(--accent); }
.brief__btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brief__btn.is-on { background: var(--accent); color: #fff; }

/* ---------- Filter bar ---------- */
.filterbar {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 6px var(--gap-md) var(--gap-lg);
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filterbar::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.pill[aria-pressed="true"] {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- Content / timeline ---------- */
.content {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--gap-md);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.status {
  padding: var(--gap-xl) var(--gap-md);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
}

/* ---------- Date grouping ---------- */
:root { --rail-x: 70px; } /* 56px time col + 8px gap + 6px half-rail */
.day-group { position: relative; }
/* The date doubles as a time indicator, so it sits in the time column to the
   left of the rail, right-aligned above the times below it. */
.day-header {
  width: var(--rail-x);
  padding-right: 14px;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: var(--gap-xs);
}
.day-header__wd { display: block; color: var(--text-secondary); font-size: 0.72rem; font-weight: 600; }
.day-header__md { display: block; }
/* The rail is drawn once on the day container so it stays continuous
   regardless of each card's time-text width. */
.day-items { position: relative; }
.day-items::before {
  content: "";
  position: absolute;
  left: var(--rail-x);
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--gap-sm);
  padding: var(--gap-md) 0;
}
/* Time column, right-aligned against the rail and lined up with the title. */
.card__when {
  flex: 0 0 56px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  padding-top: 2px;
}
.card__time {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
/* 12px spacer cell holding the dot, aligned to the event's title line. */
.card__rail {
  position: relative;
  flex: 0 0 12px;
  align-self: stretch;
}
.card__dot {
  position: absolute;
  left: 50%;
  top: 9px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
}
.card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.card__bm {
  flex: 0 0 auto;
  padding: 2px;
  color: var(--text-tertiary);
  align-self: flex-start;
}
.card__bm svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.card__bm.is-on { color: var(--accent); }
.card__bm.is-on svg { fill: var(--accent); }
.card__title {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
}
.card__tags {
  margin-bottom: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tag {
  font-size: 0.68rem;
  color: var(--text-secondary);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

/* ---------- Event story scroll (multiple sources per event) ---------- */
.story-scroll {
  display: flex;
  gap: var(--gap-sm);
  margin-top: var(--gap-sm);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.story-scroll::-webkit-scrollbar { display: none; }
.story {
  flex: 0 0 140px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.story__thumb {
  width: 140px;
  height: 88px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-2);
}
.story__thumb--ph {
  display: flex;
  align-items: center;
  justify-content: center;
}
.story__ph-src {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32);
}
:root[data-theme="light"] .story__ph-src {
  color: rgba(0, 0, 0, 0.34);
}
.story__src {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.story__head {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.story:hover .story__head { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  padding: 7px 14px;
  font-size: 0.82rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn:hover { background: var(--surface-2); }
.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
}
.btn--icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn--icon.is-on { color: var(--accent); border-color: var(--accent); }
.btn--icon.is-on svg { fill: var(--accent); stroke: var(--accent); }
.btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn--accent:hover { background: #ff6f1f; }

/* ---------- Dialog ---------- */
.dialog {
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  width: min(92vw, 380px);
}
.dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog__title { font-size: 1rem; margin-bottom: var(--gap-md); }
.dialog__meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: var(--gap-md);
}
/* Category tag in the event dialog: tint via its left border + soft bg. */
#eventCat {
  display: inline-block;
  margin-bottom: var(--gap-sm);
  border-left: 3px solid var(--text-tertiary);
}
.btn.is-on { color: var(--accent); border-color: var(--accent); }
.field {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  margin-bottom: var(--gap-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text-primary);
}
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--gap-sm);
  margin-top: var(--gap-sm);
}
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-sm);
}
.preset {
  padding: 12px;
  font-size: 0.85rem;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
}
.preset:hover { border-color: var(--accent); color: var(--accent); }
#gapCustom:not([hidden]) { margin-top: var(--gap-md); }

#settingsView { padding-top: var(--gap-lg); }
.settings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
  padding: var(--gap-md) 0;
  border-bottom: 1px solid var(--border);
}
.settings-row__label {
  font-size: 0.95rem;
  color: var(--text-primary);
}
.settings-meta {
  display: flex;
  justify-content: space-between;
  padding: var(--gap-md) 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.seg-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg {
  padding: 8px 12px;
  font-size: 0.78rem;
  background: var(--bg);
  color: var(--text-secondary);
  white-space: nowrap;
}
.seg + .seg { border-left: 1px solid var(--border); }
.seg.is-on { background: var(--accent); color: #fff; }

/* ---------- Report panel ---------- */
.reportbackdrop {
  position: fixed;
  inset: 0;
  z-index: 24;
  background: rgba(0, 0, 0, 0.45);
}
.reportpanel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--gap-md);
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
}
.reportpanel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--gap-md);
}
.reportpanel__title { font-size: 1rem; }
.reportpanel__controls { display: flex; gap: var(--gap-sm); }
.reportpanel__body {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* Bookmarks view: this tab hides the GAP/filter header, so its own title
   reserves the top breathing room the other tabs get from the topbar. */
#bookmarksView { padding-top: var(--gap-lg); }
.view-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: var(--gap-md);
}

/* ---------- Mobile (default) tweaks ---------- */
@media (max-width: 699px) {
  /* Event detail fills the empty space below the month grid: full width,
     flush to the edges, docked above the bottom nav. No floating card / shadow
     (which looked out of place in light mode). */
  #eventDialog {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    top: auto;
    margin: 0 auto;
    width: 100%;
    max-width: var(--maxw);
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
  }
  /* Don't dim the calendar — the sheet should feel like it fills the empty
     space below the month grid, not cover it. */
  #eventDialog::backdrop { background: transparent; }

  /* GAP editor docks full-width at the top instead of a floating corner box. */
  #gapDialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    margin: 0 auto;
    width: 100%;
    max-width: var(--maxw);
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: none;
  }
}

/* ---------- Tablet / desktop ---------- */
@media (min-width: 700px) {
  /* Calendar cells are large enough for text labels instead of dots. */
  .cal-cell__events { flex-flow: column nowrap; gap: 2px; }
  .cal-ev {
    display: block;
    font-size: 0.62rem;
    line-height: 1.25;
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--surface-2);
    color: var(--text-primary);
    border-left: 2px solid var(--ev-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .cal-ev__dot { display: none; }
  .cal-ev__label { display: inline; }
}

/* ---------- Wide screens ---------- */
@media (min-width: 900px) {
  .content { padding-top: var(--gap-lg); }
  .card__title { font-size: 1.04rem; }
  .cal-cell { min-height: 92px; }
}
