/* a little crossword — quiet gift-link aesthetic.
   Home is plain (one object, mixed type, lots of air).
   Interior pages are paper, stamps, and a little scrapbook whimsy. */

:root {
  --cream: #f3eee6;
  --paper: #fbf7f0;
  --ink: #3a322c;
  --ink-soft: #8a7e74;
  --rose: #c26a55;
  --rose-dark: #a85643;
  --blush: #f4cfd0;
  --sage: #8fa38a;
  --sage-dark: #6d8569;
  --butter: #e8c56b;
  --line: #e4d8c8;
  --manila: #ead9b8;
  --shadow: 0 18px 40px -18px rgba(58, 50, 44, 0.28);
  --shadow-sm: 0 8px 18px -10px rgba(58, 50, 44, 0.22);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --font-sans: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --font-brand: "Special Elite", "Courier New", Courier, monospace;
  --font-script: "Caveat", "Segoe Script", cursive;
  --font-soft: "Fraunces", "Instrument Serif", Georgia, serif;
  --pencil-cursor: url("/pencil-cursor.svg") 2 36, url("/pencil-cursor.png") 2 36, auto;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  cursor: var(--pencil-cursor);
}

body {
  font-family: var(--font-sans);
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  letter-spacing: 0.01em;
  overflow-x: hidden;
}

a, button, label, select, summary,
input, textarea {
  cursor: var(--pencil-cursor);
}

a { color: inherit; }

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 max(22px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  flex: 1;
  width: 100%;
  box-sizing: border-box;
}

/* ---------- Wordmark & quiet nav ---------- */
.wordmark {
  font-family: var(--font-brand);
  font-size: 20px;
  font-weight: 400;
  font-style: normal;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
}

.nav-quiet {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 6px 2px;
}
.nav-quiet:hover { color: var(--ink); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-brand);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--ink);
}

.brand .mark { display: none; }

/* ---------- Home (one torn-paper center) ---------- */
body.home {
  background:
    linear-gradient(180deg, rgba(243, 238, 230, 0.28) 0%, rgba(251, 247, 240, 0.38) 55%, rgba(243, 238, 230, 0.34) 100%),
    url("/newspaper-crossword-bg.jpg") center top / cover no-repeat fixed;
}

.home-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px 48px;
}

.torn-paper {
  position: relative;
  width: min(520px, 92vw);
  padding: 80px 56px 68px;
  isolation: isolate;
  filter: drop-shadow(0 20px 32px rgba(42, 37, 32, 0.28));
}

.torn-paper-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}

.paper-tape {
  position: absolute;
  top: calc(3% - 2.5px);
  left: 50%;
  width: min(200px, 48%);
  height: auto;
  transform: translateX(-50%) rotate(-3deg);
  z-index: 3;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 2px 4px rgba(42, 37, 32, 0.22));
}

.torn-paper-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  z-index: 1;
}

.torn-paper-wide {
  width: min(560px, 92vw);
  margin: 0 auto;
  padding: 64px 48px 56px;
}

.torn-paper-form {
  align-items: stretch;
  text-align: left;
  gap: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.torn-paper-form .page-intro {
  text-align: center;
  padding: 4px 0 20px;
}

.torn-paper-form .page-title {
  font-family: var(--font-brand);
  font-weight: 400;
  font-style: normal;
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.2;
  letter-spacing: 0.04em;
  margin: 0;
}

/* Expandable paper sheet — create / write the clues only */
.create-sheet {
  position: relative;
  width: min(560px, 92vw);
  margin: 0 auto 24px;
  box-sizing: border-box;
  border-style: solid;
  border-width: 40px;
  border-image-source: url("/paper-sheet.png");
  border-image-slice: 52 fill;
  border-image-width: 40px;
  border-image-repeat: stretch;
  filter: drop-shadow(0 18px 28px rgba(42, 37, 32, 0.24));
}

.create-sheet-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  width: 100%;
  padding: 8px 12px 20px;
  box-sizing: border-box;
}

