/* ─── Word Dash — Daily Puzzle ─────────────────────────────────────── */
:root {
    --bg: #080f1e;
    --purple: #7c5cff;
    --cyan: #22d3ee;
    --green: #10b981;
    --yellow: #f59e0b;
    --grey: #263551;
    --text: #f0f5ff;
    --muted: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(148, 163, 184, 0.18);
    --glass-blur: blur(14px);
    --tile-size: clamp(42px, 12vw, 62px);
    --tile-gap: 6px;
}

/* The global reset + box-sizing + safe-area tokens now live in
   /css/fundash-base.css. This file only keeps word-dash specific bits. */

html, body { height: 100%; }

body {
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 90% 55% at 10% -8%,  rgba(91, 94, 255, 0.2),  transparent 60%),
        radial-gradient(ellipse 65% 45% at 92% 110%, rgba(34, 211, 238, 0.14), transparent 55%),
        radial-gradient(ellipse 55% 38% at 50% 50%,  rgba(91, 94, 255, 0.05),  transparent 70%);
    font-family: 'Lexend', 'Inter', system-ui, -apple-system, sans-serif;
    /* Lock document to one viewport — the ONLY scroll region is .wd-board */
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

/* ─── Fixed-viewport grid shell: header / status / board(scroll) / action / keyboard.
   The board takes 1fr with its own overflow-y so a tall 6-row grid scrolls INTERNALLY
   and the keyboard is always pinned above the safe-area-inset-bottom, never
   below the viewport. */
.wd-app {
    display: grid;
    grid-template-rows: auto auto 1fr auto auto;
    height: 100dvh;
    max-height: 100dvh;
    /* top/left/right safe-area is applied by fundash-monetag's .game-container
       injection; we only own bottom padding here to avoid doubling. */
    padding: 0.5rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom));
    max-width: 480px;
    margin: 0 auto;
    overflow: hidden;
}

/* ─── Header ───────────────────────────────────────────────────────── */
.wd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.4rem 0.75rem;
    padding-left: 56px;
    flex-wrap: wrap;
    min-width: 0;
}
.wd-header > .fd-wallet-bar {
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
}

.wd-brand {
    display: inline-flex;
    align-self: flex-start;
    line-height: 0;
    text-decoration: none;
}

.wd-title {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}
.wd-title strong {
    display: block;
    font-size: 1rem;
    color: var(--cyan);
    letter-spacing: 0.14em;
    text-shadow: 0 0 12px rgba(0, 212, 255, 0.45);
}

/* ─── Status strip ─────────────────────────────────────────────────── */
.wd-status-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    padding: 0.5rem 0.75rem;
    margin: 0 0.25rem 0.6rem;
    border-radius: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    font-size: 0.78rem;
    color: var(--muted);
    min-height: 32px;
    text-align: center;
}
.wd-status-strip strong {
    color: var(--yellow);
    font-weight: 800;
    letter-spacing: 0.04em;
}
.wd-status-strip .wd-status-accent-win { color: var(--green); }
.wd-status-strip .wd-status-accent-lose { color: #ff6b9a; }

/* ─── Board ────────────────────────────────────────────────────────── */
.wd-board {
    /* Grid cell takes 1fr inside .wd-app; min-height:0 lets the row shrink
       below its intrinsic content on short phones, and overflow-y lets the
       6 rows scroll internally if they can't all fit. */
    min-height: 0;
    align-self: stretch;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: grid;
    grid-template-rows: repeat(6, var(--tile-size));
    gap: var(--tile-gap);
    justify-content: center;
    /* `safe start` avoids cropping row 1 when the 6-row grid is just barely
       taller than the 1fr cell. `align-content: center` previously centered
       the grid inside the cell, which pushed row 1 above the scroll region
       on iPhone-class viewports so users couldn't see their first guess. */
    align-content: safe start;
    margin: 0.4rem auto 0.6rem;
    padding: 0.25rem 0;
    touch-action: pan-y;
    perspective: 900px;
}

.wd-row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, var(--tile-size));
    gap: var(--tile-gap);
    isolation: isolate;
}

