:root {
  --paper: #f2efe8;
  --paper-bright: #fbfaf7;
  --ink: #171918;
  --muted: #686b66;
  --line: #d8d4ca;
  --red: #ed3c2e;
  --red-dark: #c82d22;
  --green: #27725c;
  --shadow: 0 24px 70px rgba(29, 27, 21, 0.11);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(23, 25, 24, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 25, 24, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
}

button, input { font: inherit; }
button, label, a { -webkit-tap-highlight-color: transparent; }

.site-header,
main,
footer {
  width: min(1120px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img { width: 52px; height: 52px; object-fit: contain; }
.brand span { display: grid; gap: 1px; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.18rem; }
.brand small { color: var(--muted); font-size: .76rem; letter-spacing: .08em; text-transform: uppercase; }

.privacy-note { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .84rem; }
.privacy-note span { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(39, 114, 92, .12); }

main { padding: 46px 0 72px; }

.intro { display: flex; align-items: end; justify-content: space-between; gap: 60px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 14px; color: var(--red-dark); font-size: .73rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, p { text-wrap: pretty; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { margin: 0; font-size: clamp(2.8rem, 6vw, 4.8rem); line-height: .92; letter-spacing: -.055em; }
.lede { max-width: 440px; margin: 0 0 4px; color: #4f514e; font-size: clamp(.98rem, 1.8vw, 1.16rem); line-height: 1.55; }

.puzzle-desk { border: 1px solid var(--line); background: var(--paper-bright); box-shadow: var(--shadow); }
.desk-toolbar { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 10px 18px 10px 28px; border-bottom: 1px solid var(--line); }
.desk-toolbar > span { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.mode-switch { display: inline-flex; gap: 5px; padding: 4px; background: #eeece6; }
.mode-button { min-height: 42px; border: 0; padding: 0 18px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 750; }
.mode-button.is-active { color: white; background: var(--ink); }
.mode-button:disabled { cursor: not-allowed; opacity: .45; }

.idle-workspace, .game-workspace, .creator-workspace { padding: clamp(22px, 5vw, 58px); }
.idle-heading { margin-bottom: 28px; }
.idle-heading h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -.035em; }
.blank-board-wrap { position: relative; width: min(100%, 850px); margin-inline: auto; }
.blank-puzzle-shell { display: grid; grid-template-columns: repeat(15, 1fr); border: 1px solid #cecbc3; background: #d9d6cf; gap: 1px; opacity: .48; }
.blank-puzzle-shell span { aspect-ratio: 1; background: #fffefa; }
.blank-board-wrap > p { position: absolute; inset: 50% auto auto 50%; min-width: min(380px, 78%); margin: 0; padding: 22px 28px; transform: translate(-50%, -50%); border: 1px solid var(--line); background: rgba(251, 250, 247, .94); text-align: center; box-shadow: 0 12px 35px rgba(29, 27, 21, .08); }
.blank-board-wrap strong, .blank-board-wrap span { display: block; }
.blank-board-wrap strong { font: 500 1.25rem/1.25 Georgia, serif; }
.blank-board-wrap p span { margin-top: 7px; color: var(--muted); font-size: .82rem; }
.blank-reference-wrap { width: min(100%, 850px); margin: 34px auto 0; }
.blank-reference-wrap > span { display: block; margin-bottom: 9px; color: var(--muted); font-size: .66rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.blank-reference-grid { display: grid; grid-template-columns: repeat(13, 1fr); border: 1px solid #cecbc3; background: #d9d6cf; gap: 1px; opacity: .48; }
.blank-reference-grid span { position: relative; aspect-ratio: 1.25; padding: 5px; color: var(--muted); background: #fffefa; font: 600 .65rem/1 ui-monospace, monospace; }
.creator-heading { display: flex; align-items: end; justify-content: space-between; gap: 40px; margin-bottom: 36px; }
.creator-heading h2 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -.04em; }
.creator-heading > p { max-width: 440px; margin: 0; color: var(--muted); line-height: 1.55; }
.creator-form { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.creator-form label { display: grid; gap: 9px; }
.creator-form label > span { font-weight: 750; }
.creator-form textarea, .creator-form select { width: 100%; border: 1px solid var(--line); border-radius: 0; padding: 14px; color: var(--ink); background: white; resize: vertical; }
.creator-form textarea:focus, .creator-form select:focus { outline: 2px solid var(--red); outline-offset: 2px; }
.creator-form small { color: var(--muted); line-height: 1.4; }
.search-length { grid-column: 1; }
.creator-submit { align-self: end; justify-self: end; min-width: 210px; }
.creator-progress { min-height: 430px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.creator-progress .progress-track { margin-bottom: 36px; }
.creator-progress h3 { margin: 0; font: 500 clamp(1.8rem, 4vw, 3rem)/1.1 Georgia, serif; }
.creator-progress > p:not(.eyebrow) { max-width: 620px; min-height: 1.5em; color: var(--muted); }
.creator-actions { display: flex; gap: 12px; margin-top: 18px; }
.game-heading, .reference-heading { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 28px; }
.game-heading h2, .reference-heading h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -.035em; }
.game-status { margin: 0; color: var(--muted); font-size: .86rem; white-space: nowrap; }
.puzzle-shell { display: grid; grid-template-columns: repeat(15, 1fr); width: min(100%, 850px); margin-inline: auto; border: 2px solid var(--ink); background: var(--ink); gap: 1px; }
.puzzle-cell { position: relative; aspect-ratio: 1; min-width: 0; display: grid; place-items: center; border: 0; padding: 0; color: var(--ink); background: #fffefa; cursor: pointer; }
.puzzle-cell.is-block { background: #696b67; cursor: default; }
.puzzle-cell small { position: absolute; top: 4%; left: 7%; font: 650 clamp(.48rem, 1.44vw, .83rem)/1 ui-monospace, monospace; }
.puzzle-cell strong { font: 600 clamp(.9rem, 2.88vw, 1.81rem)/1 "Bradley Hand", "Noteworthy", cursive; }
.puzzle-cell.is-filled { color: #174c91; }
.puzzle-cell.is-selected { z-index: 1; outline: 3px solid var(--red); outline-offset: -2px; }
.reference-section { margin-top: clamp(42px, 7vw, 72px); }
.reference-heading > p { max-width: 430px; margin: 0; color: var(--muted); line-height: 1.5; }
.reference-grid { display: grid; grid-template-columns: repeat(13, 1fr); border: 2px solid var(--ink); background: var(--ink); gap: 1px; }
.reference-cell { position: relative; aspect-ratio: 1.25; min-width: 0; display: grid; place-items: center; border: 0; padding: 0; background: #fffefa; cursor: pointer; }
.reference-cell small { position: absolute; top: 7%; left: 8%; color: var(--muted); font: 650 clamp(.46rem, 1.3vw, .7rem)/1 ui-monospace, monospace; }
.reference-cell strong { font: 650 clamp(.9rem, 2.8vw, 1.65rem)/1 "Bradley Hand", "Noteworthy", cursive; }
.reference-cell.is-revealed { color: var(--red-dark); background: #fff4f1; }
.reference-cell.is-propagated { color: #174c91; background: #f4f8ff; }
.reference-cell.is-unused { cursor: default; opacity: .38; background: #e9e7e0; }
.reference-cell.is-selected { z-index: 1; outline: 4px solid var(--red); outline-offset: -3px; }
.game-actions { display: flex; align-items: center; gap: 12px; margin-top: 26px; }
.game-actions .text-button { margin-left: auto; }

.workspace {
  position: relative;
  background: var(--paper-bright);
}

.drop-zone { min-height: 520px; padding: clamp(28px, 6vw, 72px); }
.drop-zone.is-dragging { outline: 3px solid var(--red); outline-offset: -10px; background: #fff8f6; }
#photo { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.empty-state,
.working-state {
  min-height: 374px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.camera-mark {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: white;
}
.camera-mark svg { width: 35px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.empty-state h2, .working-state h2, .result-state h2, .error-state h2 { margin: 0; font-size: clamp(1.9rem, 4vw, 3rem); letter-spacing: -.03em; }
.empty-state > p, .working-state > p { max-width: 430px; margin: 14px 0 27px; color: var(--muted); line-height: 1.6; }

.primary-button,
.solve-button,
.secondary-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  padding: 0 24px;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}
.primary-button, .solve-button { color: white; background: var(--ink); }
.primary-button:hover, .solve-button:hover { background: var(--red-dark); border-color: var(--red-dark); }
.drop-hint { margin-top: 15px; color: #898b86; font-size: .8rem; }

.preview-state { max-width: 640px; margin: auto; }
.preview-frame { position: relative; height: min(44vh, 420px); display: grid; place-items: center; overflow: hidden; background: #e5e1d8; }
.preview-frame img { width: 100%; height: 100%; object-fit: contain; }
.file-fallback { min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.file-fallback span { padding: 7px 10px; background: var(--ink); color: white; font-size: .75rem; letter-spacing: .12em; }
.file-fallback strong { font-family: Georgia, serif; font-size: 1.6rem; }
.file-meta { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0 23px; }
.file-meta > span { min-width: 0; display: grid; gap: 5px; }
.file-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta small { color: var(--muted); }
.text-button { border: 0; border-bottom: 1px solid currentColor; padding: 3px 0; color: var(--ink); background: none; cursor: pointer; font-weight: 750; }
.text-button:hover { color: var(--red-dark); }
.solve-button { width: 100%; justify-content: space-between; min-height: 62px; padding-inline: 27px; border: 0; font-size: 1rem; }
.solve-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.preview-state.is-working .file-meta,
.preview-state.is-working .solve-button { visibility: hidden; }
.preview-frame .working-state {
  position: absolute;
  inset: 0;
  min-height: 0;
  padding: 24px;
  background: transparent;
}
.preview-frame .working-state::before {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(520px, calc(100% - 40px));
  height: min(330px, calc(100% - 40px));
  border: 1px solid rgba(37, 39, 37, .18);
  background: rgba(255, 254, 250, .94);
  box-shadow: 0 20px 60px rgba(26, 27, 26, .2);
  content: "";
  transform: translate(-50%, -50%);
}
.preview-frame .working-state > * { position: relative; z-index: 1; }
.working-state .eyebrow { margin-top: 24px; }
.solver-glyph { display: grid; grid-template-columns: repeat(4, 58px); border: 1px solid var(--ink); }
.solver-glyph span { aspect-ratio: 1; display: grid; place-items: center; border-right: 1px solid var(--ink); font-family: Georgia, serif; font-size: 1.2rem; animation: cell-pulse 1.8s infinite; }
.solver-glyph span:last-child { border: 0; }
.solver-glyph span:nth-child(2) { animation-delay: .18s; }
.solver-glyph span:nth-child(3) { animation-delay: .36s; }
.solver-glyph span:nth-child(4) { animation-delay: .54s; }
.progress-track { width: min(390px, 80%); height: 2px; margin-top: 10px; overflow: hidden; background: var(--line); }
.progress-track span { display: block; width: 42%; height: 100%; background: var(--red); animation: progress 1.8s ease-in-out infinite; }

.result-state { padding: clamp(28px, 6vw, 72px); }
.result-heading { display: flex; align-items: center; gap: 18px; margin-bottom: 32px; }
.result-heading .eyebrow { margin-bottom: 5px; }
.result-tick { width: 52px; height: 52px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; background: var(--green); font-size: 1.4rem; }
.result-image-wrap { margin: 0; max-height: 72vh; overflow: auto; background: #dedad1; text-align: center; }
.result-image-wrap img { display: block; width: 100%; height: auto; max-height: 72vh; object-fit: contain; }
.result-actions { display: flex; gap: 12px; margin-top: 24px; }
.secondary-button { color: var(--ink); background: transparent; }
.secondary-button:hover { background: #ebe7df; }
.result-detail { margin: 16px 0 0; color: var(--muted); font-size: .83rem; }

.error-state { display: flex; align-items: flex-start; gap: 20px; padding: clamp(30px, 6vw, 64px); border-left: 5px solid var(--red); }
.error-state > span { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--red); border-radius: 50%; color: var(--red-dark); font-weight: 850; }
.error-state p { max-width: 650px; color: var(--muted); line-height: 1.55; }

footer { display: flex; justify-content: space-between; gap: 30px; padding: 30px 0 50px; border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; }
footer p { margin: 0; }
footer strong { color: var(--ink); }

[hidden] { display: none !important; }

@keyframes cell-pulse { 0%, 60%, 100% { background: transparent; color: var(--ink); } 30% { background: var(--red); color: white; } }
@keyframes progress { 0% { transform: translateX(-110%); } 100% { transform: translateX(350%); } }

@media (max-width: 700px) {
  .site-header, main, footer { width: min(100% - 28px, 1120px); }
  .site-header { min-height: 82px; }
  .brand img { width: 44px; height: 44px; }
  .privacy-note { display: none; }
  main { padding: 34px 0 58px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 14px; margin-bottom: 24px; }
  h1 { font-size: clamp(2.8rem, 14vw, 4rem); }
  .lede { margin: 0; }
  .desk-toolbar { align-items: flex-start; flex-direction: column; gap: 8px; padding: 15px; }
  .mode-switch { display: flex; }
  .mode-button { flex: 1; padding-inline: 10px; }
  .idle-workspace, .game-workspace, .creator-workspace { padding: 16px; }
  .idle-heading { margin: 10px 0 18px; }
  .blank-board-wrap > p { padding: 17px 12px; }
  .blank-reference-grid { grid-template-columns: repeat(13, 1fr); }
  .blank-reference-grid span { padding: 2px; font-size: .48rem; }
  .creator-heading { align-items: flex-start; flex-direction: column; gap: 12px; margin: 10px 0 26px; }
  .creator-form { grid-template-columns: 1fr; }
  .search-length { grid-column: auto; }
  .creator-submit { width: 100%; justify-self: stretch; }
  .creator-actions { align-items: stretch; flex-direction: column; width: 100%; }
  .game-heading, .reference-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .game-heading { margin-bottom: 18px; }
  .puzzle-cell small { top: 3%; left: 4%; }
  .reference-grid { grid-template-columns: repeat(7, 1fr); }
  .reference-cell { aspect-ratio: 1.1; }
  .game-actions { align-items: stretch; flex-direction: column; }
  .game-actions > * { width: 100%; }
  .game-actions .text-button { margin: 5px 0 0; }
  .drop-zone { min-height: 450px; padding: 22px; }
  .empty-state { min-height: 405px; }
  .drop-hint { display: none; }
  .preview-frame { height: 52vh; }
  .file-meta { align-items: flex-start; }
  .result-state { padding: 22px; }
  .result-actions { flex-direction: column; }
  .result-actions > * { width: 100%; }
  footer { flex-direction: column; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
