:root {
  --paper: #f7f7f1;
  --ink: #253e35;
  --green: #264d40;
  --muted: #66715f;
  --line: #dce1d5;
  --yellow: #f5d66b;
  --pale: #edf1e7;
  --white: #fffefa;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: 'Trebuchet MS', Arial, sans-serif;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0 auto;
  max-width: 480px;
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
.game-app { height: var(--app-height, 100dvh); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
button, input { font: inherit; }
button, a, input, summary { -webkit-tap-highlight-color: transparent; }
button, summary { touch-action: manipulation; cursor: pointer; }
button { border: 0; color: inherit; min-height: 44px; }
button:disabled { cursor: default; opacity: .55; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid #b68316;
  outline-offset: 3px;
}
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
button svg { width: 18px; height: 18px; flex-shrink: 0; }
.skip-link { position: fixed; top: -60px; left: 16px; padding: 12px; background: var(--yellow); z-index: 20; }
.skip-link:focus { top: 10px; }

.site-header {
  flex: none;
  min-height: 52px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 6px; min-height: 44px; font: bold 24px var(--serif); letter-spacing: -1.2px; }
.brand i { font-weight: normal; }
.brand img { width: 30px; height: 30px; }
.site-header nav { display: flex; align-items: center; gap: 2px; }
.text-button { display: inline-flex; align-items: center; gap: 6px; padding: 8px; background: none; font-size: 12px; white-space: nowrap; }
.help-button { min-width: 44px; background: none; font: 22px var(--serif); }
main { padding: 0 10px 10px; }
.game-app main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.game-card { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.game-heading { flex: none; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.game-heading > div { min-width: 0; }
h1, h2, h3, p { overflow-wrap: break-word; }
.game-heading h1 { font: normal 25px/1.1 var(--serif); letter-spacing: -.7px; margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-heading p { font-size: 12px; color: var(--muted); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer { flex: none; display: flex; align-items: center; gap: 6px; background: none; padding: 0 4px; min-width: 70px; font-size: 12px; font-variant-numeric: tabular-nums; }
.timer svg { width: 15px; height: 15px; }
.puzzle-body { flex: 1; min-height: 0; padding: 0 10px; display: flex; flex-direction: column; }
.board-column { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.board-wrap { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; container-type: size; }
.board { width: min(100cqw, 100cqh); display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; border: 2px solid var(--green); background: var(--green); border-radius: 5px; overflow: hidden; aspect-ratio: 1; }
.cell { position: relative; background: var(--white); min-width: 0; aspect-ratio: 1; }
.cell.block { background: var(--green); background-image: repeating-linear-gradient(135deg, transparent, transparent 5px, #ffffff04 5px, #ffffff04 6px); }
.cell.active { background: #e6eddc; }
.cell.selected { background: var(--yellow); }
.cell input { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; background: transparent; color: var(--ink); text-align: center; text-transform: uppercase; font-size: clamp(16px, 7cqmin, 30px); padding: 8px 0 0; outline: none; caret-color: transparent; touch-action: manipulation; user-select: none; -webkit-touch-callout: none; }
.cell:focus-within { box-shadow: inset 0 0 0 2px #b68316; }
.cell-number { position: absolute; top: 5px; left: 5px; font-size: 10px; line-height: 1; pointer-events: none; }
.cell.incorrect input { color: #ac4234; }
.cell.incorrect::after { content: ''; position: absolute; width: 5px; height: 5px; background: #b4473b; bottom: 4px; right: 4px; border-radius: 50%; pointer-events: none; }
.cell.revealed .cell-number { color: #796cba; }
.active-clue { flex: none; background: var(--pale); display: flex; gap: 8px; align-items: center; min-height: 60px; max-height: 100px; border-radius: 6px; margin-top: 8px; padding: 6px 8px; font-size: 14px; line-height: 1.4; }
#active-clue-text { max-height: 84px; overflow-y: auto; }
.active-clue-number { font-weight: bold; font-size: 11px; white-space: nowrap; color: #527044; }
.active-clue > button { align-self: stretch; min-width: 44px; margin-left: auto; background: none; font-size: 24px; color: #527044; }
.clues { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.clues h3 { font-size: 12px; margin: 0 0 5px; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.clues h3 span { color: var(--muted); margin-right: 5px; }
.clue-button { display: flex; align-items: flex-start; gap: 6px; text-align: left; background: none; width: 100%; border-radius: 5px; padding: 8px 5px; font-size: 12px; line-height: 1.5; color: var(--muted); margin: 2px 0; }
.clue-number { font-size: 10px; font-weight: bold; min-width: 10px; padding-top: 2px; }
.clue-button.active { background: var(--pale); color: var(--ink); }
.clue-button.solved .clue-number::after { content: '✓'; }
.clue-length { font-size: 10px; color: var(--muted); margin-left: 3px; white-space: nowrap; }
.game-message { flex: none; margin: 6px 14px; font-size: 12px; color: var(--muted); }
.game-message:empty { display: none; }
.game-message.error, .theme-status.error { color: #a94737; }
.game-toolbar { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-top: 1px solid var(--line); gap: 2px; margin-top: 8px; }
.game-toolbar > div { display: flex; gap: 4px; }
.utility-button { background: none; display: flex; align-items: center; gap: 4px; font-size: 11px; padding: 8px 2px; white-space: nowrap; }
.utility-button svg { width: 15px; height: 15px; }
.primary-button { background: var(--yellow); color: var(--ink); font-size: 12px; padding: 10px; border-radius: 7px; font-weight: bold; display: inline-flex; justify-content: center; align-items: center; gap: 6px; white-space: nowrap; }
.primary-button > span { font-size: 18px; line-height: 1; }
.keyboard { flex: none; min-width: 0; margin: 0; border: 0; padding: 8px 0 0; display: grid; gap: 4px; }
.keyboard-row { display: flex; justify-content: center; gap: 3px; }
.keyboard-row button { flex: 1; max-width: calc((100% - 27px) / 10); min-width: 0; padding: 0; border-radius: 5px; background: var(--white); box-shadow: 0 1px 0 #adb9a5; font-size: 16px; font-weight: bold; }
.keyboard-row button[data-key="Enter"], .keyboard-row button[data-key="Backspace"] { max-width: none; background: #dce5d4; font-size: 21px; }
.keyboard-row button:active { background: var(--yellow); }

.theme-panel { background: #f0f2e8; padding: 24px 16px; }
.eyebrow { font-size: 9px; letter-spacing: 1.4px; font-weight: bold; color: var(--muted); }
.theme-panel h2 { font: normal 29px/1.15 var(--serif); letter-spacing: -.7px; margin: 7px 0; }
.theme-panel-heading > p { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.theme-options { display: grid; gap: 8px; }
.theme-option { display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 64px; background: var(--white); border: 1px solid var(--line); border-radius: 8px; text-align: left; }
.theme-option.selected { border-color: #80916b; background: #e6edda; }
.theme-option-icon { width: 36px; height: 36px; border-radius: 7px; background: #f3ead0; display: grid; place-items: center; font-size: 24px; color: #897338; flex-shrink: 0; }
.theme-option:nth-child(2) .theme-option-icon { background: #eee5ee; color: #8c7694; }
.theme-option:nth-child(3) .theme-option-icon { background: #e1e8ef; color: #6a7f90; }
.theme-option:nth-child(4) .theme-option-icon { background: #f1e2d6; color: #a77e5b; }
.theme-option-title { display: block; font-size: 13px; font-weight: bold; }
.theme-option-subtitle { display: block; font-size: 11px; color: var(--muted); }
.theme-option-check { margin-left: auto; color: #527044; font-size: 18px; }
.theme-divider { border-top: 1px solid var(--line); margin: 28px 0 22px; text-align: center; height: 0; }
.theme-divider > span { position: relative; top: -10px; background: #f0f2e8; padding: 0 8px; font-size: 8px; letter-spacing: .7px; color: var(--muted); }
#theme-form label { display: block; font-size: 13px; font-weight: bold; margin-bottom: 8px; }
.theme-input-wrap { position: relative; }
.theme-input-wrap input { width: 100%; background: var(--white); border: 1px solid #bcc6b2; border-radius: 7px; padding: 13px 34px 13px 12px; font-size: 16px; }
.theme-input-wrap input::placeholder { color: #72796b; font-size: 13px; }
.theme-input-wrap > span { position: absolute; right: 10px; top: 6px; font-size: 26px; color: #75825d; }
.generate-button { display: flex; align-items: center; justify-content: center; gap: 28px; width: 100%; min-height: 48px; padding: 12px; background: var(--green); color: white; font-weight: bold; border-radius: 7px; margin-top: 10px; }
.generate-button > span { font-size: 20px; }
.theme-help { text-align: center; color: var(--muted); font-size: 11px; margin: 10px 0 0; }
.theme-status { color: var(--ink); font-size: 13px; line-height: 1.5; margin: 0; }
.theme-status:not(:empty) { margin-top: 12px; }
.offline-status { flex: none; background: #f9edba; border-radius: 8px; padding: 4px 10px; font-size: 11px; margin: 0 0 6px; }
.install-help { padding: 12px 6px; font-size: 13px; color: var(--muted); }
.install-help summary { min-height: 44px; padding: 12px 0; color: var(--ink); font-weight: bold; }
.install-help summary span { float: right; }
.install-help p { margin: 6px 0 12px; }

dialog { inset: 12px 0 auto; margin: 0 auto; border: 1px solid var(--line); border-radius: 17px; background: var(--white); color: var(--ink); padding: 30px 24px; width: min(440px, calc(100% - 24px)); max-height: calc(var(--app-height, 100dvh) - 24px); overflow-y: auto; overscroll-behavior: contain; box-shadow: 0 20px 70px #133d2926; }
dialog::backdrop { background: #19352688; }
dialog h2 { font: normal 32px/1.15 var(--serif); letter-spacing: -1px; margin: 16px 0; }
dialog p, dialog li { font-size: 14px; line-height: 1.6; color: var(--muted); }
dialog ul { padding-left: 18px; margin-bottom: 24px; }
dialog li { padding-left: 4px; margin: 10px 0; }
.dialog-close { position: absolute; top: 8px; right: 8px; min-width: 44px; background: none; font-size: 28px; }
#finish-dialog { text-align: center; }
.finish-art { color: #8b9867; font-size: 64px; line-height: 1.1; margin: 12px 0; }
.finish-stats { display: flex; justify-content: center; gap: 30px; margin: 22px 0 28px; }
.finish-stats strong { display: block; font: normal 28px var(--serif); }
.finish-stats span { font-size: 9px; letter-spacing: .5px; color: var(--muted); display: block; margin-top: 6px; }
.pause-overlay { position: absolute; inset: 0; background: #edf1e9fa; display: flex; align-items: center; justify-content: center; flex-direction: column; border-radius: 5px; text-align: center; z-index: 2; padding: 12px; }
.pause-overlay > span { font-size: 32px; }
.pause-overlay h3 { font: normal 28px var(--serif); margin: 12px 0 0; }
.pause-overlay p { color: var(--muted); font-size: 13px; margin: 10px 0 20px; }
.clues.paused { visibility: hidden; }

.compact .site-header { min-height: 44px; padding-block: 0; }
.compact .game-heading { padding-block: 5px; }
.compact .game-heading h1 { font-size: 20px; margin: 0; }
.compact .game-heading p { display: none; }
.compact .active-clue { min-height: 44px; max-height: 64px; margin-top: 4px; padding-block: 0; font-size: 12px; }
.compact #active-clue-text { max-height: 60px; }
.compact .game-toolbar { padding-block: 2px; margin-top: 4px; }
.compact .cell-number { top: 2px; left: 2px; font-size: 8px; }
.compact .pause-overlay > span, .compact .pause-overlay p { display: none; }
.compact .pause-overlay h3 { font-size: 20px; margin: 0 0 8px; }
.short-screen .game-heading { display: none; }
.short-screen .puzzle-body { padding-top: 4px; }
.short-screen .keyboard { gap: 2px; padding-top: 4px; }
.short-screen .keyboard-row button { min-height: 32px; }

@media (min-width: 600px) and (max-height: 500px) {
  .game-app { max-width: 800px; }
  .game-app main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 1fr); gap: 10px; }
  .offline-status { grid-column: 1 / -1; }
  .keyboard { align-self: center; padding: 0; }
  .keyboard-row button { min-height: 44px; }
  .short-screen .keyboard-row button { min-height: 44px; }
}

@media (max-width: 350px) {
  .site-header { padding-inline: 12px; }
  .brand > span { display: none; }
  .site-header nav { gap: 0; }
  .game-toolbar .utility-button svg { display: none; }
}
