:root {
  color-scheme: light;
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #f1ebdf;
  --ink: #1d2721;
  --muted: #69736c;
  --line: #e2d9c8;
  --line-strong: #cfc3ad;
  --pine: #1f5c45;
  --pine-ink: #fff;
  --pine-soft: #e1eee6;
  --berry: #b3261e;
  --berry-soft: #f9e4e1;
  --gold: #a87414;
  --gold-soft: #f6ead0;
  --zone: #fbf8f1;
  --zone-hover: #e6f1ea;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.06), 0 2px 8px rgb(40 30 10 / 0.05);
  --shadow-lift: 0 12px 32px rgb(40 30 10 / 0.22), 0 2px 6px rgb(40 30 10 / 0.12);
  --radius: 10px;
  --serif: "Young Serif", Georgia, serif;
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  /* One control height: every input, select and button carries exactly these. */
  --ctl-pad-y: 0.55rem;
  --ctl-pad-x: 0.8rem;
  --ctl-font: 0.9375rem;
  --ctl-line: 1.375rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1512;
    --surface: #15201b;
    --surface-2: #1b2822;
    --ink: #edf1ea;
    --muted: #97a59c;
    --line: #26362e;
    --line-strong: #34483e;
    --pine: #5fc795;
    --pine-ink: #08140e;
    --pine-soft: #1a3529;
    --berry: #ff8f84;
    --berry-soft: #3a1d1b;
    --gold: #e7bb5a;
    --gold-soft: #352b17;
    --zone: #121c18;
    --zone-hover: #1a3227;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-lift: 0 14px 36px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 400; }
button, input, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--berry); font-size: 0.875rem; margin: 0; min-height: 0; }
.error:empty { display: none; }

/* A string of lights along the top edge. */
.garland {
  height: 10px;
  background:
    radial-gradient(circle at 10px 5px, var(--berry) 3.5px, transparent 4px) 0 0 / 60px 10px repeat-x,
    radial-gradient(circle at 30px 5px, var(--gold) 3.5px, transparent 4px) 0 0 / 60px 10px repeat-x,
    radial-gradient(circle at 50px 5px, var(--pine) 3.5px, transparent 4px) 0 0 / 60px 10px repeat-x,
    linear-gradient(var(--line-strong), var(--line-strong)) 0 4.5px / 100% 1px no-repeat;
  opacity: 0.9;
}

/* ---------- controls ---------- */
.ctl, .btn {
  padding: var(--ctl-pad-y) var(--ctl-pad-x);
  font-size: var(--ctl-font);
  line-height: var(--ctl-line);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}
.ctl {
  width: 100%;
  min-width: 0;
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.ctl::placeholder { color: var(--muted); opacity: 0.8; }
.ctl:focus { outline: none; border-color: var(--pine); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 22%, transparent); }
textarea.ctl { resize: vertical; min-height: 5rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, border-color 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .card-main:focus-visible, .tab:focus-visible, .pick:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}
.btn.primary { background: var(--pine); border-color: var(--pine); color: var(--pine-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--berry); }
.btn.danger.armed { background: var(--berry); border-color: var(--berry); color: #fff; }
.btn.icon { width: calc(var(--ctl-line) + 2 * var(--ctl-pad-y) + 2px); padding-inline: 0; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { border-color: var(--pine); }
  .btn.ghost:hover { background: var(--surface-2); border-color: transparent; }
  .btn.primary:hover { background: color-mix(in srgb, var(--pine) 88%, #000); }
}
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- login ---------- */
.login { min-height: calc(100dvh - 10px); display: grid; place-items: center; padding: 24px 16px 48px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 24px 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  text-align: center;
  justify-items: center;
}
.login-card h1 { font-family: var(--serif); font-size: 2rem; }
.login-card p { margin: 0; color: var(--muted); }
.login-card .field, .login-card .btn { width: 100%; text-align: left; }
.login-card .btn { justify-content: center; }

/* ---------- app shell ---------- */
.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}
@media (min-width: 900px) { .app { padding-inline: 32px; } }

.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; gap: 14px; align-items: flex-start; min-width: 0; flex: 1 1 420px; }
.brand img { flex: none; margin-top: 2px; }
.brand h1 { font-family: var(--serif); font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.4rem); line-height: 1.1; letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; color: var(--muted); max-width: 62ch; font-size: 0.95rem; text-wrap: pretty; }
.top-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); margin-right: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: #2fa36b; box-shadow: 0 0 0 3px color-mix(in srgb, #2fa36b 25%, transparent); }

