:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --fg: #e8e6e1;
  --fg-dim: #9a9aa3;
  --line: #2a2d38;
  --tile: #1d2029;
  --tile-border: #353846;
  --tile-filled-border: #5a5e72;
  --green: #5fa364;
  --yellow: #c9a23a;
  --gray: #3a3d49;
  --gray-darker: #2a2d36;
  --solved: #1a1c23;
  --accent: #d4a574;
  --danger: #c25a5a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  min-height: 100vh;
  overflow-x: hidden;
}
body {
  background-image:
    radial-gradient(circle at 20% 0%, rgba(212, 165, 116, 0.06), transparent 40%),
    radial-gradient(circle at 80% 100%, rgba(95, 163, 100, 0.04), transparent 40%);
}
header {
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
h1 {
  font-family: 'Fraunces', serif;
  font-weight: 800;
  font-size: 28px;
  letter-spacing: -0.02em;
  font-style: italic;
}
h1 .title-link {
  cursor: pointer;
  transition: color .15s;
}
h1 .title-link:hover { color: var(--accent); }
h1 .n {
  color: var(--accent);
  font-style: normal;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.header-right {
  display: flex;
  align-items: baseline;
  gap: 18px;
}
.header-info {
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: flex;
  gap: 18px;
}
.header-info span b {
  color: var(--fg);
  font-weight: 700;
}
.info-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: color .15s, border-color .15s, background .15s;
}
.info-btn:hover {
  color: var(--accent);
  border-color: rgba(212, 165, 116, 0.45);
  background: rgba(212, 165, 116, 0.06);
}
.info-btn:active { transform: scale(0.94); }
.info-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* === Info modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px;
  overflow-y: auto;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 560px;
  width: 100%;
  padding: 36px 32px 28px;
  position: relative;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: slideUp .22s ease;
}
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}
.modal-close:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.05);
}
.modal h2 {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 800;
  font-size: 32px;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  padding-right: 28px;
}
.modal h3 {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 18px;
  margin-top: 22px;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}
.modal .lede-modal {
  font-size: 14px;
  color: var(--fg);
  margin-bottom: 14px;
  line-height: 1.55;
}
.modal .lede-modal b { color: var(--accent); font-weight: 700; }
.modal ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.modal ul li {
  font-size: 13px;
  color: var(--fg-dim);
  line-height: 1.65;
  padding-left: 18px;
  position: relative;
  margin-bottom: 4px;
}
.modal ul li::before {
  content: '·';
  position: absolute;
  left: 6px;
  color: var(--accent);
  font-weight: bold;
}
.modal ul li b {
  font-weight: 700;
  color: var(--fg);
  /* Inherits JetBrains Mono from body — stays monospace, no italics. */
}
.modal .example {
  margin-bottom: 12px;
}
.modal .mini-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.mini-tile {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--tile-border);
  background: var(--tile);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
  color: var(--fg);
  text-transform: uppercase;
}
.mini-tile.green { background: var(--green); border-color: var(--green); color: white; }
.mini-tile.yellow { background: var(--yellow); border-color: var(--yellow); color: white; }
.mini-tile.gray { background: var(--gray); border-color: var(--gray); }
.modal .example p {
  font-size: 12.5px;
  color: var(--fg-dim);
  line-height: 1.5;
}
.modal .example p b {
  color: var(--fg);
  font-weight: 700;
}
.modal hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px 0 0;
}
.modal .inspired {
  line-height: 1.7;
  color: var(--fg-dim);
  /* font-size: 0 collapses whitespace nodes between child spans;
     each child span sets its own size via inline style. */
  font-size: 0;
  word-spacing: 0;
}
.modal .inspired .ins-item {
  white-space: nowrap;
  /* inline-block keeps each link with its trailing separator together when
     the line wraps. */
  display: inline-block;
}
.modal .inspired .ins-item::after {
  content: '·';
  color: var(--line);
  margin: 0 0.3em;
  /* Inherits font-size from .ins-item, so dots scale with the names. */
}
.modal .inspired .ins-item.ins-last::after {
  content: '';
  margin: 0;
}
.modal .inspired a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--fg-dim);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color .15s, text-decoration-color .15s;
}
.modal .inspired a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}
.modal .signature {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--fg-dim);
  text-align: left;
}
.modal .signature a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--fg-dim);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color .15s, text-decoration-color .15s;
}
.modal .signature a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}
main {
  padding: 0 16px;
  max-width: 1700px;
  margin: 0 auto;
}

