/* ==========================================================================
   Writing Stars theme — orange ink on paper, plus the selectors only this
   game uses.

   Loaded after game-core.css, so the :root declarations win on source order
   and re-point the legacy --ss-* aliases too. The structural tokens stay as
   game-core defines them; only the three identity tokens change, exactly as
   the other game themes do.

   Everything below the token block is a .ws-* selector this game owns.
   ========================================================================== */

:root {
    --game-accent: #EF6C00;
    --game-accent-light: #FFA040;
    /* The family's gold star, unchanged across every game. */
    --game-highlight: #D4A017;
}

/* ---------- Reds game-core hardcoded (see times-stars.css for why) ---------- */
.ss-input:focus {
    box-shadow: 0 0 0 3px rgba(239, 108, 0, 0.35);
}

.ss-btn-primary:hover {
    background-color: #D65D00;
    box-shadow: 0 4px 15px rgba(239, 108, 0, 0.45);
}

.mc-option.wrong {
    background-color: rgba(239, 108, 0, 0.30);
}

.ss-error {
    background-color: rgba(239, 108, 0, 0.18);
}

.week-selector:focus {
    box-shadow: 0 0 0 3px rgba(239, 108, 0, 0.35);
}

/* No pull-to-refresh or rubber-banding while a finger is on the page: the
   stage itself is touch-action: none, and this stops the gesture that starts
   just outside it from yanking the letter away. */
html, body {
    overscroll-behavior-y: none;
}

/* ---------- Shared focus ring ---------- */
.ws-btn:focus-visible,
.ws-icon-btn:focus-visible,
.ws-pick:focus-visible,
.ws-door:focus-visible,
.ws-style-btn:focus-visible,
.ws-word-btn:focus-visible {
    outline: 3px solid var(--game-highlight);
    outline-offset: 2px;
}

/* ---------- Screen scaffolding ----------
   On phones game-core makes #game-app a 100dvh column flexbox and .ss-screen a
   column flexbox with flex: 1 — but the router's #ss-screen-content wrapper
   between them is a plain block, so .ss-screen never actually stretches. The
   round-based games don't mind (their keyboards use margin-top: auto); the
   tracing stage must fill the space left over, so on this page the wrapper
   joins the flex chain. .ws-scroll is the part that scrolls; the stage is the
   part that grows. */
@media (max-width: 767.98px) {
    #ss-screen-content {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
    }
}

.ws-screen {
    position: relative;
}

.ws-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
}

.ws-topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0 0.5rem;
    flex-shrink: 0;
}

.ws-title {
    flex: 1 1 auto;
    margin: 0;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.ws-topbar-spacer {
    display: inline-block;
    width: 48px;
    flex-shrink: 0;
}

.ws-icon-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1.5px solid var(--game-border);
    background-color: var(--game-surface);
    color: var(--game-muted);
    font-size: 1.1rem;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, transform 0.1s;
}

.ws-icon-btn:hover {
    color: var(--game-text);
    border-color: var(--game-text);
}

.ws-icon-btn:active {
    transform: scale(0.94);
}

.ws-icon-btn.speaking {
    color: var(--game-highlight);
    border-color: var(--game-highlight);
    animation: audioPulse 0.6s ease-in-out infinite alternate;
}

.ws-subtle {
    font-size: 0.85rem;
}

/* ---------- Home ---------- */
.ws-home-header {
    padding: 1rem 0 0.5rem;
}

.ws-home-sub {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
}

.ws-home-grid {
    margin-top: 0.75rem;
}

.ws-door {
    position: relative;
    min-height: 150px;
}

.ws-door-preview {
    display: block;
    height: 56px;
    margin: 0 auto 0.5rem;
    color: var(--game-accent);
}

.ws-door-locked .ws-door-preview {
    opacity: 0.45;
}

.ws-door-lock {
    position: absolute;
    top: 0.6rem;
    right: 0.7rem;
    font-size: 0.9rem;
    color: var(--game-muted);
}

/* The door previews are small; keep the mode-card icon rule from bleeding in. */
.ws-door i.ws-door-lock {
    font-size: 0.9rem;
    margin: 0;
}

.ws-class-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem 0.75rem;
    margin-top: 1rem;
}

.ws-class-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 2rem;
    background-color: var(--game-surface);
    border: 1px solid var(--game-border);
    font-weight: 600;
    font-size: 0.9rem;
}

.ws-class-chip i {
    color: var(--game-accent-light);
}

.ws-link {
    color: var(--game-muted);
    text-decoration: underline;
    font-size: 0.85rem;
    padding: 0.5rem 0.25rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.ws-link:hover {
    color: var(--game-text);
}

.ws-join-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* ---------- Print / Cursive switch ---------- */
.ws-style-toggle {
    display: flex;
    justify-content: center;
    gap: 0;
    margin: 0 auto 0.5rem;
    max-width: 320px;
    border: 2px solid var(--game-border);
    border-radius: 2rem;
    overflow: hidden;
    background-color: var(--game-card);
    flex-shrink: 0;
}

.ws-style-btn {
    flex: 1 1 50%;
    min-height: 48px;
    border: none;
    background: none;
    color: var(--game-muted);
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color 0.15s, color 0.15s;
}

.ws-style-btn.active {
    background-color: var(--game-accent);
    color: #ffffff;
}

.ws-style-toggle-compact {
    max-width: 260px;
}

.ws-style-toggle-compact .ws-style-btn {
    min-height: 44px;
    font-size: 0.9rem;
}

/* ---------- Picker grid ---------- */
.ws-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 0.5rem;
    padding: 0.25rem 0 0.5rem;
}

