/* Mobile first, one column. Colors are variables so dark mode only swaps them. */
:root {
  --bg: #f7f4ef;
  --card: #ffffff;
  --fg: #1c1915;
  --muted: #6a6157;
  --line: #ebe4da;
  --line-strong: #d3c9bb;
  --soft: #eee7dd;
  --accent: #c2410c;
  --accent-fg: #ffffff;
  --free-bg: #dcf2e2;
  --free-fg: #135e2a;
  --warn-bg: #fcecc4;
  --warn-fg: #6b4400;
  --tag-bg: #f1ebe2;
  --tag-fg: #4a433a;
  --shadow: 0 1px 2px rgba(70, 48, 20, 0.06), 0 8px 22px -14px rgba(70, 48, 20, 0.28);
  --bar-h: 68px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110e;
    --card: #201c18;
    --fg: #f4efe8;
    --muted: #ada397;
    --line: #2f2923;
    --line-strong: #4a4139;
    --soft: #2a241f;
    --accent: #ff8a57;
    --accent-fg: #2a0e02;
    --free-bg: #173a24;
    --free-fg: #8fe0a8;
    --warn-bg: #3b2d09;
    --warn-fg: #f5c75a;
    --tag-bg: #2d2721;
    --tag-fg: #ddd4c9;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}

/* one color per category: --k text, --kb background */
.cat-party    { --k: #a8235f; --kb: #fce4ef; }
.cat-concert  { --k: #6b3fc0; --kb: #eee7fc; }
.cat-talk     { --k: #1d5ca8; --kb: #e2edfa; }
.cat-workshop { --k: #844c00; --kb: #fbeed6; }
.cat-sport    { --k: #17703a; --kb: #ddf3e4; }
.cat-culture  { --k: #b0262f; --kb: #fce5e5; }
.cat-food     { --k: #a3410c; --kb: #fde7d9; }
.cat-social   { --k: #0d6b69; --kb: #d9f1ef; }
.cat-career   { --k: #3a4890; --kb: #e6e9f7; }
.cat-games    { --k: #566410; --kb: #ecf2d3; }
.cat-other    { --k: #565049; --kb: #efebe5; }
@media (prefers-color-scheme: dark) {
  .cat-party    { --k: #ff8ec0; --kb: #3b1a2b; }
  .cat-concert  { --k: #c5a8ff; --kb: #2b2140; }
  .cat-talk     { --k: #8ebcff; --kb: #1a2a42; }
  .cat-workshop { --k: #f2bf66; --kb: #382a10; }
  .cat-sport    { --k: #7fda9b; --kb: #15321f; }
  .cat-culture  { --k: #ff9a9c; --kb: #3c1c1e; }
  .cat-food     { --k: #ffab80; --kb: #3b2315; }
  .cat-social   { --k: #6fd6d1; --kb: #12322f; }
  .cat-career   { --k: #aab5ff; --kb: #222844; }
  .cat-games    { --k: #c8dc6c; --kb: #2a3112; }
  .cat-other    { --k: #d3cabf; --kb: #2d2721; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top, .filters, main, .foot { max-width: 720px; margin-inline: auto; padding-inline: 16px; }

/* header + summary line */
.top { padding-top: 22px; }
.top h1 { margin: 0; font-size: 1.6rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; }
.updated { margin: 3px 0 0; font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px;
  min-height: 44px; margin: 4px 0 0;
  font-size: 1.05rem; font-weight: 650;
}
.clear {
  min-height: 44px; padding: 0 2px;
  border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer;
}

/* Today · This week · This month (sticks to the top) */
.bar {
  position: sticky; top: 0; z-index: 3;
  height: var(--bar-h);
  padding: 8px 16px;
  background: var(--bg);
}
.seg {
  display: flex; gap: 4px;
  max-width: 688px; margin: 0 auto; padding: 4px;
  background: var(--soft); border-radius: 14px;
}
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: 0 6px; white-space: nowrap;
  border: 0; border-radius: 11px; background: transparent;
  font-weight: 650; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

/* filters: one row everywhere. Free · EPFL · UNIL · Type ▾ · search */
.filters { position: relative; padding-top: 2px; padding-bottom: 8px; }
.chips {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; scrollbar-width: none; padding: 4px 0;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 22px;
  background: var(--card); font-size: 0.95rem; font-weight: 550; white-space: nowrap; cursor: pointer;
}
.chip[aria-pressed="true"], .chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip .caret { margin-left: 5px; font-size: 0.8em; }
@media (max-width: 380px) {                 /* small phones: keep the row on one line */
  .chips { gap: 5px; }
  .chip { padding: 0 11px; }
}
.chip.icon { width: 44px; padding: 0; margin-left: auto; display: inline-flex; align-items: center; justify-content: center; }
.searchbox {
  display: none; align-items: center; gap: 8px;
  min-height: 46px; margin: 4px 0; padding: 0 2px 0 14px;
  border: 2px solid var(--accent); border-radius: 23px; background: var(--card);
}
.searchbox svg { flex: none; color: var(--muted); }
.searchbox input { flex: 1; min-width: 0; min-height: 42px; border: 0; background: transparent; outline: none; }
.searchbox input::placeholder { color: var(--muted); opacity: 1; }
.searchbox input::-webkit-search-cancel-button { display: none; }
.x { flex: none; width: 44px; height: 42px; border: 0; background: none; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.filters.searching .chips { display: none; }
.filters.searching .searchbox { display: flex; }

/* the Type ▾ menu */
.menu {
  position: absolute; z-index: 5; top: calc(100% - 4px); left: 16px; right: 16px; max-width: 440px;
  padding: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 16px 40px -12px rgba(40, 25, 10, 0.35);
}
.menu[hidden] { display: none; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.opt {
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  text-align: left; font-weight: 550; cursor: pointer;
}
.opt[aria-pressed="true"] { background: var(--kb); border-color: var(--k); color: var(--k); font-weight: 700; }
.menu-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.menu-foot .btn { flex: none; min-width: 96px; }

/* the list */
main { min-height: 40vh; padding-bottom: 8px; }
.day {
  position: sticky; top: var(--bar-h); z-index: 2;
  margin: 0; padding: 14px 4px 8px;
  background: var(--bg);
  font-size: 1.08rem; font-weight: 800; letter-spacing: -0.01em;
}
.day .sub { color: var(--muted); font-weight: 500; letter-spacing: 0; }
.day .hot { color: var(--accent); }
.state { text-align: center; color: var(--muted); padding: 56px 16px; margin: 0; }
.state p { margin: 0 0 12px; }
.state.small { padding: 22px 16px; }

/* month view: Monday-to-Sunday grid. Phones: dots by category + count; wide screens: up to 3 titles */
.cal { margin: 4px 0 6px; scroll-margin-top: calc(var(--bar-h) + 8px); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; }
.cal-title { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.cal-nav {
  width: 44px; height: 44px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--card);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.cal-nav:disabled { opacity: 0.3; cursor: default; }
.cal-wd, .cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px;
  margin: 0; padding: 0; list-style: none;
}
.cal-wd li { padding: 2px 0 4px; text-align: center; color: var(--muted); font-size: 0.72rem; font-weight: 650; }
.cd {
  position: relative; min-height: 54px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.cd.out { background: transparent; border-color: transparent; }
.cd.past { background: transparent; border-style: dashed; color: var(--muted); opacity: 0.55; }
.cd.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cd-hit {
  position: absolute; inset: 0; width: 100%; padding: 0;
  border: 0; border-radius: inherit; background: none; cursor: pointer;
}
.cd-num, .cd-dots { pointer-events: none; }
.cd-num {
  min-width: 24px; padding: 0 3px; border-radius: 12px;
  font-size: 0.88rem; font-weight: 700; line-height: 24px; text-align: center;
}
.cd.today .cd-num { background: var(--accent); color: var(--accent-fg); }
#cal-day { scroll-margin-top: var(--bar-h); }
.cd-dots { display: flex; justify-content: center; align-items: center; gap: 2px; }
.cd-dots i { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--k); }
.cd-dots b { font-size: 0.72rem; font-weight: 700; line-height: 1; color: var(--muted); }
.cd-titles { display: none; }
@media (min-width: 700px) {
  .cd { min-height: 100px; padding: 5px; align-items: stretch; }
  .cd-num { align-self: flex-start; }
  .cd-dots { display: none; }
  .cd-titles { position: relative; display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
  .cd-ev, .cd-more {
    display: block; width: 100%; padding: 1px 5px;
    border: 0; border-radius: 6px; text-align: left; cursor: pointer; pointer-events: auto;
    font-size: 0.74rem; font-weight: 650; line-height: 1.4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .cd-ev { background: var(--kb); color: var(--k); }
  .cd-more { background: none; color: var(--muted); }
  .cd-more:hover, .cd-ev:hover { text-decoration: underline; }
}

/* saved events */
.saved-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: 8px 0 4px;
}
.saved-note { margin: 0; color: var(--muted); font-size: 0.9rem; }
.saved-head .btn { flex: 0 1 auto; }

/* event card */
.ev {
  margin: 0 0 10px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow);
  scroll-margin-top: calc(var(--bar-h) + 52px);
  transition: box-shadow 0.3s;
}
.ev.quiet { background: transparent; border-style: dashed; border-color: var(--line-strong); box-shadow: none; }
.ev.flash { box-shadow: 0 0 0 3px var(--accent); }
.ev-main {
  display: grid; grid-template-columns: 4.4rem minmax(0, 1fr); gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}
.ev-time {
  font-size: 1.5rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; padding-top: 22px;
}
.ev-time.word { font-size: 0.88rem; font-weight: 650; letter-spacing: 0; color: var(--muted); padding-top: 27px; }
.ev.quiet .ev-time { color: var(--muted); }
.ev-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: 5px; }
/* ☆ / ★: at the right end of the tags row; 44 px to tap, but only one line tall */
.star {
  width: 44px; height: 44px; margin: -11px -12px -11px auto; padding: 0;
  border: 0; background: none; color: var(--muted); font-size: 1.35rem; line-height: 1; cursor: pointer;
}
.star[aria-pressed="true"] { color: var(--accent); }
.cat, .tag {
  padding: 1px 8px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 700; line-height: 1.5; white-space: nowrap;
}
.cat { background: var(--kb); color: var(--k); }
.tag { background: var(--tag-bg); color: var(--tag-fg); font-weight: 600; }
.tag.warn { background: var(--warn-bg); color: var(--warn-fg); }
.ev-title { margin: 0; font-size: 1.08rem; line-height: 1.28; letter-spacing: -0.005em; }
.ev-toggle {
  display: block; width: 100%; padding: 0;
  border: 0; background: none; text-align: left; font-weight: 750; cursor: pointer;
}
.ev-toggle span {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.ev.open .ev-toggle span { -webkit-line-clamp: unset; line-clamp: unset; }
.ev.quiet .ev-toggle { font-weight: 650; }
.ev-where {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  margin: 5px 0 0; color: var(--muted); font-size: 0.93rem;
}
.ev-where .v { flex: 0 1 auto; min-width: 2.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* a long price is cut before the venue is (full price in the opened card) */
.ev-where .price { flex-shrink: 100000; min-width: 2.4em; }
.ev-where .dot { flex: none; }
.pill-free {
  flex: none; padding: 0 9px; border-radius: 999px;
  background: var(--free-bg); color: var(--free-fg);
  font-size: 0.8rem; font-weight: 700; line-height: 1.6;
}
.ev-org { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; color: var(--muted); font-size: 0.86rem; }
.ev-org > span:last-child { min-width: 0; }
/* organiser picture (docs/logos/, 96 px files shown at 32 px), or its initials on a colour from the handle */
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; background: var(--soft); box-shadow: 0 0 0 1px var(--line);
}
.avatar.initials {
  display: inline-flex; align-items: center; justify-content: center;
  background: hsl(var(--h) 60% 90%); color: hsl(var(--h) 55% 27%); box-shadow: none;
  font-size: 0.72rem; font-weight: 750; letter-spacing: 0.02em; line-height: 1;
}
@media (prefers-color-scheme: dark) {
  .avatar.initials { background: hsl(var(--h) 30% 25%); color: hsl(var(--h) 70% 84%); }
}

.ev-details { padding: 0 16px 16px; }
.ev-details p { margin: 0 0 10px; }
.facts { list-style: none; margin: 0 0 10px; padding: 0; color: var(--muted); font-size: 0.93rem; }
.facts li { margin: 2px 0; }
.by { color: var(--muted); font-size: 0.93rem; }
.by a { display: inline-block; padding: 11px 0; margin: -11px 0; font-weight: 650; text-decoration: none; }
.warn-text { color: var(--warn-fg); background: var(--warn-bg); padding: 6px 10px; border-radius: 10px; font-size: 0.92rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn {
  flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--card); color: var(--fg);
  font-weight: 650; font-size: 0.95rem; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* footer */
.foot {
  margin-top: 20px; padding-top: 18px; padding-bottom: 40px;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.9rem;
}
.foot p { margin: 0 0 8px; }
.foot a { display: inline-flex; align-items: center; min-height: 44px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
