/* ============================================================================
   Quotes — stylesheet
   Palette: "glacier morning" — cool blue-grey paper, deep ink, a marigold
   site accent. Each card carries its own --accent set inline per quote.
   Type: Fraunces / IBM Plex Mono / Caveat / Sora for quotes (per-card),
   Space Grotesk for everything utilitarian.
   ========================================================================== */

:root {
  --bg: #e7edf5;
  --ink: #1e2733;
  --muted: #5c6877;
  --surface: #fcfdfe;
  --line: #c9d4e2;
  --marigold: #e29a2e;
  --marigold-deep: #b27416;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(30, 39, 51, 0.06), 0 4px 14px rgba(30, 39, 51, 0.07);
  --shadow-lg: 0 2px 4px rgba(30, 39, 51, 0.08), 0 14px 34px rgba(30, 39, 51, 0.14);
  --font-ui: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-serif: 'Fraunces', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
  --font-hand: 'Caveat', 'Comic Sans MS', cursive;
  --font-sans: 'Sora', system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 88% -6%, rgba(226, 154, 46, 0.16) 0%, transparent 62%),
    radial-gradient(900px 620px at -12% 8%, rgba(122, 156, 198, 0.22) 0%, transparent 58%),
    var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--marigold); color: var(--ink); }

a { color: var(--marigold-deep); }

/* ----------------------------------------------------------- a11y bits */

:focus-visible {
  outline: 3px solid var(--marigold);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 10px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* Honeypot — parked far off screen, never display:none (some bots check). */
.hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --------------------------------------------------------------- header */

.site-header {
  max-width: 1280px;
  margin: 0 auto;
  padding: 3.4rem 1.25rem 0.8rem;
}

.kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--marigold-deep);
}