.ws-pick {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 76px;
    padding: 0.5rem 0.25rem;
    background-color: var(--game-card);
    border: 2px solid var(--game-border);
    border-radius: 0.875rem;
    color: var(--game-accent);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.ws-pick:hover {
    border-color: var(--game-accent);
}

.ws-pick:active {
    transform: scale(0.95);
}

.ws-pick-text {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--game-text);
}

/* ---------- SVG previews (picker, home) ---------- */
.ws-preview {
    display: block;
    max-width: 100%;
    overflow: visible;
}

.ws-preview-line {
    stroke: rgba(255, 255, 255, 0.14);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.ws-preview-baseline {
    stroke: rgba(255, 255, 255, 0.28);
}

.ws-preview-stroke {
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ws-preview-dot {
    fill: currentColor;
}

/* ---------- The stage: paper, roads, ink ----------
   The canvas reads these custom properties, so the paper can be re-coloured
   here without touching the engine. */
.ws-stage {
    --ws-paper: #FBF7EE;
    --ws-line: #8FB3DD;
    --ws-midline: #D98C8C;
    --ws-descender: #CBD6E4;
    --ws-road: rgba(60, 45, 20, 0.09);
    --ws-road-active: rgba(60, 45, 20, 0.17);
    --ws-road-done: rgba(60, 45, 20, 0.05);
    --ws-centerline: rgba(60, 45, 20, 0.42);
    --ws-ink: #EF6C00;
    --ws-ink-done: #B45309;
    --ws-ink-demo: #6D4FC2;
    --ws-start: #39B54A;
    --ws-badge: #3a3a3a;
    --ws-badge-text: #ffffff;
    --ws-entry: #1565C0;
    --ws-exit: #C62828;
    --ws-upcoming-dot: rgba(60, 45, 20, 0.3);

    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--ws-paper);
    border-radius: 1rem;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.ws-layer {
    position: absolute;
    inset: 0;
    display: block;
}

.ws-layer-live {
    cursor: crosshair;
}

.ws-stage-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 0.5rem;
}

/* Finished-glyph banner: a slim strip in the controls' slot, under the
   paper, so the letter stays fully visible. The Next button in the nav row
   lights up at the same time; nothing advances on its own. */
.ws-done-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    min-height: 48px;
    padding: 0.25rem 0.6rem;
    border-radius: 0.875rem;
    background-color: rgba(212, 160, 23, 0.12);
    border: 2px solid var(--game-highlight);
    flex-shrink: 0;
    animation: fadeIn 0.25s ease-out;
}

.ws-done-bar[hidden],
.ws-controls[hidden] {
    display: none;
}

.ws-done-stars {
    font-size: 1.35rem;
    letter-spacing: 0.1em;
    color: var(--game-border);
    white-space: nowrap;
}

.ws-done-stars .earned,
.ws-stars .earned {
    color: var(--game-highlight);
    text-shadow: 0 0 14px rgba(212, 160, 23, 0.6);
}

.ws-done-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
}

.ws-btn-again {
    flex-shrink: 0;
}

/* The lit-up Next button once a letter or word is finished. Two classes so it
   outranks .ws-btn, which is declared later in this file. */
.ws-btn.ws-btn-ready {
    background-color: var(--game-accent);
    border-color: var(--game-accent);
    color: #ffffff;
    animation: wsReady 0.9s ease-in-out 3;
}

.ws-btn.ws-btn-ready i {
    color: #ffffff;
}

@keyframes wsReady {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.07); }
}

/* ---------- Controls under the stage ---------- */
.ws-controls,
.ws-nav-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.ws-nav-row {
    justify-content: space-between;
    margin-top: 0.5rem;
}

.ws-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 48px;
    min-width: 48px;
    padding: 0.6rem 1rem;
    border-radius: 0.875rem;
    border: 2px solid var(--game-border);
    background-color: var(--game-card);
    color: var(--game-text);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background-color 0.15s, transform 0.1s;
}

.ws-btn:hover {
    border-color: var(--game-accent);
}

.ws-btn:active {
    transform: scale(0.96);
}

.ws-btn i {
    color: var(--game-accent-light);
}

.ws-btn-icon {
    padding: 0.6rem 0.8rem;
}

.ws-btn-icon.active {
    border-color: var(--game-accent);
    background-color: rgba(239, 108, 0, 0.18);
}

.ws-btn-nav {
    flex: 0 0 auto;
}