.create-sheet .paper-tape {
  top: -43px;
  left: 50%;
  width: min(168px, 40%);
  transform: translateX(-50%) rotate(-2deg);
  transform-origin: center center;
}

.create-sheet-solve > .paper-tape {
  top: -44px;
}

.create-sheet .page-intro {
  text-align: center;
  padding: 4px 0 20px;
}

.create-sheet .page-title {
  font-family: var(--font-brand);
  font-weight: 400;
  font-style: normal;
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.2;
  letter-spacing: 0.04em;
  margin: 0;
}

.create-sheet .result-key {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px dashed var(--line);
}

.create-sheet-solve {
  width: min(640px, 100%);
  max-width: 100%;
  box-sizing: border-box;
}

.create-sheet-solve .grid-scroll {
  display: flex;
  justify-content: center;
  margin: 8px 0 4px;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

.create-sheet-solve .current-clue-bar {
  background: rgba(58, 50, 44, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: none;
  font-family: var(--font-sans);
  font-weight: 600;
  font-style: normal;
  font-size: 14px;
}

.create-sheet-solve .clue-list h4 {
  font-family: var(--font-brand);
  font-style: normal;
  font-weight: 400;
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.create-sheet-solve .clue-list li.active {
  background: rgba(194, 106, 85, 0.12);
}

.create-sheet-solve .clue-list li b {
  color: var(--rose-dark);
}

.solve-board-grid .form-actions {
  justify-content: center;
}

@media (min-width: 900px) {
  .create-sheet-solve {
    width: min(980px, 94vw);
  }

  body.solve-page.create-page .wrap {
    max-width: 1040px;
  }

  .solve-board {
    display: grid;
    grid-template-columns: auto minmax(240px, 1fr);
    gap: 28px 32px;
    align-items: start;
  }

  .create-sheet-solve .solve-board-clues.result-key {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    border-left: 1px dashed var(--line);
    padding-left: 28px;
  }

  .create-sheet-solve .solve-board-clues .clue-lists {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .create-sheet-solve .grid-scroll {
    justify-content: flex-start;
  }
}

body.solve-page {
  overflow-x: hidden;
}

.solve-page .wrap {
  overflow-x: hidden;
  max-width: 100%;
  box-sizing: border-box;
}

.solve-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.solve-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 0 16px;
  min-height: min(70vh, 640px);
}

.solve-stage .create-sheet {
  margin-bottom: 0;
}

.solve-stage .create-sheet-inner.center {
  align-items: center;
  text-align: center;
  gap: 14px;
  padding-top: 28px;
}

.solve-stage .create-sheet-inner.center .page-title {
  margin-top: 8px;
}

.solve-stage .create-sheet-inner.center .muted {
  max-width: 28ch;
  margin: 0 auto;
}

.create-page .wrap {
  max-width: 640px;
  width: 100%;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 28px;
}

.home-brand {
  font-family: var(--font-brand);
  font-weight: 400;
  font-style: normal;
  font-size: clamp(32px, 6.5vw, 48px);
  line-height: 1.2;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0;
  max-width: 16ch;
}

.home-kicker {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--ink-soft);
}

.home-title,
.page-title {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.05;
}

.home-title {
  font-size: clamp(48px, 9vw, 84px);
  margin: 6px 0 14px;
}

.home-sub,
.page-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 400;
}

.torn-paper .home-sub {
  max-width: 26ch;
  line-height: 1.45;
  font-size: 16px;
  font-family: var(--font-sans);
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
}

.home-cta-btn {
  margin-top: 6px;
}

@media (max-width: 720px) {
  body.home,
  body.interior {
    background-attachment: scroll;
  }

  .torn-paper {
    padding: 60px 40px 56px;
  }

  .torn-paper-wide {
    padding: 52px 32px 48px;
  }

  .create-sheet {
    border-width: 28px;
    border-image-width: 28px;
  }

  .create-sheet .paper-tape {
    top: -33px;
  }

  .create-sheet-solve > .paper-tape {
    top: -34px;
  }

  .create-sheet-inner {
    padding: 4px 8px 16px;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: 999px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: var(--pencil-cursor);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
  background: var(--rose);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--rose-dark); }

.btn-secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn-secondary:hover { border-color: var(--rose); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 10px 14px;
}
.btn-ghost:hover { color: var(--ink); }

.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Interior pages ---------- */
body.interior {
  background:
    linear-gradient(180deg, rgba(243, 238, 230, 0.72) 0%, rgba(251, 247, 240, 0.78) 100%),
    url("/newspaper-crossword-bg.jpg") center top / cover no-repeat fixed;
}

.page-intro {
  text-align: center;
  padding: 18px 0 28px;
}

.page-title {
  font-size: clamp(36px, 6vw, 52px);
  margin: 4px 0 12px;
}

.page-sub {
  max-width: 420px;
  margin: 0 auto;
  line-height: 1.5;
}

.section-hand {
  font-family: var(--font-script);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 6px;
}

/* ---------- Cards (paper) ---------- */
.card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 32px;
}