/* Lower rows stack above earlier rows so 3D-flipped tiles cannot steal taps */
.wd-board > .wd-row:nth-child(1) { z-index: 1; }
.wd-board > .wd-row:nth-child(2) { z-index: 2; }
.wd-board > .wd-row:nth-child(3) { z-index: 3; }
.wd-board > .wd-row:nth-child(4) { z-index: 4; }
.wd-board > .wd-row:nth-child(5) { z-index: 5; }
.wd-board > .wd-row:nth-child(6) { z-index: 6; }

.wd-tile {
    width: var(--tile-size);
    height: var(--tile-size);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: clamp(1.2rem, 5vw, 1.7rem);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.025);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition:
        background 0.3s ease,
        border-color 0.3s ease,
        color 0.3s ease;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    user-select: none;
}

.wd-tile.wd-has-letter:not(.wd-flipping) {
    border-color: rgba(255, 255, 255, 0.35);
    animation: wd-pop 0.14s ease-out;
}

.wd-tile.wd-flipping {
    animation: wd-flip 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes wd-flip {
    0%   { transform: rotateX(0deg); }
    50%  { transform: rotateX(-90deg); }
    100% { transform: rotateX(0deg); }
}

.wd-tile.wd-hinted {
    background: rgba(155, 92, 255, 0.22);
    border-color: rgba(155, 92, 255, 0.65);
    color: #fff;
    box-shadow: 0 0 12px rgba(155, 92, 255, 0.35);
}

/* Flip-applied color states — because transform flips the tile to show */
/* back side, we set the state mid-animation in JS (at 0.27s) and reset */
/* transform at 0.55s.                                                   */
.wd-tile.wd-state-correct {
    background: linear-gradient(180deg, #00e57a, #00b862);
    border-color: rgba(0, 229, 122, 0.9);
    color: #021808;
    box-shadow: 0 0 14px rgba(0, 229, 122, 0.25);
}
.wd-tile.wd-state-present {
    background: linear-gradient(180deg, #ffcc00, #d9a806);
    border-color: rgba(255, 204, 0, 0.9);
    color: #1e1500;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.22);
}
.wd-tile.wd-state-absent {
    background: #2a2840;
    border-color: #3b3955;
    color: #b5abcf;
}

.wd-row.wd-invalid .wd-tile {
    animation: wd-shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes wd-pop {
    0%   { transform: scale(0.9); }
    100% { transform: scale(1); }
}
@keyframes wd-shake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-6px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

/* ─── Hint + coin chip ─────────────────────────────────────────────── */
.wd-action-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin: 0.15rem auto 0.6rem;
    flex-wrap: wrap;
}

.wd-coin-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    background: rgba(255, 204, 0, 0.1);
    border: 1px solid rgba(255, 204, 0, 0.3);
    color: var(--yellow);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.wd-hint-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.95rem;
    min-height: 44px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #f3efff;
    background: linear-gradient(135deg, rgba(155, 92, 255, 0.55), rgba(0, 212, 255, 0.45));
    border: 1px solid rgba(0, 212, 255, 0.4);
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s ease;
    box-shadow: 0 0 18px rgba(0, 212, 255, 0.22);
    touch-action: manipulation;
}
.wd-hint-btn:hover { box-shadow: 0 0 28px rgba(155, 92, 255, 0.4); }
.wd-hint-btn:active { transform: scale(0.96); }
.wd-hint-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}
.wd-hint-btn svg {
    width: 14px;
    height: 14px;
}

/* ─── Keyboard ─────────────────────────────────────────────────────── */
/* Grid locks this to the last row — no margin-top:auto hack, no possibility
   of falling below the viewport, always reachable above safe-area-bottom. */
.wd-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0.4rem 0.2rem 0.15rem;
    touch-action: none;
}

.wd-kb-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.wd-key {
    flex: 1;
    min-width: 0;
    max-width: 42px;
    height: 52px;
    display: grid;
    place-items: center;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 7px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease, transform 0.1s ease;
    touch-action: manipulation;
    padding: 0;
}
.wd-key:hover { background: rgba(255, 255, 255, 0.12); }
.wd-key:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.18); }

