:root {
    --bg-light: #f6f7f8;
    --card-light: #ffffff;
    --text-light: #111827;
    --muted-light: #6b7280;
    --ring-light: #d1d5db;
    --tile-light: #ffffff;
    --tile-border-light: #111827;
    --disc-light: #e5e7eb;
    --bg-dark: #0b0d10;
    --card-dark: #0f1318;
    --text-dark: #e5e7eb;
    --muted-dark: #9aa4b2;
    --ring-dark: #1f2937;
    --tile-dark: #0f1318;
    --tile-border-dark: #e5e7eb;
    --disc-dark: #11161d;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    --bg: #0b0d10;
    --card: #0f1318;
    --text: #e5e7eb;
    --muted: #9aa4b2;
    --ring: #1f2937;
    --tile: #0f1318;
    --tile-border: #e5e7eb;
    --disc: #11161d;
}
body.light {
    --bg: var(--bg-light);
    --card: var(--card-light);
    --text: var(--text-light);
    --muted: var(--muted-light);
    --ring: var(--ring-light);
    --tile: var(--tile-light);
    --tile-border: var(--tile-border-light);
    --disc: var(--disc-light);
}
* {
    box-sizing: border-box;
}
html,
body {
    min-height: 100%;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        Inter,
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    transition:
        background 0.3s,
        color 0.3s;
}
.card {
    width: min(720px, 96vw);
    background: var(--card);
    border: 1px solid var(--ring);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 36px 24px 32px;
}
header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}
h1 {
    margin: 0;
    flex-shrink: 1;
    min-width: 0;
    font:
        800 clamp(18px, 3.2vw, 28px) / 1.1 "Zilla Slab",
        Georgia,
        serif;
}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--ring);
    background: transparent;
    color: var(--text);
    border-radius: 999px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.btn:focus-visible,
.input:focus-visible,
.box:focus-visible,
.clear:focus-visible {
    outline: 2px solid var(--tile-border);
    outline-offset: 2px;
}

.input {
    width: min(420px, 80vw);
    min-width: 220px;
    border: 1.5px solid var(--ring);
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    padding: 12px 14px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-align: center;
    text-transform: uppercase;
    margin-left: auto;
    margin-right: auto;
}
.clear {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.wheel-wrap {
    position: relative;
    margin: 18px auto 8px;
    width: min(540px, 88vw);
    aspect-ratio: 1/1;
}
.wheel {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: grid;
    place-items: center;
}
.mode-outlined .wheel {
    border: 2px dashed var(--ring);
}
.mode-disc .wheel {
    border: 2px solid var(--ring);
    background: var(--disc);
}

.tile {
    position: absolute;
    width: clamp(62px, 13vw, 84px);
    height: clamp(62px, 13vw, 84px);
    display: grid;
    place-items: center;
    background: var(--tile);
    border: 2.5px solid var(--tile-border);
    box-shadow: var(--shadow);
    transform: translate(-50%, -50%);
    user-select: none;
    border-radius: 50%;
    touch-action: none;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
}
.tile:active {
    cursor: grabbing;
}
.mode-disc .tile {
    border: none !important;
    box-shadow: none !important;
    background: transparent;
}

.letter {
    font-family: "Zilla Slab", Georgia, serif;
    font-weight: 600;
    font-size: clamp(52px, 10vw, 78px);
    line-height: 1;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
}
.tile.used .letter {
    color: #4b5563;
}
.tile.used {
    background: #0e1319;
    border-color: var(--ring);
}
.mode-disc .tile.used {
    background: #0e1319;
}

/* Dark outlined mode: lift tile background above card so circles read as shapes */
body.dark.mode-outlined .tile {
    background: #161d28;
}
/* Dark outlined mode used state: restore visible ring and legible muted letter */
body.dark.mode-outlined .tile.used {
    background: #131920;
    border-color: #2d3748;
}
body.dark.mode-outlined .tile.used .letter {
    color: #6b7280;
}

.tile.locked {
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4);
}
.tile.locked::after,
.box.box-locked::after {
    content: "";
    position: absolute;
    pointer-events: none;
    background-color: #f59e0b;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1s3.1 1.39 3.1 3.1v2z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1s3.1 1.39 3.1 3.1v2z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}
.tile.locked::after {
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
}
.box.box-locked::after {
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
}
body.dark .tile.locked {
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.35);
}
.mode-disc .tile.locked {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}
.mode-disc.dark .tile.locked {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
.shuffle {
    width: clamp(70px, 13.5vw, 94px);
    height: clamp(70px, 13.5vw, 94px);
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--tile);
    border: 2px solid var(--tile-border);
    font-weight: 800;
    font-size: clamp(26px, 5.6vw, 34px);
    cursor: grab;
    touch-action: none;
}
.mode-disc .shuffle {
    border: none;
    box-shadow: none;
}
body.dark .shuffle {
    background: #0f141a;
    border-color: var(--tile-border);
    color: var(--text);
    box-shadow:
        0 0 0 2px rgba(229, 231, 235, 0.22),
        var(--shadow);
}
.shuffle.corner-docked {
    position: absolute;
    z-index: 4;
}
.corner-top-left {
    top: 8px;
    left: 8px;
}
.corner-top-right {
    top: 8px;
    right: 8px;
}
.corner-bottom-left {
    bottom: 8px;
    left: 8px;
}
.corner-bottom-right {
    bottom: 8px;
    right: 8px;
}

