/* ===== Design tokens ===== */
:root {
  --paper:        #f6f4ee;   /* warm off-white, not the cliché cream */
  --paper-2:      #fffefb;
  --ink:          #1f2a44;   /* deep ink blue — primary */
  --ink-soft:     #46506b;
  --ink-faint:    #8a91a6;
  --line:         #e3ded2;
  --line-strong:  #d3ccba;

  /* category "highlighter" accents */
  --c-task:   #3b82f6;
  --c-event:  #e8638a;
  --c-habit:  #16a394;
  --c-note:   #f0a830;
  --c-goal:   #8b5cf6;

  --today:    #fff6df;       /* spotlight wash on the current day */
  --today-line: #f0c869;

  --radius:   14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(31,42,68,.08), 0 1px 1px rgba(31,42,68,.04);
  --shadow-md: 0 6px 18px rgba(31,42,68,.12), 0 2px 6px rgba(31,42,68,.08);
  --shadow-lift: 0 14px 30px rgba(31,42,68,.18);

  --display: "Fraunces", Georgia, serif;
  --body: "Inter", system-ui, sans-serif;
  --mono: "Space Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(31,42,68,.04) 1px, transparent 0);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: 1rem; color: var(--ink); }
:focus-visible { outline: 2.5px solid var(--ink); outline-offset: 2px; border-radius: 4px; }

/* ===== Auth screen ===== */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 38px 34px;
}
.brand {
  font-family: var(--display); font-weight: 600; font-size: 2.2rem;
  letter-spacing: -.02em; line-height: 1;
}
.brand .dot { color: var(--c-event); }
.auth-tagline { color: var(--ink-soft); margin: 10px 0 26px; font-size: .96rem; }
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-faint); margin-bottom: 6px; font-weight: 600;
}
.field input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--paper); transition: border-color .15s;
}
.field input:focus { border-color: var(--ink); outline: none; }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
}
.swatch[aria-pressed="true"] { border-color: var(--ink); transform: scale(1.12); }
.btn {
  width: 100%; padding: 12px; border-radius: var(--radius-sm); font-weight: 600;
  background: var(--ink); color: var(--paper-2); transition: transform .08s, opacity .15s;
}
.btn:hover { opacity: .92; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink-soft); font-weight: 500; }
.auth-switch { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--ink-soft); }
.auth-switch button { color: var(--ink); font-weight: 600; text-decoration: underline; }
.form-error {
  background: #fdecec; color: #b4232a; border: 1px solid #f3c6c6;
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 14px;
}

/* ===== App shell ===== */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center;
  gap: 16px; padding: 14px 22px; background: rgba(246,244,238,.86);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-size: 1.5rem; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px; }
.tab { padding: 7px 16px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  color: var(--ink-soft); transition: background .15s, color .15s; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper-2); }
.userchip { display: flex; align-items: center; gap: 9px; padding: 5px 6px 5px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper-2); }
.userchip .uname { font-weight: 600; font-size: .9rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .82rem; }

/* ===== Week navigation ===== */
.weekbar { display: flex; align-items: center; gap: 14px; padding: 20px 22px 6px; flex-wrap: wrap; }
.week-title { font-family: var(--display); font-weight: 600; font-size: 1.7rem; letter-spacing: -.02em; }
.week-sub { color: var(--ink-faint); font-size: .9rem; font-family: var(--mono); }
.navbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line-strong);
  background: var(--paper-2); display: grid; place-items: center; font-size: 1.1rem;
  box-shadow: var(--shadow-sm); transition: transform .08s; }
.navbtn:hover { transform: translateY(-1px); }
.today-btn { padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--paper-2); font-weight: 600; font-size: .88rem; box-shadow: var(--shadow-sm); }

/* ===== Week grid ===== */
.week {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px; padding: 14px 22px 60px; align-items: start;
}
.day {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 220px; display: flex; flex-direction: column; transition: box-shadow .15s, border-color .15s;
}
.day.is-today { border-color: var(--today-line); background: var(--today);
  box-shadow: 0 0 0 3px rgba(240,200,105,.25); }