.paper-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), transparent 40%),
    var(--paper);
}
.paper-card::before {
  content: "";
  position: absolute;
  top: -14px;
  left: 50%;
  width: 92px;
  height: 28px;
  background: url("/brown-tape.png") center / 100% 100% no-repeat;
  transform: translateX(-50%) rotate(-5deg);
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(42, 37, 32, 0.16));
}

.stamp {
  position: absolute;
  top: 18px;
  right: 18px;
  font-family: var(--font-script);
  font-size: 18px;
  color: var(--rose);
  border: 1.5px dashed var(--rose);
  border-radius: 4px;
  padding: 4px 10px 6px;
  transform: rotate(8deg);
  opacity: 0.8;
  pointer-events: none;
}

/* ---------- Hero leftovers (create still uses some) ---------- */
.hero {
  text-align: center;
  padding: 56px 0 36px;
}

.hero h1 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.08;
  margin: 0 0 18px;
}

.hero .accent { color: var(--rose); }

.hero p {
  font-size: 19px;
  color: var(--ink-soft);
  max-width: 540px;
  margin: 0 auto 30px;
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.tag-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.tag {
  font-size: 13px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  padding: 6px 14px;
  border-radius: 999px;
}

/* ---------- Steps (unused on home, keep for safety) ---------- */
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 48px 0;
}
@media (max-width: 720px) {
  .steps { grid-template-columns: 1fr; }
}
.step {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 26px 22px;
  box-shadow: var(--shadow-sm);
}
.step .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sage);
  color: white;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 14px;
}
.step h3 { margin: 0 0 8px; font-size: 18px; }
.step p { margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.5; }

.footer,
.site-footer {
  position: static;
  flex-shrink: 0;
  margin-top: auto;
  text-align: center;
  padding: 28px 20px max(36px, env(safe-area-inset-bottom));
  color: var(--ink-soft);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.site-footer a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid rgba(58, 50, 44, 0.35);
  padding-bottom: 1px;
}

.site-footer a:hover {
  color: var(--rose-dark);
  border-bottom-color: var(--rose-dark);
}

/* ---------- Form ---------- */
.field { margin-bottom: 22px; }

.field label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.field .hint {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 6px;
  line-height: 1.45;
}

input[type="text"], textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input[type="text"]:focus, textarea:focus {
  border-color: var(--rose);
  background: #fff;
}
input[type="text"]:-webkit-autofill,
input[type="text"]:-webkit-autofill:hover,
input[type="text"]:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #fff inset;
  box-shadow: 0 0 0 1000px #fff inset;
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  transition: background-color 99999s ease-out;
}

.clue-row {
  display: grid;
  grid-template-columns: minmax(120px, 150px) minmax(160px, 280px) auto;
  gap: 10px;
  margin-bottom: 12px;
  align-items: start;
  justify-content: start;
}
.clue-row .answer-input { grid-column: 1; text-transform: uppercase; }
.clue-row .hint-input {
  grid-column: 2;
  max-width: 280px;
  width: 100%;
}
.clue-row .remove-btn { grid-column: 3; }
.clue-row .letter-map,
.clue-row .fit-note { grid-column: 1 / -1; }
.clue-row .remove-btn {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-size: 20px;
  cursor: var(--pencil-cursor);
  padding: 10px 6px;
  line-height: 1;
}
.clue-row .remove-btn:hover { color: var(--rose-dark); }