.add { display: grid; grid-template-columns: minmax(0, 1fr) 9rem auto; gap: 8px; }
@media (max-width: 560px) {
  .add { grid-template-columns: minmax(0, 1fr) 6.5rem; }
  .add .btn { grid-column: 1 / -1; }
}

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-family: var(--serif); font-size: 1.3rem; white-space: nowrap; }
.section-head > span { text-align: right; font-size: 0.875rem; }

/* ---------- idea pool ---------- */
.pool {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.pool-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 8px;
  min-height: 52px;
}
.empty { color: var(--muted); font-size: 0.9rem; margin: 0; align-self: center; padding: 6px 2px; }

/* ---------- board ---------- */
.board-scroll { overflow-x: auto; overscroll-behavior-x: contain; margin-inline: -4px; padding: 4px 4px 8px; }
.board {
  --cols: 3;
  display: grid;
  grid-template-columns: 9.5rem repeat(var(--cols), minmax(14rem, 1fr));
  gap: 8px;
  min-width: min-content;
}
.board .corner { }
.col-head, .row-head { padding: 4px 6px; }
.col-head { display: grid; gap: 2px; align-content: end; }
.col-head .name { font-weight: 700; color: var(--pine); display: flex; gap: 6px; align-items: baseline; }
.col-head .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-head .meta, .row-head .meta { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-head { display: grid; align-content: start; gap: 2px; padding-top: 12px; }
.row-head .name { font-weight: 700; overflow-wrap: anywhere; }

.zone { transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease; }
.cell {
  background: var(--zone);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 6px;
  min-height: 84px;
  display: grid;
  gap: 6px;
  align-content: start;
}
.zone.over { background: var(--zone-hover); border-color: var(--pine); border-style: solid; }
.pool.over { box-shadow: 0 0 0 2px var(--pine), var(--shadow); }
.cell .hint { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 22px 4px; opacity: 0.7; }

.tabs { display: none; }

/* ---------- cards ---------- */
.card {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 180ms var(--ease-out), opacity 150ms ease, box-shadow 150ms ease;
}
.card::before { content: ""; flex: none; width: 4px; background: var(--line-strong); }
.card.s-bought::before { background: var(--pine); }
.card.s-wrapped::before { background: var(--gold); }
.card-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  padding: 8px 6px 8px 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}
.card-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.card.s-wrapped .card-title { color: var(--muted); }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: 0 7px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; line-height: 1.35rem; }
.chip.bought { background: var(--pine-soft); color: var(--pine); }
.chip.wrapped { background: var(--gold-soft); color: var(--gold); }
.grip {
  flex: none;
  width: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  border-left: 1px solid var(--line);
  opacity: 0.75;
}
.grip svg { width: 14px; height: 14px; }
@media (hover: hover) and (pointer: fine) {
  .card { cursor: grab; }
  .card:hover { border-color: var(--line-strong); }
  .card:hover .grip { opacity: 1; }
}
.card.source { opacity: 0.35; }
.card.landed { animation: landed 420ms var(--ease-out); }
@keyframes landed {
  0% { transform: scale(0.94); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 40%, transparent); }
  100% { transform: none; }
}
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  pointer-events: none;
  box-shadow: var(--shadow-lift);
  transform-origin: 20% 50%;
  rotate: -2deg;
  opacity: 0.96;
}
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

