/* Plait & Page: the planner's look (copied from the planner's styles.css) so the two match: its font,
   colour families, page backgrounds, white cards with a thin black edge, tinted headings,
   buttons and fields. The background is chosen with the Background menu. */

@font-face {
  font-family: 'DM Sans'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/dm-sans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'DM Sans'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/dm-sans-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Design tokens (same as the planner) ---------- */
:root {
  --bg: #E9E6DF;
  --ink: #1F2230;
  --muted: #5B6070;
  --line: #ECECF0;
  --card: #fff;
  /* The thin black edge on the big white cards, drawn as a shadow so nothing shifts */
  --card-edge: 0 0 0 1.5px var(--ink);
  color-scheme: light;
}

/* Colour families: accent (solid), tint (pastel fill), mid (outline), dark (text).
   Each section stores which one it uses (store.js). */
.c-lavender { --accent: #534AB7; --tint: #EEEDFE; --mid: #AFA9EC; --dark: #3C3489; }
.c-teal     { --accent: #1C9AA6; --tint: #CDEFF0; --mid: #9ED9DC; --dark: #0B5A61; }
.c-coral    { --accent: #E07A7C; --tint: #FCE4E4; --mid: #F3BEC0; --dark: #8A3539; }
.c-sage     { --accent: #6B8F71; --tint: #E3EDE3; --mid: #C2D6C3; --dark: #3B5A40; }
.c-grey     { --accent: #6B7080; --tint: #E8E9EE; --mid: #D3D5DD; --dark: #3B3F4C; }

/* ---------- Page backgrounds (the planner's choice, from its Settings → Theme) ---------- */
:root { --page-bg: var(--bg); }
[data-bg="stone"]    { --page-bg: var(--bg); }
[data-bg="lavender"] { --page-bg: linear-gradient(135deg, #D3DEF8, #DDD1F6 50%, #F1D1E9); }
[data-bg="mint"]     { --page-bg: linear-gradient(135deg, #C9F0E4, #D7D9F8); }
[data-bg="sage"]     { --page-bg: linear-gradient(135deg, #D0EFCF, #FAEBC4); }
[data-bg="sky"]      { --page-bg: linear-gradient(135deg, #CCE7FA, #FDF2CF); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; background: var(--page-bg); }
body {
  margin: 0; color: var(--ink);
  font: 400 15px 'DM Sans', system-ui, sans-serif;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { max-width: 1400px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- Header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
/* "Boards" like the planner's "Planner" name, then the board's title like a planner page title */
.title-group { display: flex; align-items: flex-end; gap: 12px 40px; flex-wrap: wrap; }
.brand-group { display: flex; flex-direction: column; margin: 0; font-size: inherit; }
.brand { font-size: 24px; font-weight: 700; line-height: 1.2; }
.tagline { font-size: 13px; font-weight: 500; color: var(--muted); }
select.btn-card { padding-right: 10px; cursor: pointer; }
h1 { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.25; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons and fields (as in the planner) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--card); color: var(--ink); font-weight: 600; font-size: 14px;
  text-decoration: none; white-space: nowrap;
}
/* White pill buttons on the page background, like the planner's Filter button */
.btn-card {
  min-height: 36px; padding: 0 14px; border: 1px solid #C9CBD3; border-radius: 999px; font-size: 13.5px;
}
.btn-card:hover { background: #EFEFF4; }
.btn-dark { background: var(--ink); color: #fff; }
.btn-tint { background: var(--tint); color: var(--dark); }
.btn-tint:hover { filter: brightness(.97); }
.btn-outline { border: 1px solid #C9CBD3; }
.btn-quiet { background: none; color: var(--muted); text-decoration: underline; }

.field {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--mid, #D3D5DD); border-radius: 10px; background: var(--card);
  font: inherit; color: var(--ink);
}
textarea.field { height: auto; min-height: 140px; padding: 10px 12px; line-height: 1.45; resize: vertical; font-size: 14px; }

/* ---------- Notices (copy from the planner, backup reminder): slim white cards ---------- */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: 16px; background: var(--card); box-shadow: var(--card-edge);
  font-size: 14px; line-height: 1.4;
}
.notice-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Sections: white cards with a tinted heading, like the planner's lists ---------- */
.section {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card); border-radius: 16px; box-shadow: var(--card-edge);
}
.section.drop-over { box-shadow: var(--card-edge), 0 0 0 5px var(--accent); }
/* Name with a small tally under it, as in the planner's list headings */
.section-head {
  display: flex; flex-direction: column; gap: 2px; margin: 0;
  padding: 14px 18px; border-radius: 16px 16px 0 0;
  background: var(--tint); color: var(--dark); font-size: 18px; font-weight: 700;
}
.section-tally { font-size: 13px; font-weight: 500; }
.section-body { flex: 1; display: flex; flex-direction: column; padding: 14px 18px 16px; }

.sections { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.cards { display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.tray .cards { flex-direction: row; flex-wrap: wrap; align-items: flex-start; min-height: 48px; }
.tray .card { width: 260px; }
.empty { margin: 0; padding: 8px 0; color: var(--muted); font-size: 13px; }

/* ---------- Cards (like the planner's idea cards) ---------- */
.card {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px;
  border: 1px solid var(--mid); border-radius: 12px; background: var(--card); cursor: grab;
}
.card:hover { background: var(--tint); }
.card.dragging { opacity: 0.4; }
/* A long title without a short name stops after 3 lines (pointing at the card shows it all) */
.card-title {
  font-size: 14px; font-weight: 700; color: var(--dark); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-authors { font-size: 12.5px; color: var(--dark); overflow-wrap: anywhere; }
/* Each author's name is a button: clicking it lights up every card with that author */
.author {
  padding: 0 2px; margin: 0 -2px; border: 0; border-radius: 4px; background: none;
  font: inherit; color: inherit; text-decoration: underline; text-decoration-color: var(--mid); cursor: pointer;
}
.author:hover { background: var(--mid); text-decoration: none; }
.author.on { background: var(--dark); color: #fff; text-decoration: none; }

.card-why { color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.card-why p { margin: 0; }
.card-why p.gap { height: 0.5em; }
.card-why ul { margin: 2px 0; padding-left: 18px; }
.card-why strong { color: var(--ink); font-weight: 700; }
/* On the board a note shows up to 4 lines; "…" marks that there's more inside */
.card .card-why { max-height: calc(1.45em * 4); overflow: hidden; position: relative; }
.card .card-why.clipped::after {
  content: '…'; position: absolute; right: 0; bottom: 0; padding-left: 6px;
  background: var(--card); color: var(--ink);
}
.card:hover .card-why.clipped::after { background: var(--tint); }
.card-source {
  font-size: 12.5px; color: var(--dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
a.card-source { text-decoration: underline; text-decoration-color: var(--mid); }
a.card-source:hover { text-decoration-color: var(--dark); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
/* Keywords are buttons: clicking one lights up every card that shares it */
.chip {
  padding: 2px 9px; border: 0; border-radius: 999px; background: var(--tint); color: var(--dark);
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.card:hover .chip { background: var(--card); }
.chip:hover, .card:hover .chip:hover { background: var(--mid); }
.chip.on, .card:hover .chip.on { background: var(--dark); color: #fff; }

/* While a keyword is lit: matching cards get a strong outline, the rest fade back */
.card.lit { box-shadow: 0 0 0 2px var(--dark); }
.card.dim { opacity: 0.35; }
.card.dim:hover { opacity: 0.7; }

/* Where a dragged card will land */
.card.drop-before::before, .card.drop-after::after {
  content: ''; position: absolute; background: var(--accent); border-radius: 2px;
  left: 0; right: 0; height: 3px;
}
.card.drop-before::before { top: -7px; }
.card.drop-after::after { bottom: -7px; }
.tray .card.drop-before::before, .tray .card.drop-after::after { top: 0; bottom: 0; width: 3px; height: auto; }
.tray .card.drop-before::before { left: -7px; right: auto; }
.tray .card.drop-after::after { right: -7px; left: auto; }

/* ---------- Add boxes (like the planner's quick-add) ---------- */
.add { margin-top: auto; padding-top: 14px; }
.add input {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px dashed var(--mid); border-radius: 10px; background: var(--card); font: inherit; color: var(--ink);
}
.add input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.tray .add { max-width: 560px; }

/* ---------- Dialogs (like the planner's preview card) ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; color: var(--ink);
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 12px 32px rgba(31, 34, 48, .18);
}
dialog::backdrop { background: rgba(31, 34, 48, .28); }
.dialog-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-tag {
  align-self: flex-start; padding: 3px 10px; border-radius: 999px;
  background: var(--tint); color: var(--dark); font-size: 12px; font-weight: 700;
}
.dialog-body label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.dialog-body .field { font-weight: 400; }
.article-fields { display: flex; flex-direction: column; gap: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row .grow { flex: 1; min-width: 0; }
.field-row .year { width: 110px; flex: none; }
.dialog-body [name="title"] { font-size: 17px; font-weight: 700; color: var(--dark); }
.optional { font-weight: 400; }
.counter { margin: 0; font-size: 12.5px; color: var(--muted); }
.dialog-actions { display: flex; align-items: center; gap: 8px 12px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.dialog-actions .delete { margin-right: auto; padding: 0 4px; }
.saves-hint { font-size: 13px; color: var(--muted); }

/* The note, with its formatting buttons */
.note-field { display: flex; flex-direction: column; gap: 6px; }
.note-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.note-head label { font-size: 13px; font-weight: 600; color: var(--muted); }
.format-bar { display: flex; gap: 4px; }
.format-bar button {
  min-width: 36px; height: 32px; padding: 0 10px; border: 0; border-radius: 8px;
  background: var(--tint); color: var(--dark); font-size: 14px;
}
.format-bar button:hover { filter: brightness(.96); }
.note-preview { padding: 10px 12px; border-radius: 10px; background: var(--tint); }
.note-preview-label { margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--dark); }
.note-preview .card-why { color: var(--dark); }

/* Questions ("Delete this card?", restoring) */
.ask { padding: 20px; width: min(400px, calc(100vw - 32px)); line-height: 1.45; }
.ask-title { margin: 0 0 8px; font-size: 19px; font-weight: 700; }
.ask p { margin: 0 0 14px; color: #3C4050; }

/* ---------- Version, and "Version 2.8 ready · Reload" (as in the planner) ---------- */
/* Version and "What's new", at the bottom of the board */
.version-line { margin: 4px auto 0; max-width: 640px; font-size: 12.5px; color: var(--muted); }
.version-line summary { text-align: center; cursor: pointer; }
.version-line .change { margin-top: 10px; padding: 10px 14px; border-radius: 12px; background: var(--card); color: var(--ink); }
.version-line ul { margin: 4px 0 0; padding-left: 18px; line-height: 1.45; }
.update-bar {
  position: fixed; z-index: 70; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--card); box-shadow: var(--card-edge), 0 8px 24px rgba(31, 34, 48, .2);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.update-bar .btn { min-height: 36px; padding: 0 16px; border-radius: 999px; }

/* ---------- Narrower windows: sections stack instead of squeezing ---------- */
@media (max-width: 900px) {
  #app { padding: 16px; }
  .sections { grid-template-columns: minmax(0, 1fr); }
  .tray .card { width: 100%; }
}
