/* AfterThought — a quiet reading desk.
   Neutrals are tinted slightly green-grey. Colour is rare and meaningful:
   pastel = category flavour, signal (amber) = needs your attention. */
:root {
  --bg: #f2f3ef; --well: #e6e8e1; --card: #fbfbf8; --text: #23262b; --muted: #6a6f76; --line: #d3d6ce;
  --chip: #eceee7; --btn: #2a2d33; --btn-text: #f6f6f2; --danger: #b8323f; --signal: #b8530a;
  --p0: #fbd5c4; --p1: #c9ebd9; --p2: #cfe0f6; --p3: #e2d6f6; --p4: #f6ecb8; --p5: #f7cfdc;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
}
[data-theme='dark'] {
  --bg: #131518; --well: #1a1d21; --card: #22262b; --text: #e6e7e3; --muted: #959aa2; --line: #31353c;
  --chip: #2b2f35; --btn: #3b4048; --btn-text: #f1f1ed; --danger: #ff8e99; --signal: #f0a35e;
  --p0: #5a403a; --p1: #33503f; --p2: #384a66; --p3: #483f66; --p4: #565034; --p5: #5a3a49;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
.grow { flex: 1; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; transition: background .15s, border-color .15s, color .15s; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
button.primary { background: var(--btn); color: var(--btn-text); border-color: var(--btn); font-weight: 600; }
button.primary:hover { border-color: var(--btn); filter: brightness(1.15); }
button.dark { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--danger); }
button.active { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
button.signal { background: var(--signal); color: #fff; border-color: var(--signal); font-weight: 600; }
[data-theme='dark'] button.signal { color: #1d1409; }
input, textarea, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus, textarea:focus { outline: 2px solid var(--text); outline-offset: -1px; }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; }
#loginForm { width: min(340px, 90vw); display: grid; gap: 10px; background: var(--card); padding: 30px; border-radius: 16px; border: 1px solid var(--line); }
#loginForm h1 { margin: 0; font: italic 600 34px/1 var(--serif); letter-spacing: -.01em; }
#loginForm p { margin: 0 0 6px; }

/* shell */
header { display: flex; gap: 8px; align-items: center; padding: 16px clamp(14px, 3vw, 32px) 0; }
.brand { font: italic 600 27px/1 var(--serif); text-decoration: none; letter-spacing: -.01em; }
main { max-width: 1200px; margin: 0 auto; padding: 8px clamp(14px, 3vw, 32px) 70px; }
main.reader { max-width: none; padding: 0; margin-top: 10px; }

/* categories */
.cats { display: flex; justify-content: center; gap: 14px; padding: 12px 4px 30px; overflow-x: auto; scrollbar-width: thin; }
/* the label is the container; the shape is only a small accent behind it, and long names may spill past it */
.cat { flex: none; width: 116px; min-height: 86px; border: 0; background: transparent; border-radius: 10px; display: grid; grid-template-rows: auto auto; place-items: center; align-content: center; padding: 6px 4px; font-size: 13px; font-weight: 500; line-height: 1.2; color: var(--text); text-align: center; position: relative; }
.cat:hover { background: transparent; }
.cat .shape { grid-area: 1 / 1; width: 79px; height: 73px; background: var(--well); transition: filter .25s var(--ease), transform .25s var(--ease); pointer-events: none; }
.cat .name { grid-area: 1 / 1; position: relative; z-index: 1; overflow-wrap: anywhere; max-width: 100%; }
.cat small { grid-row: 2; margin-top: 3px; font-size: 11px; color: var(--muted); font-weight: 400; }
.cat:hover .shape, .cat:focus-visible .shape { filter: saturate(1.4) brightness(.97); transform: scale(1.12) rotate(-3deg); }
.cat.on .shape { filter: saturate(1.9) brightness(.93); transform: scale(1.08); }
.cat.on .name { font-weight: 700; }
.shape.s0 { background: var(--p0); } .shape.s1 { background: var(--p1); } .shape.s2 { background: var(--p2); }
.shape.s3 { background: var(--p3); } .shape.s4 { background: var(--p4); } .shape.s5 { background: var(--p5); }
/* a family of calm, angular shapes */
.shape.s0 { clip-path: polygon(25% 3%, 75% 3%, 99% 50%, 75% 97%, 25% 97%, 1% 50%); }                   /* hexagon */
.shape.s1 { clip-path: polygon(6% 10%, 94% 0, 100% 90%, 0 100%); }                                      /* tilted rectangle */
.shape.s2 { clip-path: polygon(30% 0, 70% 0, 100% 28%, 100% 72%, 70% 100%, 30% 100%, 0 72%, 0 28%); } /* octagon */
.shape.s3 { clip-path: polygon(14% 0, 100% 0, 86% 100%, 0 100%); }                                      /* parallelogram */
.shape.s4 { clip-path: polygon(50% 0, 100% 30%, 100% 78%, 50% 100%, 0 78%, 0 30%); }                    /* pointed hexagon */
.shape.s5 { clip-path: polygon(0 0, 88% 0, 100% 24%, 100% 100%, 12% 100%, 0 76%); }                     /* notched rectangle */

/* top strip: reminders that are due, or top / random picks */
.hero { background: var(--well); border-radius: 18px; padding: 14px 18px 16px; height: 240px; display: flex; flex-direction: column; gap: 12px; }
.hero.collapsed { height: auto; padding-bottom: 12px; }
.hero-head { display: flex; align-items: baseline; gap: 12px; min-height: 28px; }
.hero-head h3 { margin: 0; font: 600 20px/1.1 var(--serif); }
.hero-head .sub { color: var(--muted); font-size: 13px; }
.hero-head button { align-self: center; padding: 3px 11px; font-size: 13px; }
.hero-row { flex: 1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; min-height: 0; }
.hcard { background: var(--card); border-radius: 12px; padding: 10px; display: flex; gap: 12px; min-width: 0; }
.hcard .thumb { flex: none; width: 96px; height: 100%; max-height: 112px; }
.hcard .hb { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.hcard .ctitle { font-size: 16px; -webkit-line-clamp: 3; margin: 0; }
.hcard .cmeta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hact { margin-top: auto; display: flex; flex-wrap: wrap; gap: 5px; }
.hact button { padding: 3px 11px; font-size: 13px; }
.hact a { text-decoration: none; }

/* add box */
.addbox { display: flex; gap: 8px; justify-content: center; margin: 30px auto; max-width: 780px; }
.addbox textarea { flex: 1; resize: none; height: 42px; text-align: center; transition: height .25s var(--ease); }
.addbox textarea:focus { height: 100px; text-align: left; }
.addbox select { align-self: flex-start; height: 42px; max-width: 150px; color: var(--muted); }
.addbox button { align-self: flex-start; height: 42px; padding: 0 20px; }

/* main panel */
.panel { background: var(--well); border-radius: 18px; padding: clamp(14px, 2vw, 22px) clamp(14px, 2.2vw, 24px) 26px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 20px; }
.toolbar .left { display: flex; gap: 8px; flex: 1 1 280px; }
.toolbar .left input { flex: 1; min-width: 0; max-width: 300px; }
.toolbar .left select { max-width: 150px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 5px 14px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.tiers { display: flex; gap: 8px; flex: 1 1 280px; justify-content: flex-end; }
.tiers label { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 8px; cursor: pointer; user-select: none; background: var(--btn); color: var(--btn-text); transition: background .15s, color .15s; }
.tiers label:has(input:not(:checked)) { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.tiers.off label { opacity: .45; pointer-events: none; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: 12px; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.thumb { display: block; border-radius: 8px; overflow: hidden; background: var(--chip); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* no image: fall back to a pastel tile in the colour of the article's first category */
.thumb.ph { display: grid; place-items: center; color: color-mix(in srgb, var(--text) 55%, transparent); font: italic 500 34px/1 var(--serif); text-decoration: none; background: var(--chip); }
.thumb.ph.c0 { background: var(--p0); } .thumb.ph.c1 { background: var(--p1); } .thumb.ph.c2 { background: var(--p2); }
.thumb.ph.c3 { background: var(--p3); } .thumb.ph.c4 { background: var(--p4); } .thumb.ph.c5 { background: var(--p5); }
.card .thumb { aspect-ratio: 16 / 10; }
.ctitle { font: 600 19px/1.22 var(--serif); letter-spacing: -.003em; text-decoration: none; margin-top: 4px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ctitle:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.cmeta { color: var(--muted); font-size: 13px; }
.excerpt { color: var(--muted); font-size: 13.5px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { background: var(--chip); border: 0; border-radius: 99px; padding: 0 9px; font-size: 12px; color: var(--text); }
.chip:hover { background: var(--line); }
.chip.tag::before { content: '#'; opacity: .55; }
.chip.when { color: var(--signal); font-weight: 600; }
.cbar { margin-top: auto; padding-top: 6px; display: flex; align-items: center; gap: 2px; border-top: 1px solid var(--line); }
.cbar button { border: 0; background: transparent; color: var(--muted); padding: 2px 8px; font-size: 14px; border-radius: 6px; }
.cbar button:hover:not(:disabled) { background: var(--chip); color: var(--text); }
.tierbadge { font-size: 12px; color: var(--muted); padding: 0 6px 0 2px; }
/* secondary actions appear on hover/focus (always visible on touch) */
.cbar .act { opacity: 0; transition: opacity .15s; }
.card:hover .cbar .act, .card:focus-within .cbar .act { opacity: 1; }
@media (hover: none) { .cbar .act { opacity: 1; } }
.pending { color: var(--muted); font-style: italic; }
.failed { color: var(--danger); }
.empty { grid-column: 1 / -1; padding: 56px 10px; max-width: 460px; margin: 0 auto; text-align: center; color: var(--muted); }
.empty strong { display: block; font: 600 22px/1.2 var(--serif); color: var(--text); margin-bottom: 6px; }

/* one entrance when the list first appears */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.grid.enter .card { animation: rise .6s var(--ease) both; animation-delay: calc(min(var(--i, 0), 9) * 45ms); }
@media (prefers-reduced-motion: reduce) { .grid.enter .card { animation: none; } * { transition-duration: .01ms !important; } }

/* popup menu */
.menu { position: absolute; z-index: 20; min-width: 200px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 5px; box-shadow: 0 10px 30px -8px rgba(20, 22, 26, .28); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; }
.menu button:hover { background: var(--chip); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); padding: 22px; width: min(520px, 94vw); max-height: 88vh; overflow: auto; }
dialog::backdrop { background: rgba(20, 22, 26, .45); }
dialog h3 { margin: 0 0 12px; font: 600 22px/1.2 var(--serif); }
dialog h4 { margin: 18px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
dialog .row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
dialog .row input { flex: 1; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
dialog code { display: block; padding: 8px; background: var(--chip); border-radius: 8px; overflow-wrap: anywhere; user-select: all; }
dialog .inline { display: flex; gap: 8px; }
dialog .inline > * { flex: 1; min-width: 0; }
dialog .setlist { display: grid; gap: 8px; }
dialog .setlist button { text-align: left; padding: 10px 14px; }
dialog > form > input[name=title] { width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; gap: 8px; align-items: center; padding: 4px 12px 4px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--chip); cursor: pointer; user-select: none; transition: background .15s, border-color .15s; }
.checks label:hover { border-color: var(--muted); }
.checks label:has(input:checked) { background: var(--card); border-color: var(--text); }

/* custom checkbox (neutral on purpose) */
input[type=checkbox] { appearance: none; -webkit-appearance: none; flex: none; width: 18px; height: 18px; margin: 0; padding: 0; display: inline-grid; place-content: center; border: 1.5px solid var(--muted); border-radius: 6px; background: var(--card); cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s; }
input[type=checkbox]:hover { border-color: var(--text); }
input[type=checkbox]::after { content: ''; width: 9px; height: 5px; margin-top: -2px; border-left: 2px solid var(--btn-text); border-bottom: 2px solid var(--btn-text); border-radius: 1px; transform: rotate(-45deg) scale(0); transition: transform .15s var(--ease); }
input[type=checkbox]:checked { background: var(--btn); border-color: var(--btn); }
input[type=checkbox]:checked::after { transform: rotate(-45deg) scale(1); }
input[type=checkbox]:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 25%, transparent); }
.tiers label input[type=checkbox] { border-color: currentColor; background: transparent; }
.tiers label input[type=checkbox]:checked { background: var(--btn-text); border-color: var(--btn-text); }
.tiers label input[type=checkbox]:checked::after { border-color: var(--btn); }

/* reader */
.readerbar { position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px clamp(10px, 2vw, 22px); background: var(--bg); border-bottom: 1px solid var(--line); }
.readerbar a { text-decoration: none; }
.readerbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#frame { display: block; width: 100%; height: calc(100vh - 100px); border: 0; background: var(--bg); }
#frame.html { background: #fff; }
.reader-empty { padding: 60px 20px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { height: auto; }
  .hero-row { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .hcard { flex: none; width: 310px; min-height: 112px; }
}
@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .cats { justify-content: flex-start; gap: 6px; }
  .cat { width: 92px; min-height: 76px; font-size: 12px; }
  .cat .shape { width: 68px; height: 62px; }
  .addbox { flex-wrap: wrap; }
  .addbox textarea { flex-basis: 100%; }
}