.wd-key-wide {
    flex: 1.5;
    max-width: 66px;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
}

.wd-key.wd-kb-correct {
    background: linear-gradient(180deg, #00e57a, #00b862);
    border-color: rgba(0, 229, 122, 0.9);
    color: #021808;
}
.wd-key.wd-kb-present {
    background: linear-gradient(180deg, #ffcc00, #d9a806);
    border-color: rgba(255, 204, 0, 0.9);
    color: #1e1500;
}
.wd-key.wd-kb-absent {
    background: #2a2840;
    border-color: #3b3955;
    color: #6e6786;
}

/* ─── Toast / inline messages ──────────────────────────────────────── */
.wd-toast {
    position: fixed;
    left: 50%;
    top: 20%;
    transform: translateX(-50%);
    z-index: 220000;
    padding: 0.7rem 1.1rem;
    border-radius: 12px;
    background: rgba(16, 14, 32, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #f8fafc;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    animation: wd-toast-in 0.2s ease-out;
}
.wd-toast.wd-toast-error { border-color: rgba(255, 107, 154, 0.45); color: #ffd1e0; }
.wd-toast.wd-toast-win   { border-color: rgba(0, 229, 122, 0.6); }
.wd-toast.wd-toast-lose  { border-color: rgba(255, 107, 154, 0.6); }

@keyframes wd-toast-in {
    from { opacity: 0; transform: translate(-50%, -12px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Result overlay (win / next-word countdown) ──────────────────── */
/* Mobile: bottom-sheet — docks to the bottom edge so the user's thumb is
   already over the action buttons. Desktop (>= 640px): centered card. */
.wd-result-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    z-index: 230000;
    background: rgba(6, 8, 18, 0.6);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 0;
    overflow: hidden;
}
.wd-result-overlay.wd-open { display: flex; animation: wd-fade-in 0.25s ease; }

.wd-result-card {
    /* min-width:0 so flex item can shrink below intrinsic content */
    min-width: 0;
    width: 100%;
    max-width: 540px;
    max-height: 90dvh;
    margin-inline: auto;
    flex-shrink: 0;
    box-sizing: border-box;
    background: linear-gradient(165deg, rgba(32, 28, 58, 0.92), rgba(14, 12, 28, 0.96));
    border: 1px solid rgba(155, 92, 255, 0.4);
    border-bottom: 0;
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 1.5rem 1.35rem calc(1.25rem + env(safe-area-inset-bottom));
    text-align: center;
    color: #f6f3ff;
    box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.55), 0 0 36px rgba(155, 92, 255, 0.22);
    animation: wd-sheet-in 0.36s cubic-bezier(0.2, 0.85, 0.3, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    position: relative;
}
.wd-result-card::before {
    content: "";
    position: sticky;
    top: 0.35rem;
    display: block;
    margin: -0.6rem auto 0.75rem;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.26);
    z-index: 2;
}

@media (min-width: 640px) {
    .wd-result-overlay {
        align-items: center;
        justify-content: center;
        padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
    }
    .wd-result-card {
        max-width: min(420px, 100%);
        max-height: 86dvh;
        border: 1px solid rgba(155, 92, 255, 0.4);
        border-radius: 22px;
        padding: 1.5rem 1.35rem 1.25rem;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 36px rgba(155, 92, 255, 0.22);
        animation: wd-card-in 0.32s cubic-bezier(0.2, 0.85, 0.3, 1);
    }
    .wd-result-card::before { display: none; }
}

@keyframes wd-sheet-in {
    from { opacity: 0; transform: translateY(22px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wd-result-title {
    font-size: 1.35rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    margin-bottom: 0.45rem;
}
.wd-result-title.wd-win  { color: var(--green); }
.wd-result-title.wd-lose { color: #ff6b9a; }

.wd-result-word {
    font-family: 'Orbitron', 'Lexend', sans-serif;
    font-size: 1.9rem;
    font-weight: 900;
    letter-spacing: clamp(0.06em, 1.8vw, 0.2em);
    color: #fff;
    margin: 0.35rem 0 0.85rem;
    text-shadow: 0 0 22px rgba(0, 212, 255, 0.4);
    max-width: 100%;
    overflow-wrap: anywhere;
}

.wd-result-prize {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-width: 100%;
    margin-bottom: 1rem;
    padding: 0.55rem 1.05rem;
    border-radius: 999px;
    background: rgba(255, 204, 0, 0.14);
    border: 1px solid rgba(255, 204, 0, 0.42);
    color: var(--yellow);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.wd-result-sub {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 0.85rem;
}

.wd-result-balance-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin: 0.35rem auto 1rem;
    padding: 0.75rem 1.15rem;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(0, 212, 255, 0.14), rgba(155, 92, 255, 0.12));
    border: 1px solid rgba(0, 212, 255, 0.5);
    box-shadow: 0 0 18px rgba(0, 212, 255, 0.25), inset 0 0 12px rgba(155, 92, 255, 0.1);
    color: #fff;
    min-width: 200px;
}
.wd-result-balance-label {
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #c9d7ff;
    opacity: 0.9;
}
.wd-result-balance-value {
    font-family: 'Orbitron', 'Lexend', system-ui, monospace;
    font-weight: 900;
    font-size: 2.1rem;
    line-height: 1;
    color: #ffffff;
    text-shadow: 0 0 12px rgba(0, 212, 255, 0.9), 0 0 22px rgba(155, 92, 255, 0.65);
    font-variant-numeric: tabular-nums;
    min-width: 2.5ch;
    text-align: center;
    transition: color 0.25s ease, text-shadow 0.25s ease;
}
.wd-result-balance-unit {
    font-size: 0.7rem;
    letter-spacing: 0.22em;
    color: #a7b8ff;
    text-transform: uppercase;
}

.wd-countdown-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    margin-bottom: 0.25rem;
}
.wd-countdown-value {
    font-family: 'Orbitron', 'Lexend', system-ui, monospace;
    font-size: 1.7rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    color: var(--cyan);
    margin-bottom: 1rem;
    font-variant-numeric: tabular-nums;
}

.wd-result-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.wd-result-btn {
    width: 100%;
    padding: 0.85rem 1rem;
    min-height: 46px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: #fff;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: linear-gradient(135deg, #9b5cff 0%, #00d4ff 100%);
    box-shadow: 0 10px 30px rgba(155, 92, 255, 0.3);
    transition: transform 0.1s ease, box-shadow 0.18s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.wd-result-btn:active { transform: scale(0.97); }
.wd-result-btn.wd-result-btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: none;
    color: var(--text);
}

@keyframes wd-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes wd-card-in {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Responsive ───────────────────────────────────────────────────── */
/* iPhone SE / Galaxy S8 mini baseline. Short heights shrink the tile so
   the full 6-row board can fit without internal scroll when possible. */
@media (max-height: 720px) {
    :root { --tile-size: clamp(36px, 9.5vw, 52px); }
    .wd-key { height: 46px; font-size: 0.95rem; }
    .wd-header { padding-top: 0.2rem; padding-bottom: 0.35rem; }
}
@media (max-height: 680px) {
    :root { --tile-size: clamp(34px, 8.5vw, 48px); --tile-gap: 5px; }
    .wd-board { margin: 0.2rem auto 0.35rem; }
}

@media (max-width: 360px) {
    :root { --tile-size: clamp(34px, 13vw, 48px); --tile-gap: 5px; }
    .wd-key { max-width: 34px; height: 46px; font-size: 0.88rem; }
    .wd-key-wide { max-width: 54px; font-size: 0.6rem; }
    .wd-title { font-size: 0.72rem; }
    .wd-title strong { font-size: 0.88rem; }
}

@media (max-height: 620px) {
    .wd-status-strip { display: none; }
    .wd-action-row { margin: 0 auto 0.25rem; }
    .wd-board { margin: 0.1rem auto 0.25rem; }
    .wd-key { height: 44px; }
}