/* === Loading === */
.loading {
  text-align: center;
  padding: 40px 20px;
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-inner {
  display: inline-block;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 22px;
  color: var(--fg-dim);
  position: relative;
}
.loading-inner::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 12px;
  vertical-align: middle;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.4); }
}

/* === Setup === */
.setup {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px;
  text-align: center;
  /* Fill the viewport (minus the sticky header) and centre vertically so
     there's no dead space below the Begin button. dvh handles mobile URL bar. */
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.setup .tagline {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 20px;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.setup h2 {
  font-family: 'Fraunces', serif;
  font-size: 56px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 28px;
  line-height: 1.05;
}
.setup h2 em {
  color: var(--accent);
  font-style: italic;
}
.setup p.lede {
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 36px;
}
.setup p.lede b { color: var(--fg); }
.field {
  text-align: left;
  margin-bottom: 22px;
}
.field label {
  display: block;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  padding: 14px 16px;
  border-radius: 4px;
  transition: border-color .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}
.quick-picks {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.quick-picks button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: all .15s;
}
.quick-picks button:hover {
  color: var(--fg);
  border-color: var(--fg-dim);
}
.quick-picks button.named {
  color: var(--accent);
  border-color: rgba(212, 165, 116, 0.3);
}
.quick-picks button.named:hover {
  background: rgba(212, 165, 116, 0.08);
}
.start-btn {
  width: 100%;
  background: var(--fg);
  color: var(--bg);
  border: none;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-style: italic;
  font-size: 22px;
  padding: 16px;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 12px;
  transition: transform .1s;
  letter-spacing: -0.01em;
}
.start-btn:hover { transform: translateY(-1px); }
.start-btn:active { transform: translateY(0); }
.link-btn {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 12px;
  margin-top: 8px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 4px;
  transition: color .15s;
}
.link-btn:hover { color: var(--fg); }

/* === Boards === */
#game {
  overflow-x: auto;
  /* Reserve room for the scrollbar so layout doesn't jump when it appears */
  scrollbar-gutter: stable;
  /* Top spacing for the boards, plus bottom clearance for the fixed keyboard. */
  padding: 28px 0 220px;
}
#game::-webkit-scrollbar { height: 8px; }
#game::-webkit-scrollbar-track { background: transparent; }
#game::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}
#game::-webkit-scrollbar-thumb:hover { background: var(--tile-filled-border); }
#game { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }
.boards {
  display: grid;
  gap: 24px 18px;
  grid-template-columns: repeat(var(--cols), max-content);
  margin: 0 auto 32px;
  width: max-content;
  /* No max-width: when content is wider than parent, parent's overflow-x scrolls.
     When content is narrower, margin: 0 auto centers it. */
  padding: 0 4px;
}
.board {
  display: grid;
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 4px;
  transition: opacity .35s, filter .35s;
}
.board.solved {
  opacity: 0.32;
  filter: grayscale(0.6);
}
.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.tile {
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--tile-border);
  background: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  color: var(--fg);
  transition: transform .15s, background .3s, border-color .3s;
}
.tile.filled {
  border-color: var(--tile-filled-border);
  animation: pop .12s ease;
}
.tile.green { background: var(--green); border-color: var(--green); color: white; }
.tile.yellow { background: var(--yellow); border-color: var(--yellow); color: white; }
.tile.gray { background: var(--gray); border-color: var(--gray); color: var(--fg); }
.tile.solved { background: var(--solved); border-color: var(--solved); color: transparent; }
.tile.flip { animation: flip .55s ease forwards; }
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
.board.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* === Keyboard === */
.keyboard {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(15, 17, 21, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 8px 16px;
  z-index: 5;
}
.kbd-row {
  display: grid;
  /* 20 half-slots so we can do half-key spacers and 1.5-key wide ENTER/BACK.
     Total row width = 10 letter-slots, matching row 1's QWERTYUIOP. */
  grid-template-columns: repeat(20, 1fr);
  gap: 5px;
  margin-bottom: 5px;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}
.key {
  /* Default: a letter key occupies 2 sub-columns (one full slot). */
  grid-column: span 2;
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  height: 50px;
  min-width: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: transform .08s;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.key:active { transform: scale(0.94); }
.key.wide {
  /* ENTER / BACK occupy 3 sub-columns (1.5 slots). */
  grid-column: span 3;
  font-size: 14px;
}
/* Half-slot spacers padding the middle row so its 9 letters centre to match
   the 10-letter top row, keeping all letter keys exactly the same width. */
.kbd-spacer {
  grid-column: span 1;
}
/* Per-board cell grid behind the letter */
.key .cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--key-cols, 1), 1fr);
  grid-auto-rows: 1fr;
  pointer-events: none;
  z-index: 0;
}
.key .cell {
  background: transparent;
  transition: background .25s;
}
.key .cell.green { background: var(--green); }
.key .cell.yellow { background: var(--yellow); }
.key .cell.gray { background: var(--gray); }
.key .cell.solved { background: var(--gray-darker); }
.key .label {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
}
.key.unguessed .cells { display: none; }

