.puzzle-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), 2.5rem);
    gap: 2px;
    width: max-content;
    padding: 0;
    border: none;
}

/* Purely visual pill/capsule path overlay, sized to match the grid exactly
   in JS. pointer-events: none so it never intercepts clicks/taps/drags --
   the cell buttons underneath keep handling all input. Positioned above
   the (position: static) cell buttons automatically since it's the only
   positioned element in the grid; cells sit above it in turn (see .cell)
   with a transparent background so their letters read on top of the
   capsules while the capsules still show through around them. */
.puzzle-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
    /* SVG roots clip to their declared width/height by default. That
       attribute is set once in JS from the grid's measured size (see
       puzzle.js's ResizeObserver) and, on the responsive /play/ grid
       (width/height resolved via aspect-ratio), can be briefly stale right
       after load -- overflow:visible means a highlight is never silently
       clipped even if that measurement was ever a beat behind. */
    overflow: visible;
}

.cell {
    position: relative;
    z-index: 2;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    text-transform: uppercase;
    background: transparent;
    color: var(--ink, #181A17);
    border: 1px solid var(--line, #ccc);
    cursor: pointer;
    padding: 0;
    user-select: none;
    /* Custom pointer-based drag tracing needs to own single-finger touch
       gestures on the grid -- without this, touch browsers try to scroll/pan
       on drag. "pinch-zoom" (rather than "none") still lets a two-finger
       pinch fall through to native zoom instead of being read as a drag. */
    touch-action: pinch-zoom;
    /* iOS Safari otherwise flashes a gray highlight rectangle on tap and
       offers a long-press callout (copy/lookup menu) on these buttons --
       neither makes sense for a rapid-tap/drag word-selection grid. */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.cell.invalid {
    background: #f28b82;
    border-color: #c5221f;
}

#word-list li {
    break-inside: avoid;
}

#word-list li.found {
    text-decoration: line-through;
    color: #888;
}

#word-list li.found::before {
    content: "";
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    margin-right: 0.4em;
    border-radius: 2px;
    background: var(--word-color, #8fd694);
    vertical-align: middle;
}

/* Honeypot field, same off-screen technique as contact/templates's .hp-field
   (site.css) -- redefined here since this page (puzzles/puzzle_detail.html)
   doesn't load site.css. A plain text input, not type="hidden", so a bot
   that skips hidden inputs doesn't skip this too; humans never see it. */
.hp-field {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Public aggregate line -- see puzzles/_rating_summary.html. */
.rating-summary {
    text-align: center;
    color: var(--muted, #6B6F67);
    font-size: 14px;
    margin: 0 0 20px;
}

/* --- Completion overlay: rating + book CTA -----------------------------
   Markup in puzzles/_completion_overlay.html, shown by puzzle.js once every
   word is found. Hidden by default; puzzle.js toggles the .is-open class. */

.completion-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 12, 8, 0.55);
}

.completion-overlay.is-open {
    display: flex;
}

.completion-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: var(--panel, #fff);
    border: 1px solid var(--line, #E4E2DB);
    border-radius: 16px;
    padding: 32px 28px 24px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.25);
    text-align: center;
}

.completion-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1;
    color: var(--muted, #6B6F67);
    cursor: pointer;
}

.completion-close:hover {
    color: var(--ink, #181A17);
    background: var(--line, #E4E2DB);
}

.completion-title {
    margin: 0 0 18px;
    font-size: 22px;
}

.completion-fastest {
    margin: -8px 0 18px;
    font-size: 14px;
    color: var(--muted, #6B6F67);
}

.completion-fastest.is-new-fastest {
    color: #d4a017;
    font-weight: 600;
}

.completion-stars {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 18px;
}

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    font-size: 34px;
    line-height: 1;
    color: var(--line, #E4E2DB);
    transition: color 0.1s ease, transform 0.1s ease;
}

.star-btn:hover,
.star-btn:focus-visible {
    transform: scale(1.1);
}

.star-btn.hovered,
.star-btn.selected {
    color: #d4a017;
}

.completion-comment-label {
    display: block;
    text-align: left;
    font-size: 13px;
    color: var(--muted, #6B6F67);
    margin-bottom: 6px;
}

.completion-comment-label span {
    font-weight: 400;
}

.completion-comment {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--line, #E4E2DB);
    border-radius: 8px;
    background: var(--bg, #FAFAF8);
    color: var(--ink, #181A17);
    font: inherit;
    font-size: 14px;
    padding: 10px 12px;
    resize: vertical;
    margin-bottom: 16px;
}

.completion-comment:focus {
    outline: 2px solid var(--accent, #0F8F5F);
    outline-offset: 1px;
}

.completion-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 22px;
}

/* Self-contained rather than relying on site.css's .btn-primary, since the
   bare /puzzle/ page (puzzles/puzzle_detail.html) doesn't load site.css. */
#completion-submit {
    background: var(--accent, #0F8F5F);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 11px 22px;
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}

#completion-submit:disabled {
    background: var(--line, #E4E2DB);
    color: var(--muted, #6B6F67);
    cursor: not-allowed;
}

.completion-ack {
    font-size: 14px;
    color: var(--accent, #0F8F5F);
    font-weight: 500;
}

.completion-book-cta {
    border-top: 1px solid var(--line, #E4E2DB);
    padding-top: 18px;
}

.completion-book-lede {
    font-size: 14px;
    color: var(--muted, #6B6F67);
    line-height: 1.5;
    margin: 0 0 14px;
}

.completion-book-links {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.completion-book-links a {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 8px;
    background: var(--tape, #F4C93B);
    color: #181A17;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
}

.completion-book-links a:hover {
    filter: brightness(0.95);
}

