*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #f5f0e8;
  font-family: 'Libre Baskerville', Georgia, serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 64px;
  color: #1a1a1a;
  -webkit-tap-highlight-color: transparent;
}
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* Off-screen input that captures hardware keyboard input on iOS/iPadOS without showing the soft keyboard */
.kb-capture {
  position: fixed; left: -9999px; top: 0;
  width: 1px; height: 1px; opacity: 0;
  border: 0; padding: 0; pointer-events: none;
}

/* HEADER */
.header {
  text-align: center;
  margin-bottom: 32px;
  width: 100%;
  max-width: 780px;
  border-bottom: 2px solid #1a1a1a;
  padding-bottom: 16px;
}
.header-eyebrow {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 8px;
}
.header-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}
.header-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}
.nav-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #1a1a1a;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.nav-btn:hover:not(:disabled) { opacity: 1; }
.nav-btn:disabled { opacity: 0.2; cursor: default; }
.header-dateline {
  font-size: 13px;
  color: #444;
  font-style: italic;
}
.header-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.header-timer { font-size: 13px; letter-spacing: 0.06em; color: #444; }
.header-stats-btn {
  background: none; border: none; cursor: pointer;
  font-size: 15px; padding: 0 2px; opacity: 0.6;
  transition: opacity 0.15s;
}
.header-stats-btn:hover { opacity: 1; }

/* ALREADY SOLVED BANNER */
.solved-banner {
  background: #c8e6c9;
  border: 1.5px solid #1a1a1a;
  padding: 10px 20px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 13px;
  width: 100%;
  max-width: 780px;
}
.solved-banner strong {
  font-family: 'Playfair Display', serif;
}

/* MAIN LAYOUT */
.puzzle-layout {
  display: flex;
  gap: 48px;
  width: 100%;
  max-width: 780px;
  align-items: flex-start;
}
.grid-section { flex-shrink: 0; }
.grid-wrap { position: relative; display: inline-block; }

/* GRID — size set via inline style on the element */
.grid {
  display: grid;
  border: 2px solid #1a1a1a;
  box-shadow: 0 1px 2px rgba(26,26,26,0.06), 0 12px 32px rgba(26,26,26,0.10);
}
.cell {
  width: var(--cell-size, 58px); height: var(--cell-size, 58px);
  border: 1px solid #1a1a1a;
  background-color: #ffffff;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', serif;
  font-size: clamp(14px, calc(var(--cell-size, 58px) * 0.45), 22px); font-weight: 700;
  cursor: pointer; user-select: none;
}
.cell.black { background-color: #1a1a1a; cursor: default; }
.cell.highlighted { background-color: #e8edf5; }
.cell.selected { background-color: #f3c969; box-shadow: inset 0 0 0 2px #c08e1f; }
.cell.correct { background-color: #cfe8d2; }
.cell.wrong { background-color: #f5cdd2; }
.cell-number {
  position: absolute; top: 3px; left: 3px;
  font-size: 9px; font-weight: 400;
  font-family: 'Libre Baskerville', serif;
  color: #1a1a1a; line-height: 1;
}

/* CONTROLS */
.controls { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.btn {
  padding: 8px 20px;
  font-family: 'Libre Baskerville', serif;
  font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1.5px solid #1a1a1a; background: transparent; color: #1a1a1a;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.btn:hover { background: #1a1a1a; color: #f5f0e8; }
.btn.btn-primary { background: #1a1a1a; color: #f5f0e8; }
.btn.btn-primary:hover { background: #333; }
.btn.btn-share { border-color: #2e7d32; color: #2e7d32; }
.btn.btn-share:hover { background: #2e7d32; color: #fff; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: transparent; color: #1a1a1a; }
.btn.btn-primary:disabled:hover { background: #1a1a1a; color: #f5f0e8; }
.share-confirm { font-size: 12px; color: #2e7d32; font-style: italic; margin-top: 6px; }
.controls-secondary { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.btn-sm {
  padding: 5px 12px;
  font-family: 'Libre Baskerville', serif;
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  border: 1px solid #888; background: transparent; color: #555;
  cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-sm:hover { border-color: #1a1a1a; color: #1a1a1a; }
.btn-sm:disabled { opacity: 0.3; cursor: default; }
.btn-sm:disabled:hover { border-color: #888; color: #555; }

/* ACTIVE CLUE BAR — desktop: inline above grid; mobile: fixed above keyboard */
.active-clue-bar {
  display: flex; align-items: center; gap: 14px;
  background: #ffffff;
  border: 1px solid #e3d9c2;
  border-left: 3px solid #d4a843;
  padding: 12px 16px; margin-bottom: 16px;
  font-size: 14.5px; line-height: 1.45;
  max-width: 780px; width: 100%;
  min-height: 52px;
  box-shadow: 0 1px 2px rgba(26,26,26,0.04);
}
.active-clue-bar .acb-tag {
  font-family: 'Playfair Display', serif;
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase;
  font-weight: 700; flex-shrink: 0;
  color: #8a6d2a;
}
.active-clue-bar .acb-text {
  flex: 1; min-width: 0;
  font-style: italic; color: #1a1a1a;
}
.active-clue-bar .acb-content {
  display: flex; align-items: center; gap: 14px;
  flex: 1; min-width: 0;
  background: transparent; border: 0; padding: 0; margin: 0;
  text-align: left; font: inherit; color: inherit;
  cursor: pointer;
}
.active-clue-bar .acb-nav {
  background: transparent; border: 1px solid #e3d9c2;
  padding: 4px 12px; font-size: 16px; line-height: 1;
  cursor: pointer; color: #6b6b6b; flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.active-clue-bar .acb-nav:hover { border-color: #1a1a1a; color: #1a1a1a; background: #faf6ee; }
.active-clue-bar .acb-nav:disabled { opacity: 0.3; cursor: default; }
.active-clue-bar.empty {
  background: #faf6ee; border-left-color: transparent;
  color: #888; font-style: italic;
  box-shadow: none;
}

/* MOBILE KEYBOARD */
.mobile-keyboard { display: none; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 5px; }
.kb-key {
  flex: 1 1 0;
  max-width: 38px; height: 46px;
  font-family: 'Libre Baskerville', serif;
  font-size: 14px; font-weight: 700;
  border: 1px solid #c9bfa8; background: #fff; color: #1a1a1a;
  cursor: pointer;
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(26,26,26,0.08);
  transition: transform 0.06s ease, background 0.1s, border-color 0.1s;
  padding: 0;
}
.kb-key:hover { background: #faf6ee; border-color: #1a1a1a; }
.kb-key:active { background: #f3c969; border-color: #c08e1f; transform: translateY(1px); box-shadow: none; }
.kb-wide { max-width: 84px; font-size: 16px; background: #f5f0e8; }
.kb-backspace { max-width: 56px; background: #f5f0e8; font-size: 16px; }

/* PUZZLE PICKER */
.puzzle-picker {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  max-width: 780px; width: 100%;
  margin: 0 auto 20px; padding: 0 8px;
}
.pp-chip {
  font-family: 'Libre Baskerville', serif;
  font-size: 13px; font-weight: 400;
  padding: 6px 10px; min-width: 38px;
  border: 1px solid #c9bfa8; background: #fff; color: #1a1a1a;
  cursor: pointer; border-radius: 4px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.pp-chip:hover { border-color: #1a1a1a; }
.pp-chip.solved { border-color: #2e7d32; color: #2e7d32; }
.pp-chip.active { background: #f3c969; border-color: #c08e1f; color: #1a1a1a; }
.pp-chip.solved.active { background: #f3c969; border-color: #c08e1f; color: #1a1a1a; }

/* CLUES */
.clues-section { flex: 1; min-width: 0; }
.clue-group { margin-bottom: 24px; }
.clue-group-title {
  font-family: 'Playfair Display', serif;
  font-size: 11px; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase;
  border-bottom: 1px solid #1a1a1a; padding-bottom: 5px; margin-bottom: 10px;
}
.clue {
  display: flex; gap: 8px; padding: 4px 6px;
  font-size: 13px; line-height: 1.5; border-radius: 2px; cursor: pointer;
}
.clue:hover { background: rgba(212, 168, 67, 0.2); }
.clue.active { background: #d4a843; }
.clue-num { font-weight: 700; flex-shrink: 0; min-width: 18px; }

/* DIALOGS */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.dialog-card {
  background: #f5f0e8; border: 2px solid #1a1a1a;
  padding: 32px 40px; max-width: 360px; width: 90%; text-align: center;
}
.dialog-title { font-family: 'Playfair Display', serif; font-size: 20px; margin-bottom: 12px; }
.dialog-body { font-size: 13px; color: #555; margin-bottom: 24px; line-height: 1.6; font-style: italic; }
.dialog-buttons { display: flex; gap: 12px; justify-content: center; }

/* STATS */
.stats-grid { display: flex; gap: 32px; justify-content: center; margin-bottom: 28px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-num { font-family: 'Playfair Display', serif; font-size: 36px; font-weight: 700; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: #666; }
.stats-disclaimer { font-size: 11px; color: #888; font-style: italic; line-height: 1.5; margin: -12px 0 20px; }

/* COMPLETION OVERLAY */
.completion-overlay {
  position: absolute; inset: -2px;
  background: rgba(245, 240, 232, 0.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 10; border: 2px solid #1a1a1a; pointer-events: none;
}
.completion-title { font-family: 'Playfair Display', serif; font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.completion-time { font-size: 13px; color: #555; letter-spacing: 0.06em; margin-bottom: 14px; }
.completion-rule { width: 40px; height: 1px; background: #1a1a1a; margin-bottom: 14px; }
.completion-sub { font-size: 12px; color: #888; font-style: italic; }

/* CONFETTI */
.confetti-wrap {
  position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden;
}
.confetti-piece {
  position: absolute; width: 8px; height: 8px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* MOBILE BOTTOM DOCK — clue bar + keyboard pinned together */
.mobile-bottom { display: none; }

/* RESPONSIVE */
@media (max-width: 639px) {
  body { padding: 16px 10px 240px; }
  .puzzle-layout { flex-direction: column; align-items: center; gap: 20px; }
  .header { margin-bottom: 16px; padding-bottom: 12px; }
  .header-title { font-size: 28px; margin-bottom: 6px; }
  .header-eyebrow { font-size: 10px; margin-bottom: 6px; }
  .grid-section { width: 100%; display: flex; flex-direction: column; align-items: center; }
  .clues-section { width: 100%; }
  .controls { justify-content: center; }

  /* Hide the inline (above-grid) clue bar on mobile — the docked one shows above keyboard */
  .active-clue-bar.inline-only { display: none; }

  .mobile-bottom {
    display: block;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: #f5f0e8;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 50;
    border-top: 1.5px solid #1a1a1a;
  }
  .mobile-bottom .active-clue-bar {
    margin: 0; border-left: none; border-right: none; border-top: none;
    border-bottom: 1px solid #1a1a1a;
  }
  .mobile-keyboard { display: block; padding: 8px 6px; }
  .kb-row { gap: 4px; }
  .completion-overlay { padding: 12px; }
  .completion-title { font-size: 24px; }
}
@media (max-width: 380px) {
  .kb-key { height: 40px; font-size: 13px; }
  .active-clue-bar { font-size: 13px; padding: 6px 10px; }
}

.site-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid #ddd;
  text-align: center;
  font-size: 12px;
  color: #888;
  line-height: 1.7;
  width: 100%;
  max-width: 780px;
}
.site-footer p { margin: 0; }
.site-footer a { color: #888; border-bottom: 1px solid #ccc; text-decoration: none; }
.site-footer a:hover { color: #1a1a1a; border-bottom-color: #1a1a1a; }
@media (max-width: 639px) { .site-footer { display: none; } }

/* PUZZLE LIST VIEW — used by pack.html, mini.html, midi.html */
.pack-shell { width: 100%; max-width: 640px; }
.pack-header {
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--pack-accent, #1a1a1a);
}
.pack-eyebrow {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 10px;
}
.pack-eyebrow a { color: #666; text-decoration: none; }
.pack-eyebrow a:hover { color: #1a1a1a; }
.pack-emoji { font-size: 42px; line-height: 1; margin-bottom: 12px; }
.pack-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}
.pack-desc {
  font-size: 14px;
  color: #555;
  font-style: italic;
  line-height: 1.5;
}
.pack-progress {
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #888;
  margin-top: 14px;
}
.pack-meta-strip {
  margin-top: 10px;
  font-size: 11px;
  color: #888;
  font-style: italic;
  letter-spacing: 0.03em;
}

.puzzle-list { display: flex; flex-direction: column; gap: 10px; }
.puzzle-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border: 1.5px solid #1a1a1a;
  background: #fff;
  text-decoration: none;
  color: #1a1a1a;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.puzzle-row:hover { background: #1a1a1a; color: #f5f0e8; }
.puzzle-row:hover .puzzle-row-meta { color: #bbb; }
.puzzle-row-num {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
  min-width: 28px;
  text-align: center;
}
.puzzle-row-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.puzzle-row-title {
  font-family: 'Playfair Display', serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.puzzle-row-meta { font-size: 12px; color: #666; font-style: italic; }
.puzzle-row-status { font-size: 18px; flex-shrink: 0; color: #2e7d32; }
.puzzle-row-status.unsolved { color: transparent; }

.pack-error { width: 100%; max-width: 480px; text-align: center; margin-top: 64px; }
.pack-error h1 {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  margin-bottom: 12px;
}
.pack-error p {
  font-size: 14px;
  color: #666;
  font-style: italic;
  margin-bottom: 24px;
  line-height: 1.5;
}
.pack-error a {
  font-family: 'Libre Baskerville', serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1a1a;
  border: 1.5px solid #1a1a1a;
  padding: 8px 20px;
  text-decoration: none;
  display: inline-block;
}
.pack-error a:hover { background: #1a1a1a; color: #f5f0e8; }