.site-header h1 {
  margin: 0.3rem 0 0.45rem;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(3.1rem, 9vw, 5.4rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

/* -------------------------------------------------------------- controls */

.controls {
  max-width: 1280px;
  margin: 1.4rem auto 0.4rem;
  padding: 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.toolbar {
  display: flex;
  flex: 1 1 280px;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.toolbar input[type='search'] {
  flex: 1 1 180px;
  min-width: 0;
  padding: 0.62rem 0.95rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
}

.toolbar select {
  padding: 0.62rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

/* The no-JS fallback submit button disappears once app.js takes over. */
html.js .js-hide { display: none; }

.noscript-note {
  flex-basis: 100%;
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* -------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  border-radius: 999px;
  padding: 0.68rem 1.25rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn.primary {
  background: var(--marigold);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: #ecaa44; transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn.primary:active { transform: translateY(0); }

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn.ghost:hover { border-color: var(--ink); }

.icon-btn {
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: rgba(30, 39, 51, 0.06); }

/* The add button becomes a floating pill on phones. */
@media (max-width: 639px) {
  #open-add {
    position: fixed;
    right: 1.05rem;
    bottom: 1.15rem;
    z-index: 40;
    box-shadow: var(--shadow-lg);
  }
}

/* ----------------------------------------------------------------- cards */

.cards {
  max-width: 1280px;
  margin: 0.8rem auto 0;
  /* Generous bottom padding keeps the floating add button off the last card. */
  padding: 0.5rem 1.25rem 6rem;
  columns: 1;
  column-gap: 1.1rem;
}

@media (min-width: 640px)  { .cards { columns: 2; } }
@media (min-width: 1024px) { .cards { columns: 3; } }
@media (min-width: 1480px) { .cards { columns: 4; } }

.card {
  --accent: #2c6e6a;
  display: block;
  break-inside: avoid;
  background: var(--surface);
  border: 1px solid rgba(201, 212, 226, 0.6);
  border-radius: var(--radius);
  padding: 1.35rem 1.3rem 1.15rem;
  margin: 0 0 1.1rem;
  box-shadow: var(--shadow-sm);
  transform: rotate(var(--tilt, 0deg));
  transition: opacity 0.55s ease, transform 0.55s ease, box-shadow 0.25s ease;
}

/* A few cards sit ever so slightly askew, like pinned notes. */
.cards > .card:nth-child(5n + 2) { --tilt: 0.4deg; }
.cards > .card:nth-child(7n + 4) { --tilt: -0.45deg; }

.card:hover {
  transform: translateY(-3px) rotate(0deg);
  box-shadow: var(--shadow-lg);
}

/* Reveal-on-scroll: only when JS is around to add .in, never for reduced motion. */
html.js .cards > .card:not(.in) {
  opacity: 0;
  transform: translateY(16px) rotate(var(--tilt, 0deg));
}

/* Oversized opening quote mark in the card's own accent. */
.card::before {
  content: '\201C';
  display: block;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 2.7rem;
  line-height: 0.55;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.card[data-align='center'] { text-align: center; }

.card-text {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.card[data-font='serif'] .card-text {
  font-family: var(--font-serif);
  font-size: 1.18rem;
  line-height: 1.5;
  font-weight: 500;
}
.card[data-font='mono'] .card-text {
  font-family: var(--font-mono);
  font-size: 0.98rem;
  line-height: 1.6;
}
.card[data-font='handwritten'] .card-text {
  font-family: var(--font-hand);
  font-size: 1.55rem;
  line-height: 1.25;
  font-weight: 500;
}
.card[data-font='sans'] .card-text {
  font-family: var(--font-sans);
  font-size: 1.06rem;
  line-height: 1.55;
}

/* Background variants */
.card[data-bg='gradient'] {
  background: linear-gradient(
    158deg,
    color-mix(in srgb, var(--accent) 15%, #ffffff) 0%,
    var(--surface) 62%
  );
}

.card[data-bg='paper'] {
  background-color: #faf6ed;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  border-color: rgba(190, 175, 140, 0.45);
}

/* Solid: the whole card is the accent colour. --fg is a readable near-black
   or white picked per quote (see util.contrastText) so text always contrasts. */
.card[data-bg='solid'] {
  background: var(--accent);
  color: var(--fg, #fff);
  border-color: transparent;
}
.card[data-bg='solid']::before { color: var(--fg, #fff); opacity: 0.5; }
.card[data-bg='solid'] .card-text,
.card[data-bg='solid'] .card-author b { color: var(--fg, #fff); }
.card[data-bg='solid'] .card-context,
.card[data-bg='solid'] .card-meta,
.card[data-bg='solid'] .card-addedby {
  color: var(--fg, #fff);
  opacity: 0.82;
}

.card-context {
  margin: 0.55rem 0 0;
  font-size: 0.84rem;
  font-style: italic;
  color: var(--muted);
}

.card-meta {
  margin: 0.85rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.card-author b {
  color: var(--ink);
  font-weight: 700;
}

.card-addedby {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  opacity: 0.8;
}

/* ------------------------------------------------------------ empty state */

.empty {
  column-span: all;
  text-align: center;
  padding: 4.2rem 1.5rem;
  max-width: 34rem;
  margin: 0 auto;
}

.empty h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: 2.1rem;
}

.empty p { color: var(--muted); margin: 0.7rem 0 1.3rem; }

.empty-line {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1.25rem;
  margin: 0;
}

/* ---------------------------------------------------------------- dialog */

#add-dialog {
  border: none;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  margin: auto 0 0;
  border-radius: 22px 22px 0 0;
  max-height: 93dvh;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 640px) {
  #add-dialog {
    margin: auto;
    width: min(640px, calc(100vw - 3rem));
    border-radius: 22px;
  }
}

#add-dialog::backdrop {
  background: rgba(20, 27, 38, 0.5);
  backdrop-filter: blur(2px);
}

#add-form { padding: 1.3rem 1.4rem 1.5rem; }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: 1.7rem;
}

.field { margin-bottom: 0.9rem; min-width: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 0.9rem;
}
@media (min-width: 520px) {
  .field-row { grid-template-columns: 1fr 1fr; }
}

.field > label,
.mini-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 0.35rem;
}

.req, .opt {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0;
}
.req { color: var(--marigold-deep); }

.field input[type='text'],
.field input[type='search'],
.field input[type='date'],
.field input:not([type]),
.field textarea {
  width: 100%;
  padding: 0.62rem 0.8rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}

.field textarea { resize: vertical; min-height: 4.2rem; }

.field select {
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.55rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}
.check input { accent-color: var(--marigold-deep); }

.style-fieldset {
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  padding: 0.9rem 0.95rem 0.2rem;
  margin: 0 0 1rem;
}

.style-fieldset legend {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 0.4rem;
}

/* Segmented radio chips */
.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.segmented label { cursor: pointer; }
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: inline-block;
  padding: 0.42rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: #fff;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.segmented input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.segmented input:focus-visible + span {
  outline: 3px solid var(--marigold);
  outline-offset: 2px;
}

/* Accent swatches */
.swatches { display: flex; align-items: center; flex-wrap: wrap; gap: 0.55rem; }
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px var(--line);
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 3px var(--ink); }
.swatches input[type='color'] {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.preview-label {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.preview-card { margin-bottom: 1rem; cursor: default; }
.preview-card:hover { transform: rotate(0deg); box-shadow: var(--shadow-sm); }

.form-error {
  background: #f7e3e0;
  color: #8a2c1d;
  border: 1px solid #e4b8b1;
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-size: 0.88rem;
  margin: 0 0 0.9rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

/* ----------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: 5.6rem;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.15rem;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  max-width: min(90vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
  .card,
  html.js .cards > .card:not(.in) {
    opacity: 1;
    transform: none;
  }
  .card:hover { transform: none; }
}