/* ----------------------------------------------------------
   Centre hold-to-submit: hold a dragged letter over the
   centre for 5s and the shuffle glyph morphs into a tick.
   Dropping on the tick submits the boxes.

   Nothing at all is visible for the first 3s. The ring only
   surfaces at 60% of the hold and fills from there, so a
   casual hold shows nothing: this is an easter egg and the
   affordance should not advertise itself. The 5000ms below
   must stay in step with CENTER_HOLD_MS in the script.
   ---------------------------------------------------------- */
.shuffle {
    padding: 0;
}
.shuffle > * {
    grid-area: 1 / 1;
}
.shuffle-glyph {
    line-height: 1;
}
.shuffle-ring {
    display: none;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
}
.shuffle-ring circle {
    fill: none;
    stroke: var(--muted);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 276;
    stroke-dashoffset: 276;
    opacity: 0;
}
.shuffle.holding .shuffle-ring,
.shuffle.armed .shuffle-ring {
    display: block;
}
.shuffle.holding .shuffle-ring circle {
    animation: aw-center-hold 5000ms linear forwards;
}
.shuffle.armed .shuffle-ring circle {
    opacity: 0.75;
    stroke-dashoffset: 0;
}
/* 60% of 5s is the 3s reveal; the ring fades up over the next
   0.4s and fills at a steady rate to full at 5s. */
@keyframes aw-center-hold {
    0%,
    60% {
        opacity: 0;
        stroke-dashoffset: 276;
    }
    68% {
        opacity: 0.5;
        stroke-dashoffset: 221;
    }
    100% {
        opacity: 0.5;
        stroke-dashoffset: 0;
    }
}
.shuffle-tick {
    display: none;
    width: 46%;
    height: 46%;
    fill: none;
    stroke: var(--text);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.shuffle.armed .shuffle-glyph {
    display: none;
}
.shuffle.armed .shuffle-tick {
    display: block;
}
/* The dragged letter clears out of the tick's way, but on the same
   timeline as the ring, so the hold stays invisible before 3s. */
body.center-holding .drag-ghost {
    animation: aw-center-ghost-fade 5000ms linear forwards;
}
@keyframes aw-center-ghost-fade {
    0%,
    60% {
        opacity: 0.9;
    }
    68%,
    100% {
        opacity: 0.25;
    }
}
body.center-armed .drag-ghost {
    animation: none;
    opacity: 0;
}

/* A miss must never be silent: the boxes shake briefly so the
   person knows the check actually ran. */
@keyframes aw-miss-shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-6px);
    }
    40% {
        transform: translateX(6px);
    }
    60% {
        transform: translateX(-4px);
    }
    80% {
        transform: translateX(4px);
    }
}
@keyframes aw-miss-dim {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}
.boxes.miss {
    animation: aw-miss-shake 340ms ease-in-out;
}
@media (prefers-reduced-motion: reduce) {
    /* No sweeping ring and no shaking: step the progress and
       dim instead, so both still read as feedback. The steps run
       between keyframes, and the whole stretch before the 3s
       reveal is a flat invisible pair, so a stepped ring still
       shows nothing until 3s. */
    .shuffle.holding .shuffle-ring circle {
        animation-timing-function: steps(4, end);
    }
    .boxes.miss {
        animation: aw-miss-dim 420ms ease-in-out;
    }
}
.boxes {
    --box-size: 56px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 16px;
}
.box {
    width: var(--box-size);
    height: var(--box-size);
    border: 2px solid var(--ring);
    border-radius: 0;
    margin-left: -2px;
    background: transparent;
    color: var(--text);
    font:
        800 var(--box-font-size, 28px) / 1 Inter,
        sans-serif;
    text-align: center;
    text-transform: uppercase;
    caret-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
.box:first-child {
    margin-left: 0;
    border-radius: 10px 0 0 10px;
}
.box:last-child {
    border-radius: 0 10px 10px 0;
}
.box:first-child:last-child {
    border-radius: 10px;
}
.box:focus {
    outline: none;
}
.box.filled {
    opacity: 1;
}
.box.selected {
    border-color: var(--text);
    box-shadow: inset 0 0 0 1px var(--text);
    z-index: 1;
    position: relative;
}
.box.box-locked {
    border-color: #f59e0b;
    border-width: 2.5px;
    background: rgba(245, 158, 11, 0.15);
    box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.3);
    z-index: 1;
    position: relative;
}
body.light .box.box-locked {
    background: rgba(245, 158, 11, 0.18);
}
/* Compact boxes for mobile when many letters */
@media (max-width: 480px) {
    .boxes.compact {
        /* 6–8 letters */
        --box-size: 40px;
        --box-font-size: 20px;
    }
    /* tighter for very long words (9–11 letters) */
    .boxes.compact-tight {
        --box-size: 32px;
        --box-font-size: 16px;
    }
    /* ultra compact to fit up to ~12 per row (minimal gaps) */
    .boxes.compact-ultra {
        --box-size: 24px;
        --box-font-size: 12px;
    }
}

