/* Quilt -- quilt.html. Two halves: the board/engine (`qt-` prefix, quilt-engine.js) and the page
   around it (`quilt-` prefix: mode tabs, pickers, tournament cards, summary modal -- adapted from
   sudoku.css, duplicated rather than shared per this repo's one-stylesheet-per-page convention). */

.qt-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 14px 20px;
    background: var(--color-surface);
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}

.qt-stat {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qt-stat-icon {
    font-size: 18px;
    line-height: 1;
}

.qt-stat-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
}

.qt-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.qt-stat-value.urgent {
    color: var(--color-danger);
}

.qt-round-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-secondary);
}

/* ---- Board ---- */

.qt-board {
    --qt-cell: 40px;
    --qt-line: #E4E1EE;
    position: relative;
    width: 100%;
    aspect-ratio: var(--qt-cols) / var(--qt-rows);
    background-color: var(--color-surface);
    background-image:
        linear-gradient(to right, var(--qt-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--qt-line) 1px, transparent 1px);
    background-size: calc(100% / var(--qt-cols)) calc(100% / var(--qt-rows));
    border: 2px solid var(--color-primary-dark);
    border-radius: var(--radius-sm);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: crosshair;
}

/* Focused only so Ctrl+Z reaches the round's keydown listener -- there's no keyboard drawing, so
   no focus ring. */
.qt-board:focus {
    outline: none;
}

.qt-rects,
.qt-knots,
.qt-clues {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.qt-rect,
.qt-knot,
.qt-clue,
.qt-preview {
    position: absolute;
}

/* A placed piece: fabric tint with a dashed "stitch" line inside the edge. */
.qt-rect {
    background: var(--qt-colour, var(--qt-tint));
    border: 2px solid var(--color-primary-dark);
    border-radius: 3px;
    box-shadow: inset 0 0 0 max(2px, calc(var(--qt-cell) * 0.08)) rgba(255, 255, 255, 0.55);
    transition: background-color 0.6s ease, border-color 0.6s ease, box-shadow 0.6s ease;
}

.qt-rect::after {
    content: '';
    position: absolute;
    inset: max(3px, calc(var(--qt-cell) * 0.12));
    border: 1.5px dashed rgba(60, 52, 137, 0.35);
    border-radius: 2px;
    transition: opacity 0.6s ease;
}

.qt-rect-error {
    border-color: var(--color-danger);
    background-image: repeating-linear-gradient(45deg, rgba(192, 57, 43, 0.12) 0 6px, transparent 6px 12px);
}

.qt-rect-error::after {
    border-color: rgba(192, 57, 43, 0.5);
}

.qt-clue {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(11px, calc(var(--qt-cell) * 0.5));
    font-weight: 800;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    transition: color 0.6s ease, opacity 0.6s ease;
}

/* Hard-mode shape clues: a frame around the number -- square box = must be a square, long pill =
   must be a single row or column. A frame rather than a corner badge so it never collides with
   two-digit numbers on small cells. */
.qt-clue-square::before,
.qt-clue-strip::before {
    content: '';
    position: absolute;
    border: max(1.5px, calc(var(--qt-cell) * 0.05)) solid var(--color-primary);
}

.qt-clue-square::before {
    inset: 10%;
    border-radius: 2px;
}

.qt-clue-strip::before {
    inset: 24% 3%;
    border-radius: 999px;
}

/* Blocker: a sewn button/knot no rectangle may cover. */
.qt-knot {
    display: flex;
    align-items: center;
    justify-content: center;
}

.qt-knot::before {
    content: '';
    width: 58%;
    height: 58%;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.85) 0 9%, transparent 10%),
        radial-gradient(circle at 65% 35%, rgba(255, 255, 255, 0.85) 0 9%, transparent 10%),
        radial-gradient(circle at 35% 65%, rgba(255, 255, 255, 0.85) 0 9%, transparent 10%),
        radial-gradient(circle at 65% 65%, rgba(255, 255, 255, 0.85) 0 9%, transparent 10%),
        var(--color-text-muted);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: background-color 0.6s ease;
}

/* Drag preview + its size label. */
.qt-preview {
    border: 2px dashed var(--color-primary);
    background: rgba(127, 119, 221, 0.18);
    border-radius: 3px;
    z-index: 2;
    pointer-events: none;
}

.qt-preview-label {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-primary-dark);
    color: white;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

/* Near the top edge there's no room above the preview -- show the label below it instead. */
.qt-preview:not(.qt-preview-top) .qt-preview-label {
    bottom: auto;
    top: calc(100% + 6px);
}

/* ---- Reveal ---- */

.qt-board.qt-solved,
.qt-board.qt-failed {
    cursor: default;
    background-image: none;
}

