:root {
  --paper: #F4EFE4; --ink: #1E1B18; --oxblood: #8C2F23; --ink-soft: #5A5349;
  --hairline: #1E1B1855; --tint: #8C2F2314;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .12 0 0 0 0 .1 0 0 0 0 .09 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  --gutter: 16px; --tray-gap: 6px;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1.0625rem/1.5 var(--serif);
  background-image: var(--grain);
}
h1, h2, p, dl, dd, ol, blockquote { margin: 0; padding: 0; }
button, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { color: var(--ink-soft); cursor: default; }
:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 2px; }

.masthead { max-width: 1160px; margin: 0 auto; padding: 14px var(--gutter) 0; }
.wordmark { display: flex; align-items: center; gap: 12px; font-size: clamp(1.75rem, 7.6vw, 2.5rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.wordmark img { flex: none; display: block; width: 1.25em; height: 1.25em; }
.masthead::after { content: ""; display: block; margin-top: 12px; height: 5px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
nav { display: flex; flex-wrap: wrap; align-items: center; column-gap: 18px; margin-top: 6px; }
nav button { min-height: 44px; padding: 0 2px; font-size: 1rem; }
body[data-mode="daily"] #btn-daily, body[data-mode="practice"] #btn-practice { font-weight: 700; color: var(--oxblood); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }
body[data-mode="daily"] #btn-new { display: none; }
.difficulty { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 1rem; color: var(--ink-soft); }
.difficulty span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
select { min-height: 44px; padding: 0 6px; background: transparent; border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; color: var(--ink); }

main { max-width: 1160px; margin: 0 auto; padding: 0 var(--gutter) 40px; }
.slug { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 0; font-style: italic; color: var(--ink-soft); font-size: 1rem; }
.slug-right { display: inline-flex; gap: 16px; font-variant-numeric: tabular-nums; font-style: normal; }
#timer, #hint-count { color: var(--ink); }

#board { container-type: inline-size; --longest: 8; padding: 6px 0 14px; }
.word { display: inline-flex; align-items: flex-end; white-space: nowrap; margin: 0 .55em 10px 0; --cell: min(var(--cap, 32px), calc(100cqi / (var(--longest) + 1))); font-size: 16px; }
.cell { display: grid; grid-template-rows: 32px 16px; width: var(--cell); height: 54px; padding: 0 1px; justify-items: center; align-items: end; border-radius: 0; position: relative; }
.cell::after { content: ""; position: absolute; left: 2px; right: 2px; top: 34px; height: 1px; background: var(--ink); }
.guess, .cipher { grid-column: 1; line-height: 1; }
.cell[data-guess=""] .guess { display: none; }
.cell[data-guess=""] .cipher { grid-row: 1; align-self: end; padding-bottom: 3px; font-size: 25px; font-weight: 600; color: var(--ink); text-shadow: 0 1px 0 #fff8; }
.cell:not([data-guess=""]) .guess { grid-row: 1; align-self: end; padding-bottom: 3px; font-size: 25px; font-weight: 700; color: var(--oxblood); }
.cell:not([data-guess=""]) .cipher { grid-row: 2; align-self: end; font-size: 12px; color: var(--ink-soft); }
.cell[data-selected] { background: var(--tint); }
.cell[data-selected]::after { height: 3px; background: var(--oxblood); }
.cell[data-conflict] .guess, .cell[data-wrong] .guess { background: var(--oxblood); color: var(--paper) !important; padding: 2px 3px 3px; text-decoration: underline wavy 1px; text-underline-offset: 1px; }
.punct { font-size: 25px; font-weight: 600; line-height: 1; padding-bottom: 22px; }

#tray { position: sticky; bottom: 0; background: var(--paper) var(--grain); border-top: 1px solid var(--hairline); margin-inline: -10px; padding: 0 0 calc(8px + env(safe-area-inset-bottom)); }
#message { min-height: 1.5em; padding-top: 4px; text-align: center; font-style: italic; font-size: .9375rem; color: var(--oxblood); }
#controls { display: grid; grid-template-columns: 1fr auto 1fr 1fr; margin-bottom: 6px; }
#controls button { min-height: 44px; font-size: 1rem; white-space: nowrap; }
#controls button:not(:disabled):hover { color: var(--oxblood); }
#keyboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--tray-gap); }
.key-row { display: contents; }
#keyboard button { height: 46px; min-width: 0; border: 1px solid var(--ink); border-radius: 2px; font-size: 1.125rem; font-weight: 600; box-shadow: inset 0 -2px 0 #1E1B181f; }
#keyboard button:not(:disabled):active { background: var(--ink); color: var(--paper); }
#keyboard button[data-used] { border-color: var(--hairline); color: var(--ink-soft); font-weight: 400; box-shadow: none; }
body:has(#result:not([hidden])) #tray { display: none; }
body:has(#result:not([hidden])) .cell:not([data-guess=""]) .guess { color: var(--ink); }
body:has(#result:not([hidden])) .cell .cipher { display: none; }
body:has(#result:not([hidden])) .cell { height: 38px; }
body:has(#result:not([hidden])) .cell::after { display: none; }
body:has(#result:not([hidden])) .punct { padding-bottom: 6px; }

h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; padding-bottom: 6px; border-bottom: 2px solid var(--oxblood); margin-bottom: 12px; }
#result { padding: 22px 0 8px; scroll-margin-top: 10px; }
#result-text { font-size: 1.5rem; line-height: 1.35; text-wrap: pretty; }
.attribution { margin-top: 10px; font-style: italic; }
.tally { margin-top: 2px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.share-label { display: block; margin-top: 18px; font-size: .9375rem; color: var(--ink-soft); }
#share-text { display: block; width: 100%; margin-top: 4px; padding: 8px 0 8px 12px; background: none; border: 0; border-left: 2px solid var(--hairline); border-radius: 0; resize: none; font-size: 1rem; }
.share-row { margin-top: 12px; display: flex; align-items: center; gap: 12px; }
#btn-share { min-height: 46px; padding: 0 22px; background: var(--oxblood); color: var(--paper); border-radius: 2px; font-weight: 600; }
#share-status { font-style: italic; }

#how, #stats, #archive { margin-top: 32px; }
.streak { font-size: 5rem; font-weight: 700; line-height: 1; color: var(--oxblood); letter-spacing: -.03em; font-variant-numeric: lining-nums; margin-bottom: 10px; }
dl { display: grid; grid-template-columns: 1fr auto; }
dt, dd { padding: 7px 0; border-bottom: 1px solid var(--hairline); }
dd { text-align: right; font-variant-numeric: tabular-nums; }
#archive-list { list-style: none; display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
#archive-list button { width: 100%; min-height: 44px; text-align: left; border-bottom: 1px solid var(--hairline); font-size: 1rem; }
#archive-list button:hover { color: var(--oxblood); }
#archive-list button[data-solved] { color: var(--oxblood); }
#btn-archive-more { min-height: 44px; margin-top: 6px; text-decoration: underline; text-underline-offset: 4px; }

@media (min-width: 720px) {
  .word { --cell: min(46px, calc(100cqi / (var(--longest) + 1))); }
  .cell { height: 62px; grid-template-rows: 38px 18px; }
  .cell::after { top: 40px; }
  .cell[data-guess=""] .cipher, .cell:not([data-guess=""]) .guess, .punct { font-size: 33px; }
  .punct { padding-bottom: 24px; }
  #keyboard { grid-template-columns: repeat(13, 1fr); }
  #tray { position: static; margin-inline: 0; }
  #controls { display: flex; justify-content: center; gap: 28px; }
  #controls button { padding: 0 8px; }
}
@media (min-width: 1000px) {
  .wordmark { font-size: 2.75rem; }
  .masthead { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 24px; }
  .masthead::after { grid-column: 1 / -1; }
  nav { margin: 0; }
  .difficulty { margin-left: 8px; }
  main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; column-gap: 48px; grid-auto-rows: min-content; }
  #game, #result { grid-column: 1; }
  #how, #stats, #archive { grid-column: 2; }
  #game { grid-row: 1 / span 3; }
  #result { grid-row: 4; }
  #how { grid-row: 1; margin-top: 16px; }
  #stats { grid-row: 2; }
  #archive { grid-row: 3 / span 2; }
  #how, #stats, #archive { border-left: 1px solid var(--oxblood); margin-left: -24px; padding-left: 24px; margin-top: 0; padding-top: 16px; }
  #archive-list button { font-size: .9375rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