/* Help Bubble */
.help-bubble {
    position: fixed;
    bottom: 68px;
    right: 14px;
    width: 280px;
    background: var(--card);
    border: 1px solid var(--ring);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
    z-index: 99;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}
.help-bubble::after {
    content: "";
    position: absolute;
    bottom: -7px;
    right: 17px;
    width: 12px;
    height: 12px;
    background: var(--card);
    border-right: 1px solid var(--ring);
    border-bottom: 1px solid var(--ring);
    transform: rotate(45deg);
}
.help-bubble.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.help-bubble ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.help-bubble li {
    font-size: 13px;
    line-height: 1.45;
    color: var(--text);
    padding-left: 14px;
    position: relative;
}
.help-bubble li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--muted);
}
.help-bubble strong {
    color: var(--text);
    font-weight: 600;
}
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1.5px solid var(--ring);
    background: transparent;
    color: var(--text);
    opacity: 0.6;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition:
        opacity 0.18s,
        border-color 0.18s,
        background 0.18s,
        transform 0.18s;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.icon-btn:hover {
    opacity: 1;
    border-color: color-mix(in srgb, var(--ring) 50%, var(--text));
    background: color-mix(in srgb, transparent 92%, var(--text));
}
.icon-btn:active {
    transform: scale(0.88);
    opacity: 1;
}
#dropAllBtn {
    transition:
        opacity 0.18s,
        border-color 0.18s,
        background 0.18s,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#dropAllBtn.flipped {
    transform: rotate(180deg);
}
#dropAllBtn.flipped:active {
    transform: rotate(180deg) scale(0.9);
}
.help-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid var(--ring);
    background: var(--bg);
    color: var(--muted);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    z-index: 100;
    transition: color 0.15s;
}
.help-btn:hover {
    color: var(--text);
}
.help-btn[aria-expanded="true"] {
    color: var(--text);
}
#shareToast {
    position: fixed;
    top: 72px;
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    background: var(--card);
    border: 1px solid var(--ring);
    border-radius: 999px;
    padding: 7px 16px;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    z-index: 200;
    transition:
        opacity 0.18s ease,
        transform 0.18s ease;
}
#shareToast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
#shareToast .toast-word {
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.04em;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Drag visuals */
.tile.drag-origin {
    opacity: 0.45;
}
.box.drag-origin {
    color: transparent;
}
.drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    width: clamp(62px, 13vw, 84px);
    height: clamp(62px, 13vw, 84px);
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    background: var(--tile);
    border: 2.5px solid var(--tile-border);
    box-shadow: var(--shadow);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.9;
    color: var(--text);
    font-family: "Zilla Slab", Georgia, serif;
    font-weight: 600;
    font-size: clamp(30px, 6.8vw, 42px);
}
.drag-ghost.box-ghost {
    width: var(--box-ghost-width, 56px);
    height: var(--box-ghost-height, 56px);
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    font-family: Inter, sans-serif;
    font-weight: 800;
    font-size: var(--box-ghost-font-size, 28px);
    line-height: 1;
}
.tile.drop-target {
    box-shadow:
        0 0 0 4px #f59e0b,
        var(--shadow);
}
.mode-disc .tile.drop-target {
    box-shadow: 0 0 0 4px #f59e0b;
}
.box.drop-target {
    border-color: #f59e0b;
    box-shadow: inset 0 0 0 3px rgba(245, 158, 11, 0.35);
}

.mode-disc .drag-ghost {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* On a phone the wheel gets the whole first screen and the footer starts
   below it. The 24px is the body's top padding. */
@media (max-width: 600px) {
    .fold {
        min-height: calc(100vh - 24px);
        min-height: calc(100svh - 24px);
    }
}
.site-footer {
    width: min(720px, 96vw);
    margin-top: 20px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}
.site-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}
.site-footer a,
.linklike {
    color: var(--muted);
    text-decoration: none;
}
.site-footer a:hover,
.linklike:hover {
    color: var(--text);
    text-decoration: underline;
}
.linklike {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}
.footer-copy {
    margin-top: 8px;
    opacity: 0.85;
    line-height: 1.5;
}
.consent-banner {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    z-index: 9999;
    width: min(720px, calc(100vw - 24px));
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--ring);
    border-radius: 14px;
    box-shadow: var(--shadow);
}
.consent-banner[hidden] {
    display: none;
}
.consent-inner {
    padding: 16px 18px;
}
.consent-title {
    margin: 0 0 6px;
    font-weight: 800;
    font-size: 15px;
}
.consent-desc {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--muted);
}
.consent-desc a {
    color: var(--text);
}
.consent-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.consent-actions button {
    border-radius: 10px;
    padding: 9px 16px;
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid var(--text);
    background: transparent;
    color: var(--text);
}
