:root {
  --paper: #f5f7fa;
  --surface: #ffffff;
  --ink: #1b2a41;
  --ink-soft: #55627a;
  --line: #d9dee7;
  --open: #2f9e75;
  --open-tint: #dcf2e8;
  --amber: #d98e1f;
  --amber-tint: #fbedd6;
  --past: #eceff3;
  --focus: #2563c9;
  --radius-tile: 10px;
  --radius-btn: 999px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111a28;
    --surface: #18243a;
    --ink: #e8edf5;
    --ink-soft: #a3afc2;
    --line: #2c3a53;
    --open: #4cc495;
    --open-tint: #173b33;
    --amber: #f0aa45;
    --amber-tint: #3b2f1c;
    --past: #1c2638;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
  .half.booked { background: #c9d3e3; }
  .swatch.booked { background: #c9d3e3; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 24px;
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 48px;
  align-items: start;
}

.side { position: sticky; top: 24px; display: grid; gap: 28px; }

.who { margin: 0 0 6px; color: var(--ink-soft); font-size: 0.95rem; }

h1 {
  margin: 0;
  font-size: clamp(2rem, 1.4rem + 2vw, 2.75rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.lede { margin: 14px 0 0; color: var(--ink-soft); max-width: 36ch; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 0.95rem; }
.legend li { display: flex; align-items: center; gap: 10px; }

.swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid var(--line); }
.swatch.free { background: var(--open-tint); border-color: var(--open); }
.swatch.soft { background: repeating-linear-gradient(135deg, var(--amber) 0 3px, var(--amber-tint) 3px 7px); border-color: var(--amber); }
.swatch.booked { background: var(--ink); border-color: var(--ink); }
.swatch.split { background: linear-gradient(var(--open-tint) 0 50%, var(--ink) 50% 100%); }

/* Calendar */
.cal { min-width: 0; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.cal-head h2 {
  margin: 0;
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.nav {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: 1.5rem; line-height: 1;
  cursor: pointer;
}
.nav:disabled { opacity: 0.35; cursor: default; }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.weekdays { margin-bottom: 8px; color: var(--ink-soft); font-size: 0.85rem; font-weight: 500; }
.weekdays span { padding-left: 4px; }

.day {
  position: relative;
  aspect-ratio: 1 / 1.05;
  min-height: 64px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  background: var(--surface);
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr 1fr;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.day.blank { visibility: hidden; }
.day:disabled { cursor: default; }

.half { display: block; }
.half.free { background: var(--open-tint); }
.half.soft { background: repeating-linear-gradient(135deg, var(--amber) 0 3px, var(--amber-tint) 3px 8px); }
.half.booked { background: var(--ink); }
.half.past { background: var(--past); }
.half + .half { border-top: 1px solid var(--surface); }

.num {
  position: absolute; top: 6px; left: 8px;
  font-weight: 700; font-size: 1rem;
  font-variant-numeric: tabular-nums;
  padding: 0 5px; border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
.day.is-past .num { color: var(--ink-soft); background: transparent; }

.day[aria-selected="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.day:focus-visible, .nav:focus-visible, .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.status { min-height: 1.5em; margin: 14px 0 0; color: var(--ink-soft); }
.status.error { color: #b42318; }

/* Day panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.panel-empty { margin: 0; color: var(--ink-soft); }
.panel h3 { margin: 0 0 4px; font-size: 1.25rem; font-weight: 700; }
.panel .sub { margin: 0 0 16px; color: var(--ink-soft); }
.halves { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 6px; font-size: 0.95rem; }
.halves li { display: flex; align-items: center; gap: 8px; }
.actions { display: grid; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 18px;
  border-radius: var(--radius-btn);
  border: 1.5px solid var(--ink);
  font: inherit; font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.secondary { background: transparent; color: var(--ink); }

.foot { max-width: 1180px; margin: 0 auto; padding: 8px 24px 40px; color: var(--ink-soft); font-size: 0.9rem; }

@media (max-width: 860px) {
  .page { display: flex; flex-direction: column; align-items: stretch; gap: 28px; padding: 24px 16px 16px; }
  .side { position: static; display: contents; }
  .intro { order: 1; }
  .legend { order: 2; }
  .cal { order: 3; }
  .panel { order: 4; }
  .weekdays, .grid { gap: 4px; }
  .day { min-height: 0; aspect-ratio: 1 / 1.15; border-radius: 8px; }
  .num { top: 3px; left: 3px; font-size: 0.85rem; padding: 0 3px; }
  .foot { padding: 8px 16px 32px; }
}

@media (prefers-reduced-motion: no-preference) {
  .grid.reveal .day { animation: ink-in 360ms ease-out both; animation-delay: calc(var(--i) * 12ms); }
  @keyframes ink-in { from { opacity: 0; transform: translateY(4px); } }
}