.clue-row.wont-fit .answer-input {
  border-color: var(--butter);
  background: #fff;
}
.clue-row .fit-note {
  margin: -4px 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: #6b5426;
  line-height: 1.4;
}
.clue-row .fit-note[hidden] { display: none; }

.letter-map {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: -4px;
}
.letter-map[hidden] { display: none; }
.lm-letter {
  width: 20px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 3px;
}
.lm-letter.cross {
  background: var(--butter);
  border-color: #c9a84a;
  color: var(--ink);
}
.lm-letter.lonely {
  background: #fdf6e4;
  border-color: var(--butter);
  color: #8a7a55;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.form-actions .btn {
  width: auto;
  min-width: 0;
  padding: 9px 18px;
  font-size: 13px;
}

.weave-preview {
  margin: 0 0 16px;
  padding: 16px 16px 14px;
  border-radius: var(--radius-sm);
  background: #f7f1e8;
  border: 1.5px solid var(--line);
}
.weave-kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--ink-soft);
  margin: 0 0 4px;
  font-weight: 700;
}
.weave-preview .hint { margin: 0 0 12px; }
.weave-preview .xw-grid {
  --cell: 32px;
}
.xw-cell.crossing {
  background: #f4e2a8;
}
.xw-cell.crossing::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 5px;
  height: 5px;
  background: var(--rose);
  border-radius: 50%;
}

.fit-summary {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 14px;
  background: #fdf6e4;
  border: 1px solid var(--butter);
  color: #6b5426;
}
.fit-summary[hidden] { display: none; }
.fit-summary b { letter-spacing: 0.02em; }

.clue-row-labels {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.08em;
}
.clue-row-labels span:first-child { max-width: 150px; flex: 0 0 150px; }
.clue-row-labels span:nth-child(2) { flex: 0 0 280px; max-width: 280px; }

@media (max-width: 560px) {
  .clue-row {
    grid-template-columns: 1fr auto;
  }
  .clue-row .answer-input { grid-column: 1; }
  .clue-row .remove-btn { grid-column: 2; grid-row: 1; }
  .clue-row .hint-input { grid-column: 1 / -1; }
}