/* ---------- phone: one occasion at a time ---------- */
@media (max-width: 720px) {
  .tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -16px 10px;
    padding: 2px 16px 4px;
    scroll-padding-inline: 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: none;
    display: inline-flex;
    gap: 6px;
    align-items: center;
    padding: var(--ctl-pad-y) 14px;
    font-size: var(--ctl-font);
    line-height: var(--ctl-line);
    border-radius: 99px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tab[aria-selected="true"] { background: var(--pine); border-color: var(--pine); color: var(--pine-ink); }
  .tab .n { font-variant-numeric: tabular-nums; opacity: 0.75; font-weight: 500; }
  .tab.over { box-shadow: 0 0 0 2px var(--pine); }
  .board-scroll { overflow: visible; margin: 0; padding: 0; }
  .board { grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 4px; }
  .board .corner, .board .col-head { display: none; }
  .row-head { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 2px 2px; }
  .cell { min-height: 64px; }
  .cell .hint { padding: 14px 4px; }
}

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: min(88dvh, 760px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in 220ms var(--ease-out); }
dialog.sheet > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
dialog.sheet:focus { outline: none; }
dialog::backdrop { background: rgb(10 16 13 / 0.45); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (max-width: 560px) {
  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    max-height: 92dvh;
  }
  @keyframes sheet-in { from { transform: translateY(100%); } }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font-family: var(--serif); font-size: 1.35rem; }
.sheet-body { padding: 6px 20px 16px; overflow-y: auto; display: grid; gap: 14px; }
.sheet-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }

.field { display: grid; gap: 5px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field > span, .field > legend { font-size: 0.85rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 10px; }

.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block;
  text-align: center;
  padding: calc(var(--ctl-pad-y) - 3px) 6px;
  line-height: var(--ctl-line);
  font-size: var(--ctl-font);
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 600;
  color: var(--muted);
  transition: background-color 150ms ease, color 150ms ease;
}
.seg input:checked + span { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--pine); outline-offset: 1px; }

.picker { display: grid; gap: 4px; grid-template-columns: minmax(4.5rem, 7rem) repeat(var(--cols, 3), minmax(0, 1fr)); align-items: stretch; }
.picker .ph { font-size: 0.72rem; line-height: 1.2; color: var(--muted); font-weight: 600; text-align: center; padding: 0 2px 3px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; align-self: end; }
.picker .rh { font-size: 0.85rem; font-weight: 600; align-self: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick {
  border: 1px solid var(--line-strong);
  background: var(--zone);
  border-radius: 7px;
  min-height: 36px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
.pick[aria-pressed="true"] { background: var(--pine); border-color: var(--pine); color: var(--pine-ink); font-weight: 700; }
.pick.pool-pick { grid-column: 1 / -1; min-height: 0; padding: var(--ctl-pad-y) var(--ctl-pad-x); line-height: var(--ctl-line); font-size: var(--ctl-font); margin-top: 4px; }

.settings-block { display: grid; gap: 8px; }
.settings-block h3 { font-weight: 700; font-size: 1rem; }
.edit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
/* The list rows and the add row share one set of tracks, so the fields line up. */
.settings-block { --icon: calc(var(--ctl-line) + 2 * var(--ctl-pad-y) + 2px); --tail: calc(3 * var(--icon) + 8px); }
.edit-list li, .edit-add { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, var(--icon)); gap: 4px; align-items: center; }
.edit-list li.occ, .edit-add.occ { grid-template-columns: 3.4rem minmax(0, 1fr) repeat(3, var(--icon)); }
.edit-add .btn { grid-column: span 3; padding-inline: 4px; }
.ctl.emoji { text-align: center; padding-inline: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  translate: -50% 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 10px 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow-lift);
  font-size: 0.925rem;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 220ms var(--ease-out);
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast button { background: transparent; color: inherit; border: 1px solid color-mix(in srgb, var(--bg) 40%, transparent); border-radius: 8px; padding: 4px 10px; font-weight: 700; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .drag-ghost { rotate: 0deg; }
}
.span-all { grid-column: 1 / -1; }
.card-main:focus-visible { outline-offset: -3px; border-radius: 6px; }
