:root {
  --bg: #fff; --card: #fff; --ink: #1c1c1c; --muted: #666; --line: #e5e5e5;
  --accent: #8a1c2e; --on-accent: #fff; --band: #6d1424; --band-ink: #f8ecd9; --gold: #8c6914;
  --mask: #333; --on-mask: #ddd; --hint: #ffd675;
  --shadow: 0 0 0 1px #e5e5e5, 0 6px 18px rgb(0 0 0 / .06);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #121212; --card: #1e1e1e; --ink: #eee; --muted: #a8a8a8; --line: #333;
  --accent: #e8a0ab; --on-accent: #2b0d13; --band: #4f0f1c; --gold: #e0bd6c;
  --mask: #3d3d3d; --on-mask: #ccc;
  --shadow: 0 0 0 1px #2c2c2c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

header { background: var(--band); color: var(--band-ink); border-bottom: 3px solid #c9a24a; }
.bar { max-width: 1120px; margin: auto; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px 28px; }
.brand { display: flex; align-items: center; gap: 12px; }
.seal { display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid #c9a24a; border-radius: 50%; color: #e6c777; font: 1.5rem var(--serif); }
h1 { margin: 0; font: 600 1.75rem/1.1 var(--serif); letter-spacing: .01em; color: #fff; }
.brand p { margin: 0; font-size: .8rem; opacity: .8; }
nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: .95rem; }
.nav-label { margin-right: 6px; opacity: .75; font-size: .85rem; }
.nav-sep { width: 1px; height: 22px; margin: 0 8px; background: rgb(255 255 255 / .3); }
nav a { padding: 5px 12px; border-radius: 6px; color: inherit; text-decoration: none; }
nav a:hover { background: rgb(255 255 255 / .12); }
nav a[aria-current] { background: #f8ecd9; color: #6d1424; font-weight: 600; }
#theme { width: 34px; height: 34px; margin-left: 8px; padding: 0; background: transparent; border: 1px solid rgb(255 255 255 / .4); border-radius: 50%; font-size: 1rem; line-height: 1; }
#stats-link { display: grid; place-items: center; width: 34px; height: 34px; margin-left: 8px; padding: 0; border: 1px solid rgb(255 255 255 / .4); border-radius: 50%; font-weight: 600; }
#stats-link + #theme { margin-left: 4px; }
#theme:hover { background: rgb(255 255 255 / .12); filter: none; }

.layout { max-width: 1120px; margin: auto; padding: 28px 20px 56px; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; align-items: start; }
main { min-width: 0; }

#puzzle { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
#puzzle-label { font: 600 1.7rem/1.2 var(--serif); }
#new-puzzle { flex: none; padding: 7px 14px; font-size: .9rem; color: var(--ink); background: transparent; border: 1px solid var(--muted); }
#new-puzzle:hover { background: var(--line); filter: none; }

.controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
select { padding: 7px 8px; max-width: 100%; font: .9rem var(--sans); color: var(--ink); background: var(--card); border: 1px solid var(--muted); border-radius: 8px; }
#subject[hidden] { display: none; }
#text-choice { flex: none; max-width: 45%; border: 0; border-right: 1px solid var(--line); border-radius: 0; }
#text-choice[hidden] { display: none; }
#stats { margin: 0 0 8px; color: var(--gold); font-size: .9rem; font-weight: 600; }
#stats:empty { display: none; }

#how, #yesterday { margin-bottom: 6px; color: var(--muted); font-size: .9rem; }
#yesterday { margin-bottom: 16px; }
#how summary, #yesterday summary { cursor: pointer; width: fit-content; }
#rules, #yesterday-answer { margin: 6px 0 0; }

#extras:empty { display: none; }
#extras { margin: 0 0 14px; }
.hint-list { margin: 0 0 8px; padding-left: 20px; }
.secondary { padding: 7px 14px; font-size: .9rem; color: var(--ink); background: transparent; border: 1px solid var(--muted); }
.secondary:hover { background: var(--line); filter: none; }
.share { margin-bottom: 10px; }
.card { padding: 14px 18px; background: var(--card); border-left: 4px solid var(--gold); border-radius: 8px; box-shadow: var(--shadow); font-size: .95rem; }
.card p { margin: 0 0 6px; }
.card p:last-child { margin-bottom: 0; }
.card .matiere { color: var(--gold); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.card .credit { color: var(--muted); font-size: .8rem; }
.quote { margin-bottom: 12px; padding: 18px 24px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); font-size: 1.25rem; }
.share-text { margin: 0 0 10px; padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; font-size: .85rem; }

form { display: flex; gap: 6px; padding: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
form:focus-within { outline: 3px solid var(--gold); outline-offset: 1px; }
input:focus-visible { outline: 0; }
input { flex: 1; min-width: 0; padding: 10px 12px; font: 1.1rem var(--sans); color: inherit; background: transparent; border: 0; outline: 0; }
input::placeholder { color: var(--muted); }
button { padding: 10px 20px; font: 600 1rem var(--sans); color: var(--on-accent); background: var(--accent); border: 0; border-radius: 8px; cursor: pointer; transition: filter .15s; }
button:hover { filter: brightness(1.12); }

#key-hint { margin: 8px 2px 0; color: var(--muted); font-size: .8rem; }
kbd { padding: 0 5px; background: var(--card); border: 1px solid var(--line); border-radius: 4px; font: inherit; }
#message { min-height: 1.55em; margin: 12px 2px; color: var(--muted); }
#message.win { padding: 10px 14px; background: var(--card); border-left: 4px solid var(--gold); border-radius: 6px; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: right; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
th:first-child, td:first-child { text-align: left; font-weight: 600; overflow-wrap: anywhere; }
th:last-child, td:last-child { width: 36%; }
td { font-variant-numeric: tabular-nums; }
tr.last td { background: color-mix(in srgb, var(--gold) 14%, transparent); }
.temp { display: inline-block; padding: 1px 8px; background: color-mix(in srgb, hsl(var(--hue) 80% 50%) 22%, transparent); border-radius: 20px; white-space: nowrap; }
.progress { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.progress i { flex: 1; min-width: 20px; height: 8px; overflow: hidden; background: var(--line); border-radius: 4px; }
.progress i::after { content: ''; display: block; width: var(--value); height: 100%; background: linear-gradient(90deg, #d98a2b, #c2202f); border-radius: 4px; }

#game > h2 { margin: 4px 0 12px; font: 600 1.5rem/1.8 var(--serif); }
.article { padding: 18px 24px; overflow-wrap: anywhere; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); font: 1.05rem/1.9 var(--serif); }
.article p { margin: 0 0 12px; }
.article p:last-child { margin-bottom: 0; }
#game > p { color: var(--muted); font-size: .85rem; }
.mask { display: inline-block; padding: 0 4px; vertical-align: baseline; background: var(--mask); border-radius: 4px; color: var(--on-mask); font: .7em/1.75em var(--sans); text-align: center; white-space: nowrap; }
.mask.close { color: var(--hint); font-style: italic; }
.just { background: color-mix(in srgb, var(--gold) 35%, transparent); border-radius: 3px; }

aside { position: sticky; top: 20px; padding: 22px 24px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); font-size: .9rem; line-height: 1.5; }
aside h2 { margin: 0 0 8px; color: var(--gold); font-size: .75rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
blockquote { margin: 0; font: italic 1.15rem/1.45 var(--serif); }
#citation-source { margin: 10px 0 14px; color: var(--muted); font-size: .85rem; }
#citation-matiere { display: inline-block; margin: 0 0 14px; padding: 2px 12px; background: var(--accent); border-radius: 20px; color: var(--on-accent); font-size: .8rem; font-weight: 600; }
.use-label { margin: 0; color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
#citation-use { margin: 2px 0 14px; }
#citation-check { margin: 0; padding-top: 12px; border-top: 1px solid var(--line); }
#citation-date { margin: 4px 0 0; color: var(--muted); font-size: .78rem; }

footer { max-width: 1120px; margin: auto; padding: 0 20px 28px; font-size: .85rem; }
.page { max-width: 720px; margin: auto; padding: 32px 20px 56px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.tile strong { display: block; color: var(--accent); font: 600 1.8rem/1.2 var(--serif); }
.tile span { color: var(--muted); font-size: .85rem; }
.note { color: var(--muted); font-size: .85rem; }
.page h1 { color: var(--ink); }
.page h2 { margin-top: 28px; font: 600 1.2rem var(--serif); }

.celebrate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow: hidden; pointer-events: none; }
.stamp { padding: 8px 24px; border: 5px double #b3202f; border-radius: 8px; background: rgb(255 253 247 / .94); color: #b3202f; font: 700 clamp(1.6rem, 7vw, 3rem) var(--serif); letter-spacing: .06em; text-transform: uppercase; animation: stamp 2.2s ease-out both; }
.piece { position: absolute; top: 50%; left: 50%; width: 9px; height: 14px; border-radius: 2px; animation: burst 1.6s ease-out both; }
@keyframes stamp {
  0% { opacity: 0; transform: rotate(-8deg) scale(2.6); }
  14% { opacity: 1; transform: rotate(-8deg) scale(1); }
  20% { transform: rotate(-8deg) scale(1.06); }
  26%, 80% { opacity: 1; transform: rotate(-8deg) scale(1); }
  100% { opacity: 0; transform: rotate(-8deg) scale(1); }
}
@keyframes burst {
  from { opacity: 1; transform: translate(-50%, -50%); }
  to { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--turn)); }
}
@media (prefers-reduced-motion: reduce) { .celebrate { display: none; } }

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 20px 16px 40px; }
  .bar { padding: 12px 16px; }
  aside { position: static; }
  th, td { padding: 8px 10px; }
  th:last-child, td:last-child { width: 32%; }
  .article { padding: 14px 16px; }
}
@media (hover: none) { #key-hint { display: none; } }
