/* Aphorisms — a page from an old book: parchment, ink, a little gold. */

:root {
  color-scheme: light dark;
  --bg: #f3ead8;
  --bg-deep: #e9dcc2;
  --card: #fbf6ea;
  --ink: #2a2118;
  --ink-soft: #7a6a55;
  --line: #dccbab;
  --accent: #8b2e1f;      /* oxblood, like a rubricated initial */
  --accent-ink: #fbf6ea;
  --gold: #a8823e;
  --accent-soft: #f1e2c8;
  --danger: #9a2f22;
  --display: "Cormorant Garamond", "Cormorant", "EB Garamond", Garamond, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --caps: "Cormorant SC", "Cormorant Garamond", Garamond, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d;
    --bg-deep: #0d0b08;
    --card: #1d1914;
    --ink: #efe4cc;
    --ink-soft: #a8987c;
    --line: #3a3126;
    --accent: #d4a85a;    /* gold leaf on ink */
    --accent-ink: #14110d;
    --gold: #d4a85a;
    --accent-soft: #2e261a;
    --danger: #e0806c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    var(--paper),
    radial-gradient(ellipse at 50% 30%, var(--bg) 40%, var(--bg-deep) 100%);
  background-attachment: fixed;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
h2 { font-family: var(--display); font-weight: 600; font-size: 1.7rem; margin: 0; letter-spacing: 0.01em; }
h3 {
  font-family: var(--caps); font-weight: 600; font-size: 1rem; letter-spacing: 0.12em;
  color: var(--ink-soft); margin: 1.4rem 0 0.6rem;
}
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
code { font-size: 0.85em; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3em; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.1rem; }
.date {
  flex: 1; text-align: center; font-family: var(--caps); letter-spacing: 0.14em;
  color: var(--ink-soft); font-size: 0.95rem;
}
.icon-btn {
  background: none; border: 0; padding: 0.45rem; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; color: var(--ink-soft);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }
.streak {
  display: inline-flex; align-items: center; gap: 0.25rem; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.25rem 0.7rem 0.25rem 0.5rem; font-family: var(--display); font-weight: 700; font-size: 1.1rem;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}
.streak:hover { border-color: var(--gold); }
.streak .flame { font-size: 1rem; }
.streak[data-cold="true"] .flame { filter: grayscale(1); opacity: 0.5; }
.streak.bump { animation: bump 0.6s ease; }
@keyframes bump { 30% { transform: scale(1.25); } 100% { transform: none; } }

/* ---------- stage & card ---------- */
.stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0.5rem 1.1rem 1.5rem; gap: 1.4rem;
}
.card {
  position: relative; max-width: 42rem; width: 100%;
  background: var(--paper), var(--card);
  padding: 2.4rem 2.6rem 1.6rem;
  border: 1px solid var(--line);
  outline: 1px solid var(--line); outline-offset: -9px;   /* the inner frame line of a printed page */
  box-shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 18px 50px -12px rgba(60, 40, 10, .25);
  animation: rise 0.7s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.ornament { text-align: center; color: var(--gold); font-size: 1.6rem; line-height: 1; margin-bottom: 0.9rem; font-family: var(--display); }
.quote {
  margin: 0; font-family: var(--display); font-style: italic; font-weight: 500;
  font-size: clamp(1.55rem, 1.1rem + 1.9vw, 2.25rem); line-height: 1.32;
  text-wrap: pretty; text-align: center;
}
.quote::before { content: "“"; } .quote::after { content: "”"; }
.quote.long { font-size: clamp(1.2rem, 1rem + 1vw, 1.5rem); text-align: left; line-height: 1.45; }
.quote.long::first-letter {
  float: left; font-style: normal; font-weight: 700; color: var(--accent);
  font-size: 3.4em; line-height: 0.8; padding: 0.08em 0.08em 0 0;
}
.quote.long::before, .quote.long::after { content: none; }
.translation {
  margin: 1rem auto 0; max-width: 34rem; text-align: center;
  font-family: var(--display); font-size: clamp(1.05rem, 0.9rem + 0.8vw, 1.3rem); color: var(--ink-soft); text-wrap: pretty;
}
.translation.pending { opacity: 0.5; }
.rule { display: flex; align-items: center; gap: 0.8rem; color: var(--gold); margin: 1.3rem auto 0.7rem; max-width: 14rem; }
.rule::before, .rule::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.attribution { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.source {
  font-family: var(--caps); font-weight: 600; font-size: 1.25rem; letter-spacing: 0.08em;
  color: var(--ink); text-decoration: none;
}
.source[href]:hover { color: var(--accent); }
.source::before { content: "— "; color: var(--gold); }
.cite { color: var(--ink-soft); font-family: var(--display); font-style: italic; font-size: 0.98rem; }
.community { text-align: center; margin: 0.6rem 0 0; font-size: 0.82rem; color: var(--ink-soft); }
.community b { color: var(--accent); font-weight: 600; }

.discover {
  margin: 1rem 0 0; padding: 0.55rem 0.8rem; border-radius: 6px;
  background: var(--accent-soft); font-size: 0.85rem;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem 0.8rem;
}
.discover::before { content: "✨"; }
.discover span { flex: 1; min-width: 12rem; }

/* faces */
.rate { margin-top: 1.1rem; padding-top: 0.8rem; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.3rem 1rem; }
.rate-label { font-family: var(--display); font-style: italic; color: var(--ink-soft); font-size: 1rem; }
.faces { display: inline-flex; gap: 0.4rem; }
.face {
  background: none; border: 0; cursor: pointer; padding: 0.1rem; line-height: 0; border-radius: 50%;
  color: var(--ink-soft); opacity: 0.55; transition: transform .12s, color .15s, opacity .15s;
}
.face svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.face svg .eye { fill: currentColor; stroke: none; }
.face:hover { transform: scale(1.12); opacity: 1; }
.face[aria-checked="true"] { color: var(--accent); opacity: 1; }
.face[aria-checked="true"] svg circle:first-child { fill: var(--accent-soft); }
.face.pop { animation: bump .5s ease; }

/* ---------- the seal ritual ---------- */
.seal {
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  background: none; border: 0; cursor: pointer; padding: 2rem; animation: rise .8s ease both;
}
.seal-disc {
  width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: 3rem; color: #f6d9c9;
  background: radial-gradient(circle at 35% 30%, #c0503c, #8b2e1f 55%, #5e1a10);
  box-shadow: inset 0 0 0 6px rgba(0,0,0,.12), inset 0 0 0 9px rgba(255,255,255,.08), 0 10px 25px -6px rgba(94,26,16,.6);
  transition: transform .2s;
}
.seal:hover .seal-disc { transform: rotate(-6deg) scale(1.04); }
.seal-label { font-family: var(--display); font-style: italic; font-size: 1.6rem; }
.seal-hint { font-family: var(--caps); letter-spacing: .14em; color: var(--ink-soft); font-size: .9rem; }
.seal.breaking .seal-disc { animation: crack .55s ease forwards; }
@keyframes crack { 40% { transform: scale(1.15) rotate(8deg); } 100% { transform: scale(.2) rotate(40deg); opacity: 0; } }

/* ---------- buttons ---------- */
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }
.btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.5rem 1.15rem; cursor: pointer; font-family: var(--display); font-weight: 600; font-size: 1.05rem;
  transition: border-color .15s, background .15s; text-decoration: none; color: var(--ink);
  display: inline-flex; align-items: center;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 0.25rem 0.8rem; font-size: 0.92rem; }
.btn.wide { width: 100%; justify-content: center; margin-top: 1.2rem; padding: 0.7rem; font-size: 1.2rem; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.empty { text-align: center; color: var(--ink-soft); font-family: var(--display); font-style: italic; font-size: 1.2rem; }
.status { text-align: center; font-size: 0.8rem; color: var(--ink-soft); margin: 0; padding: 0 1rem; min-height: 1.2rem; }

/* toast (XP, badges) */
.toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 0.6rem 1.1rem; border-radius: 999px; z-index: 50;
  font-family: var(--display); font-size: 1.05rem; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
  animation: toast-in .35s ease both; max-width: calc(100% - 2rem); text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- library drawer ---------- */
.drawer { max-width: 42rem; width: calc(100% - 2.2rem); margin: 0 auto 0.8rem; }
.drawer summary { cursor: pointer; color: var(--ink-soft); text-align: center; list-style: none; font-family: var(--caps); letter-spacing: .12em; }
.drawer summary::-webkit-details-marker { display: none; }
.drawer summary::before { content: "❧ "; color: var(--gold); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 0.6rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.list .q { font-family: var(--display); font-size: 1.1rem; }
.list .meta { color: var(--ink-soft); font-size: 0.8rem; display: block; margin-top: 0.15rem; font-family: var(--sans); }
.list .x { background: none; border: 0; cursor: pointer; color: var(--ink-soft); align-self: start; }
.list:empty::after { content: "Nothing here yet."; color: var(--ink-soft); font-size: 0.85rem; font-style: italic; }

.foot { display: flex; justify-content: space-between; gap: 1rem; padding: 0.7rem 1.2rem; font-size: 0.75rem; color: var(--ink-soft); }

/* ---------- dialogs ---------- */
.dialog {
  border: 0; padding: 0; background: transparent; width: 100%; max-width: min(40rem, 100%);
  max-height: 90dvh; overflow: hidden; display: flex; flex-direction: column;
}
.dialog:not([open]) { display: none; }
.dialog::backdrop { background: rgba(20, 14, 6, 0.5); backdrop-filter: blur(3px); }
.dialog-inner {
  background: var(--paper), var(--card); color: var(--ink); border-radius: 10px;
  padding: 1.3rem 1.5rem 1.5rem; margin: 0; border: 1px solid var(--line);
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
}
.dialog-head { display: flex; align-items: center; gap: 0.75rem; }
.dialog-head h2 { flex: 1; }
.welcome { text-align: center; }
.welcome .muted { font-family: var(--display); font-size: 1.15rem; }

/* theme cards */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.5rem; text-align: left; }
.theme {
  min-width: 0; display: flex; align-items: center; gap: 0.55rem; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.7rem;
  transition: border-color .15s, background .15s;
}
.theme:hover { border-color: var(--gold); }
.theme[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.theme .icon { font-size: 1.4rem; line-height: 1; flex: none; }
.theme .name { font-family: var(--display); font-weight: 600; font-size: 1.08rem; line-height: 1.15; text-align: left; }

/* collapsible sections */
.section { border-top: 1px solid var(--line); margin-top: 1rem; }
.section > summary {
  cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.85rem 0 0.4rem; font-family: var(--caps); letter-spacing: .1em; font-weight: 600; font-size: 1.05rem;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary > span:first-child::before { content: "▸ "; color: var(--gold); }
.section[open] > summary > span:first-child::before { content: "▾ "; }
.section > summary .muted { font-family: var(--sans); letter-spacing: 0; font-weight: 400; font-size: .85rem; }

/* authors */
.group { margin-top: 0.9rem; }
.group h4 { margin: 0 0 0.35rem; font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; }
.group-tools { font-size: 0.75rem; margin-left: 0.5rem; }
.group-tools a { cursor: pointer; margin-right: 0.5rem; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 0.4rem; }
.person {
  min-width: 0; position: relative; display: flex; align-items: center; gap: 0.55rem;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.35rem 0.5rem 0.35rem 0.4rem; cursor: pointer; user-select: none;
}
.person:hover { border-color: var(--gold); }
.person input { position: absolute; opacity: 0; pointer-events: none; }
.person:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.person:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.person .text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.person .name { font-size: 0.86rem; font-weight: 600; }
.person .blurb { font-size: 0.7rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 50%; overflow: hidden; background: var(--line);
  display: grid; place-items: center; font: 700 0.75rem var(--display); color: var(--ink-soft);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; filter: sepia(.25); }

/* flags */
.flag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.4rem; }
.flag {
  min-width: 0; position: relative; display: flex; align-items: center; gap: 0.6rem;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.4rem 0.55rem; cursor: pointer; user-select: none;
}
.flag:hover { border-color: var(--gold); }
.flag input { position: absolute; opacity: 0; pointer-events: none; }
.flag:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.flag .art { flex: none; width: 32px; height: 22px; display: grid; place-items: center; }
.flag .art svg { width: 32px; height: 22px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.flag .none { width: 32px; height: 22px; border-radius: 3px; border: 1px dashed var(--ink-soft); display: grid; place-items: center; color: var(--ink-soft); }
.flag .native { font-size: 0.88rem; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag .native::first-letter { text-transform: uppercase; }

/* forms */
.row { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.row.wrap { flex-wrap: wrap; }
input[type="text"], textarea, .field select {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.7rem;
}
input[type="text"], textarea { width: 100%; }
textarea { font-family: var(--display); font-size: 1.1rem; resize: vertical; }
#push-config { font: 0.72rem ui-monospace, Consolas, monospace; }
.stack { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.9rem; }
.field { display: inline-flex; align-items: center; gap: 0.5rem; }
.notice { background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px; padding: 0.7rem 0.9rem; font-size: 0.9rem; }
.bookmarklet { cursor: grab; }
.foot-links { text-align: center; margin: 1.6rem 0 0; }
.foot-links a { color: var(--ink-soft); }
.community-note { text-align: center; margin: 1.2rem 0 0; }

/* ---------- journey ---------- */
.level { text-align: center; margin: 1rem 0 0.5rem; }
.level-name { font-family: var(--display); font-weight: 700; font-size: 2rem; color: var(--accent); }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 0.5rem auto; max-width: 20rem; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: inherit; transition: width .6s ease; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin-top: 1rem; }
.stat { text-align: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.2rem; }
.stat b { display: block; font-family: var(--display); font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: 0.72rem; color: var(--ink-soft); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 15rem; margin: 0 auto; }
.calendar i { aspect-ratio: 1; border-radius: 4px; background: var(--line); opacity: .55; }
.calendar i[data-on="true"] { background: var(--accent); opacity: 1; }
.calendar i[data-today="true"] { outline: 2px solid var(--gold); outline-offset: 1px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.5rem; }
.badge { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem; text-align: center; background: var(--card); }
.badge .b-icon { font-size: 1.7rem; display: block; }
.badge .b-name { font-family: var(--display); font-weight: 700; font-size: 1.02rem; display: block; line-height: 1.15; margin-top: .2rem; }
.badge .b-desc { font-size: 0.72rem; color: var(--ink-soft); }
.badge[data-locked="true"] { opacity: .45; }
.badge[data-locked="true"] .b-icon { filter: grayscale(1); }

@media (max-width: 600px) {
  .card { padding: 1.9rem 1.4rem 1.3rem; outline-offset: -7px; }
  .dialog { max-height: 94dvh; margin-bottom: 0; }
  .dialog-inner { border-radius: 12px 12px 0 0; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
  .theme-grid, .people, .flag-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .person .blurb { white-space: normal; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .top { padding: 0.7rem 0.8rem; gap: 0.5rem; }
  .date { font-size: 0.8rem; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* Cormorant defaults to old-style figures ("1" looks like "I"); counters need lining ones. */
.streak, .stat b, .level, .level-name, .bar + .muted, .badge .b-desc { font-variant-numeric: lining-nums tabular-nums; }