.add-row-btn {
  background: transparent;
  border: 1.5px dashed var(--line);
  color: var(--ink-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  width: 100%;
  cursor: var(--pencil-cursor);
  font-weight: 700;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}
.add-row-btn:hover { border-color: var(--rose); color: var(--rose-dark); }

.banner {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.banner-warn { background: #fdf6e4; border: 1px solid var(--butter); color: #6b5426; }
.banner-error { background: #fbe6e0; border: 1px solid #eab6a4; color: #9c4126; }
.banner-success { background: #eaf3e8; border: 1px solid var(--sage); color: #395c37; }

/* ---------- Result / share ---------- */
.link-box {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #f7f1e8;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 14px 0 22px;
  flex-wrap: wrap;
}
.link-box code {
  flex: 1;
  min-width: 200px;
  font-size: 14px;
  word-break: break-all;
  color: var(--rose-dark);
  font-family: inherit;
}

.result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- Crossword grid ---------- */
.grid-scroll {
  overflow-x: hidden;
  padding: 4px 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.xw-grid {
  --cell: 34px;
  --cols: 1;
  --rows: 1;
  position: relative;
  width: calc(var(--cols) * var(--cell) + 1px);
  height: calc(var(--rows) * var(--cell) + 1px);
  max-width: 100%;
  background: transparent;
  padding: 0;
  margin: 0 auto;
}

.xw-cell {
  --x: 0;
  --y: 0;
  position: absolute;
  left: calc(var(--x) * var(--cell));
  top: calc(var(--y) * var(--cell));
  width: calc(var(--cell) + 1px);
  height: calc(var(--cell) + 1px);
  background: #fff;
  border: 1px solid #1a1a1a;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  text-align: center;
  overflow: hidden;
}

.xw-cell input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-size: calc(var(--cell) * 0.52);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  color: var(--ink);
  padding: 0;
  margin: 0;
  border-radius: 0;
  outline: none;
  caret-color: var(--rose);
  font-family: inherit;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.xw-cell input:-webkit-autofill,
.xw-cell input:-webkit-autofill:hover,
.xw-cell input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  transition: background-color 99999s ease-out;
  box-shadow: 0 0 0 1000px #fff inset;
}

.xw-cell input:focus { background: rgba(194, 106, 85, 0.12); }
.xw-cell.active-word { background: #fff; }
.xw-cell.active-word input:not(:focus) { background: rgba(232, 197, 107, 0.22); }
.xw-cell.empty-check {
  box-shadow: inset 0 0 0 2px rgba(194, 106, 85, 0.45);
}
.xw-cell.correct input { color: var(--sage-dark); background: rgba(143, 163, 138, 0.22); }
.xw-cell.incorrect input { animation: shake 0.3s ease; }

.xw-cell .num {
  position: absolute;
  top: max(1px, calc(var(--cell) * 0.03));
  left: max(2px, calc(var(--cell) * 0.08));
  font-size: calc(var(--cell) * 0.26);
  line-height: 1;
  font-weight: 800;
  color: var(--ink-soft);
  pointer-events: none;
  z-index: 1;
}

.xw-cell .preview-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ---------- Clue lists ---------- */
.clue-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-top: 8px;
}
@media (max-width: 560px) {
  .clue-lists { grid-template-columns: 1fr; }
}

.clue-list h4 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: lowercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 20px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.clue-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clue-list li {
  cursor: var(--pencil-cursor);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}
.clue-list li:hover { background: rgba(194, 106, 85, 0.08); }
.clue-list li.active { background: rgba(232, 197, 107, 0.35); font-weight: 700; }
.clue-list li b { margin-right: 6px; color: var(--rose-dark); }

.current-clue-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f4e2a8;
  color: var(--ink);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Envelope ---------- */
.envelope-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72vh;
  text-align: center;
}

.envelope {
  position: relative;
  width: min(420px, 100%);
  cursor: var(--pencil-cursor);
  filter: drop-shadow(0 22px 30px rgba(58, 50, 44, 0.18));
  transition: transform 0.25s ease;
}
.envelope:hover { transform: translateY(-6px) rotate(-0.6deg); }

.envelope-flap {
  height: 72px;
  background: linear-gradient(180deg, #f3e0b8, var(--manila));
  clip-path: polygon(0 0, 50% 72%, 100% 0);
  border-radius: 4px 4px 0 0;
  margin-bottom: -1px;
}

.envelope-face {
  background: var(--manila);
  border-radius: 0 0 10px 10px;
  padding: 28px 36px 36px;
  position: relative;
}

.envelope-stamp {
  position: absolute;
  top: 18px;
  right: 18px;
  font-family: var(--font-brand);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.02em;
  max-width: 92px;
  text-align: center;
  color: var(--rose);
  border: 1.5px dashed var(--rose);
  padding: 4px 8px 6px;
  transform: rotate(7deg);
  opacity: 0.85;
}

.envelope-kicker {
  margin: 8px 0 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: #8a6f4e;
}

.envelope h2 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  margin: 8px 0 12px;
  font-size: 32px;
  line-height: 1.15;
}

.envelope p {
  color: #8a6f4e;
  margin: 0 0 22px;
  line-height: 1.5;
}

.envelope .icon { display: none; }

/* ---------- Completion overlay ---------- */
.celebrate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 50, 44, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.celebrate-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 44px 36px;
  text-align: center;
  max-width: 400px;
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.celebrate-card .icon { font-size: 48px; margin-bottom: 14px; }
.celebrate-card h2 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 32px;
  margin: 0 0 10px;
}
.celebrate-card p { color: var(--ink-soft); margin: 0 0 24px; }

.confetti-piece {
  position: fixed;
  top: -10px;
  z-index: 60;
  border-radius: 2px;
  pointer-events: none;
  animation-name: fall;
  animation-timing-function: cubic-bezier(0.4, 0.2, 0.6, 1);
  animation-fill-mode: forwards;
}

@keyframes fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; }
}

/* ---------- Misc ---------- */
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spacer-lg { height: 40px; }
input[type="text"].title-input-lg {
  font-size: 22px;
  font-family: var(--font-brand);
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0.08em;
  max-width: 320px;
  width: 100%;
  padding: 6px 2px 8px;
  border: none;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transition: border-color 0.15s ease;
}
input[type="text"].title-input-lg:focus {
  border: none;
  border-bottom: 1.5px solid var(--rose);
  background: transparent;
  outline: none;
  box-shadow: none;
}
input[type="text"].title-input-lg:-webkit-autofill,
input[type="text"].title-input-lg:-webkit-autofill:hover,
input[type="text"].title-input-lg:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px transparent inset;
  box-shadow: none;
  transition: background-color 99999s ease-out;
}
.small { font-size: 13px; }

