/* Colors as tokens so dark mode (shared/theme.js) only has to swap values. */
:root {
    --bg: #eef2f7;
    --card: #ffffff;
    --text: #1d2433;
    --muted: #5f6b7d;
    --border: #d6deea;
    --cell: #f6f8fb;
    --grid-line: #dfe5ee;
    --accent: #2f5d9e; /* denim: focus, drag preview, active tab */
    --accent-soft: #e2eaf6;
    --wrong: #cf3f3f;
    --wrong-soft: #f8dcdc;
    --blank: #d9dee6;
    --stitch: rgba(255, 255, 255, .9);
    --btn-bg: #1d2433;
    --btn-text: #ffffff;
    --shadow: rgba(29, 36, 51, .08);
    /* Fabrics, one per emoji square in the shared result: 🟨🟥🟩🟦🟪🟧🟫 */
    --f0: #f4c95d;
    --f1: #f29e9e;
    --f2: #a8d5a2;
    --f3: #9cc7ee;
    --f4: #c9b3ec;
    --f5: #f6b38a;
    --f6: #d6b48f;
}

:root[data-theme="dark"] {
    --bg: #11151c;
    --card: #1a2029;
    --text: #e7ecf3;
    --muted: #9aa6b8;
    --border: #2b3442;
    --cell: #151a22;
    --grid-line: #252d39;
    --accent: #86abe3;
    --accent-soft: #23314a;
    --wrong: #f07474;
    --wrong-soft: #3d2124;
    --blank: #2e3644;
    --stitch: rgba(255, 255, 255, .55);
    --btn-bg: #e7ecf3;
    --btn-text: #11151c;
    --shadow: rgba(0, 0, 0, .4);
    --f0: #a8862f;
    --f1: #a85f63;
    --f2: #5e8f5a;
    --f3: #4f7fae;
    --f4: #7d68a8;
    --f5: #a86d47;
    --f6: #8a6d4c;
}

* {
    box-sizing: border-box;
}

/* No double-tap zoom (pinch zoom still works) */
html {
    touch-action: manipulation;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

button {
    font: inherit;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.app {
    max-width: 460px;
    margin: 0 auto;
    padding: 64px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.title {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.title h1 {
    margin: 0;
    font-family: "Silkscreen", "Courier New", monospace;
    font-weight: 400;
    font-size: 34px;
    letter-spacing: .02em;
    text-shadow: 3px 3px 0 var(--accent-soft);
}

.title p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    align-self: center;
}

.tab {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 7px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.tab[aria-selected="true"] {
    background: var(--accent-soft);
    color: var(--text);
}

.status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.timer {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

.timer small {
    font-weight: 500;
    font-size: 13px;
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 6px;
}

.secondary {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
}

.secondary:disabled {
    opacity: .45;
    cursor: default;
}

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

.board {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 2px 10px var(--shadow);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: crosshair;
}

.board:focus {
    outline: none;
}

.board:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.board.done {
    cursor: default;
}

.layer {
    position: absolute;
    inset: 6px;
}

.cells {
    display: grid;
}

.cells div {
    background: var(--cell);
    box-shadow: inset 0 0 0 .5px var(--grid-line);
}

.cells div.clue-cell {
    background: color-mix(in srgb, var(--fab) 38%, var(--cell));
}

.patch {
    position: absolute;
    padding: 2px;
}

.patch-fill {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 9px;
    background: var(--fab);
}

/* The running stitch around each patch */
.patch-fill::after {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 6px;
    border: 2px dashed var(--stitch);
}

.patch.blank .patch-fill {
    background: var(--blank);
}

.patch.bad .patch-fill {
    background: repeating-linear-gradient(135deg, var(--wrong-soft) 0 6px, transparent 6px 12px), var(--fab, var(--blank));
}

.patch.bad .patch-fill::after {
    border-color: var(--wrong);
}

.patch.pop {
    animation: pop .45s ease both;
}

@keyframes pop {
    40% {
        transform: scale(1.06);
    }
}

.overlay,
.clues {
    pointer-events: none;
}

.preview {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px dashed var(--accent);
    border-radius: 9px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.preview span {
    background: var(--accent);
    color: var(--card);
    font-weight: 700;
    font-size: 12px;
    padding: 2px 7px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.cursor {
    position: absolute;
    border: 2.5px solid var(--accent);
    border-radius: 8px;
}

.board:not(:focus-visible) .cursor {
    display: none;
}

.clue {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: 8px;
    border: 2px solid var(--fab);
    background: var(--card);
    color: var(--text);
    font-weight: 800;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 1px 3px var(--shadow);
}

.chip svg {
    display: block;
}

.chip svg rect {
    fill: var(--fab);
    stroke: currentColor;
    stroke-width: 1.6;
}

/* ---------- Finished ---------- */

.win {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    text-align: center;
}

.win h2 {
    margin: 0;
    font-family: "Silkscreen", "Courier New", monospace;
    font-weight: 400;
    font-size: 20px;
}

.win p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.win-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.primary {
    background: var(--btn-bg);
    color: var(--btn-text);
    border: 0;
    border-radius: 10px;
    padding: 9px 16px;
    font-weight: 700;
    cursor: pointer;
}

/* ---------- How to play ---------- */

.howto {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 14px;
    line-height: 1.5;
}

.howto h2 {
    margin: 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

.howto ul {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.legend .chip {
    --fab: var(--f3);
    font-size: 13px;
    font-weight: 600;
}

@media (max-width: 400px) {
    .chip {
        padding: 3px 5px;
        font-size: 13px;
        gap: 3px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .patch.pop {
        animation: none;
    }
}