.ws-stars {
    font-size: 1.4rem;
    letter-spacing: 0.12em;
    color: var(--game-border);
    min-width: 3.5em;
    text-align: center;
}

.ws-word-count {
    text-align: center;
}

/* ---------- Word title: the active letter ---------- */
.ws-title-word {
    letter-spacing: 0.12em;
    font-size: 1.6rem;
}

.ws-word-letter {
    color: var(--game-muted);
    transition: color 0.2s;
}

.ws-word-letter.is-active {
    color: var(--game-accent-light);
    text-decoration: underline;
    text-decoration-thickness: 3px;
    text-underline-offset: 4px;
}

.ws-word-letter.is-done {
    color: var(--game-text);
}

/* ---------- Words list ---------- */
.ws-word-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
    padding-bottom: 0.5rem;
}

.ws-word-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 56px;
    padding: 0.6rem 0.75rem;
    background-color: var(--game-card);
    border: 2px solid var(--game-border);
    border-radius: 0.875rem;
    color: var(--game-text);
    font-family: 'Montserrat', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.ws-word-btn:hover {
    border-color: var(--game-accent);
}

.ws-word-btn:active {
    transform: scale(0.97);
}

.ws-word-bonus {
    color: var(--game-highlight);
    font-size: 0.8rem;
}

/* ---------- Prompt cards (join, coming soon) ---------- */
.ws-prompt-card {
    padding: 2rem 1.5rem;
    max-width: 420px;
    margin: 1rem auto;
}

.ws-prompt-icon {
    font-size: 2.5rem;
    color: var(--game-highlight);
    margin-bottom: 0.5rem;
}

.ws-prompt-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

/* ---------- Layout by viewport ---------- */
@media (min-width: 768px) {
    /* .ss-screen is a plain block on desktop, so the stage needs a height. */
    .ws-stage-wrap {
        height: min(60vh, 540px);
    }

    .ws-title {
        font-size: 1.6rem;
    }
}

@media (max-width: 767.98px) {
    .ws-home-header {
        padding: 0.5rem 0 0.25rem;
    }

    .ws-home-header .star-icon {
        font-size: 1.5rem;
    }

    .ws-door {
        min-height: 128px;
        padding: 0.9rem 0.5rem;
    }

    .ws-door-preview {
        height: 46px;
    }

    .ws-stage-wrap {
        min-height: 200px;
    }

    .ws-btn {
        padding: 0.55rem 0.75rem;
        font-size: 0.85rem;
    }

    .ws-done-text {
        font-size: 0.9rem;
    }

    .ws-done-stars {
        font-size: 1.15rem;
    }
}

/* Landscape phones: there is no room under the paper, so the controls move
   beside it — the stage takes the left, the buttons stack on the right. */
@media (max-width: 991.98px) and (max-height: 480px) and (orientation: landscape) {
    .ws-trace-screen {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "top top"
            "stage controls"
            "stage nav";
        column-gap: 0.5rem;
        row-gap: 0.25rem;
        min-height: 0;
    }

    .ws-trace-screen .ws-topbar {
        grid-area: top;
        padding: 0 0 0.25rem;
    }

    .ws-trace-screen .ws-stage-wrap {
        grid-area: stage;
        height: auto;
        min-height: 150px;
        margin-bottom: 0;
    }

    /* The right column is short, so: Show me on its own line, Restart and the
       stroke-number toggle side by side, Prev and Next side by side. The
       finished banner takes the controls' slot and stacks its three pieces. */
    .ws-trace-screen .ws-controls {
        grid-area: controls;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
        align-content: start;
    }

    .ws-trace-screen .ws-controls[hidden] {
        display: none;
    }

    .ws-trace-screen .ws-controls .ws-btn:first-child {
        grid-column: 1 / -1;
    }

    .ws-trace-screen .ws-done-bar {
        grid-area: controls;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 0.4rem;
        align-self: start;
    }

    .ws-trace-screen .ws-nav-row {
        grid-area: nav;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-top: 0;
    }

    .ws-trace-screen .ws-btn {
        justify-content: center;
    }

    /* The banner shows the stars; the small copy in the nav row is noise here. */
    .ws-trace-screen .ws-nav-row .ws-stars {
        display: none;
    }

    .ws-trace-screen .ws-word-count {
        flex-basis: 100%;
        order: 3;
        text-align: center;
    }

    .ws-title {
        font-size: 1.1rem;
    }

    .ws-icon-btn {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 359.98px) {
    .ws-btn {
        padding: 0.5rem 0.55rem;
        font-size: 0.8rem;
        gap: 0.3rem;
    }

    .ws-picker-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .ws-btn,
    .ws-icon-btn,
    .ws-pick,
    .ws-word-btn,
    .ws-style-btn,
    .ws-word-letter {
        transition: none;
    }

    .ws-btn:active,
    .ws-icon-btn:active,
    .ws-pick:active,
    .ws-word-btn:active {
        transform: none;
    }

    .ws-icon-btn.speaking,
    .ws-done-bar,
    .ws-btn.ws-btn-ready {
        animation: none;
    }
}