.progress-note {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 18px;
}

.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
}

@media (max-width: 560px) {
  .stamp { display: none; }
  .card { padding: 24px 18px; }
  .wordmark {
    white-space: normal;
    font-size: 18px;
    max-width: 11em;
  }
}

/* ---------- Solve page: newspaper edition ---------- */
.solve-page {
  --paper-news: #f7f2e6;
  --paper-rule: #2a2520;
  --font-paper: "Libre Bodoni", "Instrument Serif", Georgia, "Times New Roman", serif;
}

.solve-page .wrap-newspaper {
  max-width: 820px;
}

.topbar-newspaper {
  border-bottom: 2px solid var(--paper-rule);
  padding-bottom: 12px;
  margin-bottom: 8px;
}

.paper-dateline {
  font-family: var(--font-paper);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.newspaper-intro {
  display: block;
  width: min(460px, 100%);
  margin: 0;
  padding: 0;
  border: 2px solid var(--paper-rule);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), transparent 28%),
    var(--paper-news);
  box-shadow:
    6px 8px 0 rgba(42, 37, 32, 0.08),
    var(--shadow);
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: var(--pencil-cursor);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.newspaper-intro:hover {
  transform: translateY(-4px) rotate(-0.4deg);
  box-shadow:
    8px 12px 0 rgba(42, 37, 32, 0.1),
    var(--shadow);
}

.newspaper-intro-masthead {
  padding: 22px 28px 16px;
  border-bottom: 3px double var(--paper-rule);
  text-align: center;
}

.paper-section-label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.paper-masthead {
  font-family: var(--font-paper);
  font-weight: 700;
  font-style: normal;
  font-size: clamp(34px, 7vw, 48px);
  letter-spacing: -0.02em;
  line-height: 0.95;
  margin: 0;
  color: var(--paper-rule);
  text-transform: none;
}

.paper-subhead {
  margin: 10px 0 0;
  font-family: var(--font-paper);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-soft);
}

.newspaper-intro-body {
  padding: 24px 28px 30px;
  text-align: center;
}

.newspaper-intro .envelope-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.newspaper-intro h3 {
  font-family: var(--font-paper);
  font-style: italic;
  font-weight: 400;
  margin: 8px 0 12px;
  font-size: clamp(26px, 5vw, 34px);
  line-height: 1.15;
  color: var(--paper-rule);
}

.newspaper-intro p {
  color: var(--ink-soft);
  margin: 0 0 22px;
  line-height: 1.5;
  font-size: 15px;
}

.newspaper-sheet {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.4), transparent 18%),
    var(--paper-news);
  border: 2px solid var(--paper-rule);
  box-shadow:
    5px 7px 0 rgba(42, 37, 32, 0.07),
    var(--shadow-sm);
  padding: 28px 28px 36px;
  margin-top: 12px;
}