.qt-solved .qt-rect,
.qt-failed .qt-rect {
    border-color: transparent;
    border-radius: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.qt-solved .qt-rect::after,
.qt-failed .qt-rect::after {
    border-color: rgba(255, 255, 255, 0.35);
}

.qt-solved .qt-clue,
.qt-failed .qt-clue {
    color: rgba(255, 255, 255, 0.75);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    opacity: 0.55;
}

.qt-solved .qt-clue::before,
.qt-failed .qt-clue::before {
    display: none;
}

/* Knot cells belong to the picture too: fill the cell with its colour, button drawn on top. */
.qt-solved .qt-knot,
.qt-failed .qt-knot {
    background: var(--qt-colour);
    transition: background-color 0.6s ease;
}

.qt-solved .qt-knot::before,
.qt-failed .qt-knot::before {
    background-color: rgba(0, 0, 0, 0.22);
}

.qt-failed .qt-rects,
.qt-failed .qt-knots {
    filter: grayscale(0.85) opacity(0.75);
}

.qt-solved {
    animation: qt-pop 0.5s ease 0.6s both;
}

@keyframes qt-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.025); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .qt-rect,
    .qt-clue,
    .qt-knot::before {
        transition: none;
    }

    .qt-solved {
        animation: none;
    }
}

/* ---- Message + controls ---- */

.qt-message {
    min-height: 1.6em;
    margin: 12px 0 8px;
    text-align: center;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.qt-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.qt-control-btn {
    padding: 10px 20px;
    border: 0.5px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.15s;
}

.qt-control-btn:not(:disabled):hover {
    border-color: var(--color-primary);
    background: var(--color-primary-tint);
}

.qt-control-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* ==================== Page ==================== */

.quilt-mode-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 460px;
    margin: 0 auto 20px;
}

.quilt-mode-tab {
    flex: 1;
    min-width: 140px;
    padding: 10px 14px;
    border: 0.5px solid var(--color-border);
    background: white;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.quilt-mode-tab.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.quilt-mode-tab:not(.active):hover {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
}

.game-container {
    max-width: 460px;
    margin: 0 auto;
}

.quilt-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
}

.quilt-subtitle {
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}


.quilt-difficulty-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quilt-difficulty-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 16px 20px;
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-md);
    background: white;
    cursor: pointer;
    transition: all 0.15s;
}

.quilt-difficulty-btn:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-tint);
}

.quilt-difficulty-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text);
}

.quilt-difficulty-points {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
}

.quilt-tournament-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quilt-tournament-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding: 20px 24px;
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
}

.quilt-tournament-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quilt-tournament-name {
    font-weight: 800;
    font-size: 22px;
    color: var(--color-text);
}

.quilt-tournament-meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 15px;
    color: var(--color-text-secondary);
}

.quilt-tournament-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.quilt-tournament-meta-icon {
    width: 20px;
    height: 20px;
    color: var(--color-primary);
    flex-shrink: 0;
}

.quilt-tournament-sep {
    color: var(--color-border-strong);
}

.quilt-tournament-card .btn {
    flex: 0 0 auto;
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .quilt-tournament-card {
        flex-direction: column;
        align-items: stretch;
    }

    .quilt-tournament-card .btn {
        width: 100%;
    }
}

.quilt-tournament-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}


/* ---------- Post-round summary modal ----------
   Same overlay/dialog/close pattern as index.html's sign-in modal / wordle.html's summary modal,
   duplicated here rather than shared since only one page's CSS loads at a time. */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(44, 44, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 300;
}

.modal-dialog {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 52px 24px 24px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--radius-sm);
    z-index: 1;
}

.modal-close:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.quilt-summary-celebrate {
    position: relative;
    display: flex;
    justify-content: center;
    height: 64px;
    margin-bottom: 8px;
}

.quilt-summary-trophy-wrap {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--color-primary-tint);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.quilt-summary-trophy-wrap svg {
    width: 30px;
    height: 30px;
}

.quilt-summary-confetti {
    position: absolute;
    top: 8px;
    width: 7px;
    height: 7px;
    border-radius: 2px;
}

.quilt-summary-confetti-1 {
    left: calc(50% - 92px);
    background: #F2B705;
    transform: rotate(20deg);
}

.quilt-summary-confetti-2 {
    left: calc(50% - 68px);
    top: 34px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--color-danger);
}

.quilt-summary-confetti-3 {
    right: calc(50% - 92px);
    background: var(--color-primary);
    transform: rotate(-20deg);
}

.quilt-summary-confetti-4 {
    right: calc(50% - 68px);
    top: 34px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--color-success);
}

.quilt-summary-title {
    text-align: center;
    font-size: 22px;
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: 4px;
}