/* === Toast === */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; }
.toast.danger { background: var(--danger); color: white; }
.toast.success { background: var(--green); color: white; }

/* === End screen === */
.endscreen {
  max-width: 640px;
  margin: 40px auto;
  padding: 40px 28px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}
.endscreen h2 {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 44px;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.endscreen h2.win { color: var(--green); }
.endscreen h2.lose { color: var(--danger); }
.endscreen .subtitle {
  color: var(--fg-dim);
  margin-bottom: 24px;
  font-size: 14px;
}
.endscreen .results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.result-item {
  border: 1px solid var(--line);
  padding: 10px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg);
}
.result-item .word {
  text-transform: uppercase;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.05em;
}
.result-item .score {
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 4px;
}
.result-item.win .word { color: var(--green); }
.result-item.lose .word { color: var(--danger); }
.endscreen .summary-line {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--fg-dim);
  margin-bottom: 24px;
  word-break: break-all;
  padding: 12px;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--line);
  text-align: center;
}
.endscreen .summary-line .g { color: var(--green); font-weight: 700; }
.endscreen .summary-line .r { color: var(--danger); font-weight: 700; }
.endscreen .actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}
.endscreen .actions button {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--bg);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 3px;
  transition: background .15s, border-color .15s;
}
.endscreen .actions button:hover {
  background: #e6b885;
  border-color: #e6b885;
}
.endscreen .actions button:active {
  transform: translateY(1px);
}
.endscreen .divider {
  height: 1px;
  background: var(--line);
  margin: 22px 0 18px;
}
.endscreen .share-block {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 18px;
}
.endscreen .share-block label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  margin-bottom: 6px;
}
.endscreen .share-block .share-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.endscreen .share-block .copy-field {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 8px 10px;
  border-radius: 3px;
  min-width: 0;
  /* Each line stays on its own line; long lines (e.g. share URL with hash)
     scroll horizontally rather than wrapping or breaking. */
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  user-select: text;
  -webkit-user-select: text;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.endscreen .share-block .copy-field::-webkit-scrollbar { height: 6px; }
.endscreen .share-block .copy-field::-webkit-scrollbar-track { background: transparent; }
.endscreen .share-block .copy-field::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}
.endscreen .share-block .copy-field::-webkit-scrollbar-thumb:hover {
  background: var(--tile-filled-border);
}
.endscreen .share-block .copy-field .g {
  color: var(--green);
  font-weight: 700;
}
.endscreen .share-block .copy-field .r {
  color: var(--danger);
  font-weight: 700;
}
.endscreen .share-block button {
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 12px;
  padding: 0 14px;
  border-radius: 3px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background .15s;
  /* Don't shrink: keep button a tidy fixed width while the field expands. */
  flex-shrink: 0;
  align-self: stretch;
}
.endscreen .share-block button:hover { background: #e6b885; }
.endscreen .share-block .share-help {
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 8px;
  line-height: 1.5;
}

.hidden { display: none !important; }

@media (max-width: 600px) {
  h1 { font-size: 22px; }
  header { padding: 12px 16px; }
  .header-right {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }
  .header-info { font-size: 10px; gap: 10px; }
  .info-btn { width: 30px; height: 30px; }
  .info-btn svg { width: 17px; height: 17px; }
  .tile { width: 30px; height: 30px; font-size: 14px; }
  .boards { gap: 18px 12px; }
  .setup h2 { font-size: 40px; }
  .setup { padding: 32px 20px; }
  .endscreen h2 { font-size: 32px; }
  main { padding: 0 8px; }
  #game { padding: 18px 0 220px; }
  .key { height: 46px; font-size: 12px; }
  .key.wide { font-size: 13px; }
  .kbd-row { gap: 4px; max-width: none; }
  .keyboard { padding: 10px 6px 14px; }
  .modal-backdrop { padding: 16px 12px; }
  .modal { padding: 28px 22px 22px; }
  .modal h2 { font-size: 26px; }
  .modal h3 { font-size: 16px; margin-top: 18px; }
}