.newspaper-sheet.center {
  text-align: center;
  padding: 48px 28px;
}

.paper-page-head {
  text-align: center;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 3px double var(--paper-rule);
}

.paper-page-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.paper-page-rule {
  display: none;
}

.paper-byline {
  margin: 10px 0 0;
  font-family: var(--font-paper);
  font-style: italic;
  font-size: 17px;
  color: var(--ink-soft);
}

.paper-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--ink-soft);
}

.paper-headline {
  font-family: var(--font-paper);
  font-weight: 700;
  font-size: clamp(28px, 5vw, 40px);
  margin: 8px 0 12px;
  color: var(--paper-rule);
}

.solve-page .current-clue-bar {
  background: #fff;
  border: 1px solid var(--paper-rule);
  border-left: 4px solid var(--paper-rule);
  border-radius: 0;
  box-shadow: 0 8px 16px -10px rgba(42, 37, 32, 0.35);
  font-family: var(--font-paper);
  font-weight: 400;
  font-style: normal;
}

.paper-puzzle-block {
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid rgba(42, 37, 32, 0.25);
}

.solve-page .xw-grid {
  border-radius: 0;
  background: transparent;
  padding: 0;
  margin: 0 auto;
}

.solve-page .xw-cell {
  background: #fff;
  border: 1px solid #1a1a1a;
  border-radius: 0;
}

.solve-page .xw-cell input {
  border-radius: 0;
  font-family: var(--font-sans);
}

.solve-page .clue-list h4 {
  font-family: var(--font-paper);
  font-style: normal;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-rule);
  border-bottom: 1px solid var(--paper-rule);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.solve-page .clue-list li {
  border-radius: 0;
  font-size: 13.5px;
  padding: 6px 4px;
  border-bottom: 1px dotted rgba(42, 37, 32, 0.18);
}

.solve-page .clue-list li b {
  font-family: var(--font-paper);
  color: var(--paper-rule);
  min-width: 1.4em;
  display: inline-block;
}

.solve-page .clue-list li.active {
  background: rgba(42, 37, 32, 0.08);
  font-weight: 700;
}

.solve-page .celebrate-card {
  border: 2px solid var(--paper-rule);
  border-radius: 0;
  background: var(--paper-news);
}

.solve-page .celebrate-card h2 {
  font-family: var(--font-paper);
  font-style: normal;
  font-weight: 700;
}

@media (max-width: 560px) {
  .newspaper-sheet { padding: 20px 16px 28px; }
  .newspaper-intro-masthead,
  .newspaper-intro-body { padding-left: 18px; padding-right: 18px; }
}

/* ---------- Responsive: phone + iPad ---------- */
@media (max-width: 1024px) {
  body.home,
  body.interior {
    background-attachment: scroll;
  }
}