.quilt-summary-subtitle {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 20px;
}

.quilt-summary-breakdown {
    border-top: 0.5px solid var(--color-border);
    padding-top: 12px;
    margin-bottom: 16px;
}

.quilt-summary-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: var(--color-text-secondary);
    padding: 4px 0;
}

.quilt-summary-line-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quilt-summary-line-icon {
    display: flex;
    flex: 0 0 auto;
    color: var(--color-primary);
}

.quilt-summary-line-icon svg {
    width: 16px;
    height: 16px;
}

.quilt-summary-total {
    border-top: 0.5px solid var(--color-border);
    margin-top: 6px;
    padding-top: 10px;
    font-weight: 700;
    color: var(--color-text);
    font-size: 16px;
}

/* ---------- Share options (Daily/Classic/Tournament completion) ---------- */
.quilt-share-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quilt-share-option {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--color-primary);
    border-radius: var(--radius-lg);
    background: var(--color-primary-tint);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: filter 0.15s;
}

.quilt-share-option:hover {
    filter: brightness(0.97);
}

.quilt-share-friends {
    border-color: var(--color-success);
    background: #E3F5EE;
}

.quilt-share-option-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.quilt-share-friends .quilt-share-option-icon {
    color: var(--color-success);
}

.quilt-share-option-icon svg {
    width: 22px;
    height: 22px;
}

.quilt-share-option-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quilt-share-option-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--color-primary);
}

.quilt-share-friends .quilt-share-option-title {
    color: var(--color-success);
}

.quilt-share-option-desc {
    font-size: 13px;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

/* Badge + chevron live in their own column on the right, out of the title's text flow, so a long
   title never pushes the badge onto its own visual row underneath. */
.quilt-share-option-side {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    color: var(--color-primary);
}

.quilt-share-friends .quilt-share-option-side {
    color: var(--color-success);
}

.quilt-share-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--color-primary);
    color: white;
    font-size: 12px;
    font-weight: 700;
}

.quilt-share-badge-green {
    background: var(--color-success);
}

.quilt-share-option-side svg {
    width: 18px;
    height: 18px;
}

/* Set by markClaimed() once this specific option's bonus has been awarded -- the other option
   stays fully interactive regardless. */
.quilt-share-option-claimed {
    cursor: default;
    opacity: 0.7;
}

.quilt-share-option-claimed:hover {
    filter: none;
}

.quilt-share-or {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-primary);
    font-weight: 700;
    font-size: 12px;
}

.quilt-share-or::before,
.quilt-share-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* Classic picker: name + size on one line, a short blurb under it. */
.quilt-difficulty-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    text-align: left;
}

.quilt-difficulty-points {
    flex-shrink: 0;
    margin-left: 12px;
    white-space: nowrap;
}

.quilt-difficulty-blurb {
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* Solved picture shown at the top of the summary modal (quilt-summary-modal.js). */
.quilt-summary-picture {
    display: grid;
    width: min(180px, 60%);
    margin: 0 auto 16px;
    aspect-ratio: var(--qt-cols) / var(--qt-rows);
    grid-template-columns: repeat(var(--qt-cols), 1fr);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.quilt-summary-perfect {
    display: block;
    width: fit-content;
    margin: -8px auto 14px;
    padding: 3px 12px;
    border-radius: 999px;
    background: var(--color-primary-tint);
    color: var(--color-primary-dark);
    font-size: 13px;
    font-weight: 700;
}

/* Patchwork Run mosaic: the run's big picture, with later tiles covered and the current one
   highlighted (quilt-page.js#mosaicHtml). */
.quilt-mosaic {
    position: relative;
    width: min(200px, 60%);
    margin: 0 auto 16px;
}

.quilt-mosaic .quilt-summary-picture {
    width: 100%;
    margin: 0;
}

.quilt-mosaic-tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    font-weight: 800;
    font-size: 18px;
    color: var(--color-primary);
}

.quilt-mosaic-locked {
    background: var(--color-primary-tint);
}

.quilt-mosaic-current {
    background: #FDF3C8;
    color: var(--color-primary-dark);
    box-shadow: inset 0 0 0 3px var(--color-primary);
}

/* ---------- How to Play: Quilt-specific mini visuals (shared .htp-* layout is in components.css) */
.htp-mini-quilt {
    position: relative;
    width: 100%;
    max-width: 150px;
    margin: 0 auto;
    cursor: default;
    pointer-events: none;
    border-width: 1.5px;
}

.htp-mini-quilt .qt-clue {
    font-size: 13px;
}

@media (max-width: 420px) {
    .qt-stats {
        padding: 12px 14px;
    }

    .qt-stat-label {
        display: none;
    }
}