.day.drag-over { border-color: var(--ink); box-shadow: var(--shadow-md); }
.day-head { padding: 12px 13px 8px; display: flex; align-items: baseline; justify-content: space-between; }
.day-name { font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .07em; }
.day-date { font-family: var(--mono); font-size: .78rem; color: var(--ink-faint); }
.day.is-today .day-date { color: #b9821a; font-weight: 700; }
.blocks { flex: 1; padding: 4px 9px 9px; display: flex; flex-direction: column; gap: 8px; }

/* ===== Block cards ===== */
.block {
  background: var(--paper-2); border: 1px solid var(--line); border-left: 4px solid var(--ink-faint);
  border-radius: var(--radius-sm); padding: 9px 11px; box-shadow: var(--shadow-sm);
  cursor: grab; transition: box-shadow .12s, transform .12s, opacity .12s;
}
.block:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.block.dragging { opacity: .5; cursor: grabbing; box-shadow: var(--shadow-lift); }
.block[data-cat="task"]  { border-left-color: var(--c-task); }
.block[data-cat="event"] { border-left-color: var(--c-event); }
.block[data-cat="habit"] { border-left-color: var(--c-habit); }
.block[data-cat="note"]  { border-left-color: var(--c-note); }
.block[data-cat="goal"]  { border-left-color: var(--c-goal); }
.block.done { opacity: .55; }
.block.done .block-title { text-decoration: line-through; }
.block-top { display: flex; align-items: flex-start; gap: 8px; }
.block-check { flex-shrink: 0; width: 18px; height: 18px; border-radius: 5px;
  border: 1.5px solid var(--line-strong); margin-top: 1px; display: grid; place-items: center;
  font-size: .7rem; color: #fff; background: transparent; }
.block.done .block-check { background: var(--c-habit); border-color: var(--c-habit); }
.block-title { font-weight: 600; font-size: .92rem; flex: 1; word-break: break-word; }
.block-time { font-family: var(--mono); font-size: .72rem; color: var(--ink-faint); margin-top: 3px; }
.block-notes { font-size: .82rem; color: var(--ink-soft); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.add-block { margin: 2px 9px 11px; padding: 8px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--line-strong); color: var(--ink-faint); font-weight: 600;
  font-size: .85rem; width: calc(100% - 18px); transition: border-color .15s, color .15s; }
.add-block:hover { border-color: var(--ink); color: var(--ink); }

/* ===== Group calendar ===== */
.group-layout { padding: 8px 22px 60px; }
.group-pick { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0 18px; }
.group-tab { padding: 8px 15px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--paper-2); font-weight: 600; font-size: .88rem; display: flex; align-items: center; gap: 8px; }
.group-tab[aria-selected="true"] { background: var(--ink); color: var(--paper-2); border-color: var(--ink); }
.members-row { display: flex; align-items: center; gap: -6px; margin-left: 4px; }
.members-row .avatar { width: 26px; height: 26px; font-size: .72rem; margin-left: -7px;
  border: 2px solid var(--paper); }
.event {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; box-shadow: var(--shadow-sm); border-top: 3px solid var(--c-event); }
.event-title { font-weight: 600; font-size: .92rem; }
.event-meta { font-family: var(--mono); font-size: .74rem; color: var(--ink-faint); margin-top: 3px; }
.event-loc { font-size: .82rem; color: var(--ink-soft); margin-top: 2px; }
.rsvp-row { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.rsvp { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-strong);
  font-size: .76rem; font-weight: 600; color: var(--ink-soft); }
.rsvp[aria-pressed="true"][data-s="going"] { background: var(--c-habit); color: #fff; border-color: var(--c-habit); }
.rsvp[aria-pressed="true"][data-s="maybe"] { background: var(--c-note); color: #fff; border-color: var(--c-note); }
.rsvp[aria-pressed="true"][data-s="no"]    { background: var(--ink-faint); color: #fff; border-color: var(--ink-faint); }
.att-faces { display: flex; margin-top: 8px; }
.att-faces .avatar { width: 22px; height: 22px; font-size: .64rem; margin-left: -6px; border: 2px solid var(--paper-2); }
.att-faces .avatar:first-child { margin-left: 0; }
.empty-group { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-group .brand { font-size: 1.6rem; margin-bottom: 8px; }

/* ===== Modal ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(31,42,68,.42); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 440px; background: var(--paper-2); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); padding: 26px; max-height: 90vh; overflow: auto; }
.modal h3 { font-family: var(--display); font-weight: 600; font-size: 1.4rem; margin-bottom: 18px; }
.modal .field input, .modal .field textarea, .modal .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--paper); }
.modal textarea { resize: vertical; min-height: 64px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cat-row { display: flex; gap: 7px; flex-wrap: wrap; }
.cat-chip { padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--line-strong);
  font-size: .82rem; font-weight: 600; text-transform: capitalize; }
.cat-chip[aria-pressed="true"] { color: #fff; }
.cat-chip[data-cat="task"][aria-pressed="true"]  { background: var(--c-task);  border-color: var(--c-task); }
.cat-chip[data-cat="event"][aria-pressed="true"] { background: var(--c-event); border-color: var(--c-event); }
.cat-chip[data-cat="habit"][aria-pressed="true"] { background: var(--c-habit); border-color: var(--c-habit); }
.cat-chip[data-cat="note"][aria-pressed="true"]  { background: var(--c-note);  border-color: var(--c-note); }
.cat-chip[data-cat="goal"][aria-pressed="true"]  { background: var(--c-goal);  border-color: var(--c-goal); }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { width: auto; flex: 1; }
.btn.danger { background: #fdecec; color: #b4232a; }
.btn.secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line-strong); }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: var(--paper-2); padding: 11px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-lift); z-index: 60;
  transition: transform .25s cubic-bezier(.2,.9,.3,1); max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }

.loading { display: grid; place-items: center; min-height: 60vh; color: var(--ink-faint);
  font-family: var(--mono); }

/* ===== Responsive ===== */
@media (max-width: 1000px) {
  .week { grid-template-columns: repeat(2, 1fr); }
  .day { min-height: 0; }
}
@media (max-width: 560px) {
  .week { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .weekbar { padding: 14px; }
  .week { padding: 12px 14px 50px; }
  .group-layout { padding: 8px 14px 50px; }
  .row2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