@media (hover: none) {
  body.home,
  body.interior {
    background-attachment: scroll;
  }

  .btn,
  .add-row-btn,
  .clue-list li,
  .remove-btn {
    min-height: 44px;
  }

  .remove-btn {
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 900px) {
  .create-sheet {
    width: min(560px, 94vw);
  }

  .create-page .wrap {
    max-width: 100%;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .solve-page .wrap-newspaper {
    max-width: 100%;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .topbar-newspaper {
    flex-wrap: wrap;
    gap: 8px 16px;
  }

  .paper-dateline {
    font-size: 11px;
  }

  .clue-row {
    grid-template-columns: minmax(100px, 140px) minmax(140px, 1fr) auto;
  }

  .clue-row .hint-input {
    max-width: none;
  }

  .clue-row-labels span:first-child {
    max-width: 140px;
    flex: 0 0 140px;
  }

  .clue-row-labels span:nth-child(2) {
    flex: 1;
    max-width: none;
  }

  .title-input-lg {
    max-width: 100%;
  }
}

@media (max-width: 720px) {
  .home-stage {
    padding: 24px 16px max(32px, env(safe-area-inset-bottom));
  }

  .torn-paper {
    width: min(520px, 94vw);
    padding: 64px 36px 56px;
  }

  .home-brand {
    font-size: clamp(26px, 8vw, 40px);
    max-width: 14ch;
  }

  .torn-paper .home-sub {
    font-size: 15px;
  }

  .paper-tape {
    width: min(150px, 46%);
  }

  .site-footer {
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }

  .create-sheet {
    border-width: 28px;
    border-image-width: 28px;
    width: min(560px, 94vw);
  }

  .create-sheet .paper-tape {
    top: -33px;
    width: min(140px, 46%);
  }

  .create-sheet-solve > .paper-tape {
    top: -34px;
  }

  .create-sheet-inner {
    padding: 4px 6px 14px;
  }

  .xw-grid,
  .solve-page .xw-grid {
    --cell: 28px;
  }

  body.solve-page.create-page .wrap {
    padding-left: 8px;
    padding-right: 8px;
  }

  .solve-page .create-sheet,
  .solve-page .create-sheet-solve {
    width: 100%;
    max-width: 100%;
    filter: none;
    box-shadow: 0 12px 24px -12px rgba(42, 37, 32, 0.28);
  }

  .result-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .result-actions .btn {
    width: 100%;
  }

  .link-box {
    flex-direction: column;
    align-items: stretch;
  }

  .newspaper-intro {
    width: 100%;
  }

  .envelope-wrap {
    min-height: 60vh;
    padding: 12px 0;
  }
}

@media (max-width: 560px) {
  .clue-row {
    grid-template-columns: 1fr auto;
  }

  .clue-row .answer-input { grid-column: 1; }
  .clue-row .remove-btn { grid-column: 2; grid-row: 1; }
  .clue-row .hint-input {
    grid-column: 1 / -1;
    max-width: none;
  }

  .clue-row-labels {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
  }

  .clue-row-labels span:first-child,
  .clue-row-labels span:nth-child(2) {
    max-width: none;
    flex: none;
  }

  .clue-row-labels span:nth-child(2) {
    grid-column: 1 / -1;
  }

  .create-sheet {
    border-width: 22px;
    border-image-width: 22px;
  }

  .create-sheet .paper-tape {
    top: -29px;
  }

  .create-sheet-solve > .paper-tape {
    top: -30px;
  }

  .create-sheet .page-title,
  .torn-paper-form .page-title {
    font-size: clamp(20px, 6vw, 26px);
  }

  .field label {
    font-size: 12px;
  }

  input[type="text"],
  textarea {
    font-size: 16px; /* keep iOS from zooming */
    padding: 12px 14px;
  }

  .xw-cell input[type="text"] {
    font-size: calc(var(--cell) * 0.52);
    padding: 0;
    margin: 0;
    line-height: 1;
    height: 100%;
    width: 100%;
  }

  input[type="text"].title-input-lg {
    font-size: 18px;
    padding: 6px 2px 8px;
  }

  .topbar-newspaper {
    flex-direction: column;
    align-items: flex-start;
  }

  .paper-masthead {
    font-size: clamp(28px, 9vw, 40px);
  }

  .solve-page .xw-grid {
    --cell: 24px;
  }

  .solve-page .grid-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: 2px 0;
    justify-content: center;
  }

  .current-clue-bar {
    font-size: 14px;
    padding: 10px 14px;
  }

  .form-actions .btn {
    width: 100%;
  }
}

@media (min-width: 561px) and (max-width: 1024px) {
  /* iPad / tablet */
  .torn-paper {
    width: min(520px, 80vw);
  }

  .create-sheet {
    width: min(640px, 88vw);
  }

  .create-sheet-solve {
    width: min(700px, 90vw);
  }

  .create-page .wrap {
    max-width: 720px;
  }

  .solve-page .wrap-newspaper {
    max-width: 760px;
  }

  .clue-lists {
    gap: 18px;
  }

  .xw-grid {
    --cell: clamp(22px, calc((100vw - 96px) / var(--cols)), 34px);
  }
}

