/* ================================================
   Wordo — CSS (pairs with ui-shared.css)
   ================================================ */

/* ---------- colour tokens ---------- */
:root {
    --wo-correct: #22c55e;
    --wo-present: #eab308;
    --wo-absent-dark: #3a3a3c;
    --wo-absent-light: #787c7e;
    --wo-key-bg-dark: #818384;
    --wo-key-bg-light: #d3d6da;
    --wo-tile-border-dark: rgba(255,255,255,0.18);
    --wo-tile-border-light: rgba(0,0,0,0.15);
    --wo-tile-filled-border-dark: rgba(255,255,255,0.35);
    --wo-tile-filled-border-light: rgba(0,0,0,0.30);
}

/* ---------- layout ---------- */
.wo-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 4px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* ---------- board ---------- */
.wo-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    width: min(350px, 100%);
    aspect-ratio: 5 / 6;
}

.wo-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
}

.wo-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
    font-size: clamp(1.4rem, 5vw, 2rem);
    font-weight: 700;
    text-transform: uppercase;
    border: 2px solid var(--wo-tile-border-dark);
    border-radius: 6px;
    background: transparent;
    color: var(--text-dark);
    transition: border-color 0.12s ease, transform 0.1s ease;
    aspect-ratio: 1;
}

body.light-mode .wo-tile {
    border-color: var(--wo-tile-border-light);
    color: var(--text-light);
}

/* filled (typed but not revealed) */
.wo-tile.filled {
    border-color: var(--wo-tile-filled-border-dark);
    animation: pop 0.1s ease;
}

body.light-mode .wo-tile.filled {
    border-color: var(--wo-tile-filled-border-light);
}

/* revealed states */
.wo-tile.correct {
    background: var(--wo-correct);
    border-color: var(--wo-correct);
    color: #fff;
}

.wo-tile.present {
    background: var(--wo-present);
    border-color: var(--wo-present);
    color: #fff;
}

.wo-tile.absent {
    background: var(--wo-absent-dark);
    border-color: var(--wo-absent-dark);
    color: #fff;
}

body.light-mode .wo-tile.absent {
    background: var(--wo-absent-light);
    border-color: var(--wo-absent-light);
}

/* ---------- animations ---------- */
@keyframes pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

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

.wo-tile.flip {
    animation: flipIn 0.5s ease forwards;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 50%, 90% { transform: translateX(-4px); }
    30%, 70% { transform: translateX(4px); }
}

.wo-row.shake {
    animation: shake 0.4s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    40%  { transform: translateY(-20px); }
    60%  { transform: translateY(-10px); }
}

/* ---------- hint bar ---------- */
.wo-hint-bar {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 2px 0;
}

.wo-btn-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid var(--border-dark);
    background: var(--surface-strong-dark);
    color: var(--muted-dark);
    cursor: not-allowed;
    opacity: 0.6;
    transition: all 0.2s ease;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

body.light-mode .wo-btn-hint {
    border-color: var(--border-light);
    background: var(--surface-strong-light);
    color: var(--muted-light);
}

.wo-btn-hint.unlocked {
    opacity: 1;
    cursor: pointer;
    background: color-mix(in srgb, #eab308 20%, var(--surface-strong-dark));
    border-color: #eab308;
    color: #fef08a;
    box-shadow: 0 0 10px rgba(234, 179, 8, 0.25);
    animation: hintPulse 2.2s infinite ease-in-out;
}

body.light-mode .wo-btn-hint.unlocked {
    background: color-mix(in srgb, #ca8a04 18%, var(--surface-strong-light));
    border-color: #ca8a04;
    color: #854d0e;
    box-shadow: 0 0 10px rgba(202, 138, 4, 0.25);
}

.wo-btn-hint.unlocked:active {
    transform: scale(0.96);
}

.wo-btn-hint.used {
    opacity: 0.45;
    cursor: default;
    border-color: transparent;
    animation: none;
}

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

/* ---------- on-screen keyboard ---------- */
.wo-keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 500px;
    padding: 0 2px;
    touch-action: none;
}

.wo-kb-row {
    display: flex;
    gap: 5px;
    width: 100%;
    justify-content: center;
}

.wo-key {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 52px;
    min-width: 30px;
    flex: 1;
    max-width: 44px;
    border-radius: 6px;
    border: none;
    background: var(--wo-key-bg-dark);
    color: #fff;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

body.light-mode .wo-key {
    background: var(--wo-key-bg-light);
    color: var(--text-light);
}

.wo-key:active {
    transform: scale(0.94);
}

.wo-key.wide {
    flex: 1.5;
    max-width: 66px;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
}

.wo-key.correct {
    background: var(--wo-correct);
    color: #fff;
}

.wo-key.present {
    background: var(--wo-present);
    color: #fff;
}

.wo-key.absent {
    background: var(--wo-absent-dark);
    color: #999;
    opacity: 0.65;
}

body.light-mode .wo-key.absent {
    background: var(--wo-absent-light);
    color: #fff;
    opacity: 0.65;
}

/* ---------- toast ---------- */
.wo-toast-wrap {
    position: fixed;
    top: calc(var(--app-header-offset, 64px) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.wo-toast {
    background: var(--surface-dark);
    color: var(--text-dark);
    border: 1px solid var(--border-dark);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    opacity: 0;
    animation: toastIn 0.2s ease forwards;
    pointer-events: auto;
    backdrop-filter: blur(10px);
}

body.light-mode .wo-toast {
    background: var(--surface-light);
    color: var(--text-light);
    border-color: var(--border-light);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wo-toast.fade-out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* ---------- next-word bar ---------- */
.wo-endbar {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 0;
    width: 100%;
}

.wo-endbar.visible {
    display: flex;
}

.wo-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}

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

.wo-btn-primary {
    background: var(--wo-correct);
    color: #fff;
}

.wo-btn-primary:hover {
    background: #16a34a;
}

.wo-btn-secondary {
    background: var(--surface-strong-dark);
    color: var(--text-dark);
    border: 1px solid var(--border-dark);
}

body.light-mode .wo-btn-secondary {
    background: var(--surface-strong-light);
    color: var(--text-light);
    border-color: var(--border-light);
}

.wo-btn-secondary:hover {
    background: color-mix(in srgb, var(--wo-correct) 15%, var(--surface-strong-dark));
}

body.light-mode .wo-btn-secondary:hover {
    background: color-mix(in srgb, var(--wo-correct) 12%, var(--surface-strong-light));
}

/* ---------- stats modal ---------- */
.wo-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 16px;
}

.wo-modal-overlay.open {
    display: flex;
}

.wo-modal {
    width: min(400px, 100%);
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    border-radius: 16px;
    padding: 28px 24px;
    color: var(--text-dark);
    animation: modalSlideIn 0.3s cubic-bezier(0.16,1,0.3,1);
    position: relative;
}

body.light-mode .wo-modal {
    background: var(--surface-light);
    border-color: var(--border-light);
    color: var(--text-light);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.wo-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--muted-dark);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.wo-modal-close:hover {
    background: var(--surface-strong-dark);
}

body.light-mode .wo-modal-close {
    color: var(--muted-light);
}

body.light-mode .wo-modal-close:hover {
    background: var(--surface-strong-light);
}

.wo-modal h2 {
    margin: 0 0 20px;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* stat boxes */
.wo-stats-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.wo-stat {
    text-align: center;
    min-width: 50px;
}

.wo-stat-val {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
}

.wo-stat-label {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--muted-dark);
    margin-top: 4px;
    line-height: 1.2;
}

body.light-mode .wo-stat-label {
    color: var(--muted-light);
}

/* distribution bars */
.wo-distro {
    margin-bottom: 20px;
}

.wo-distro h3 {
    margin: 0 0 10px;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: center;
}

.wo-distro-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 0.78rem;
    font-weight: 600;
}

.wo-distro-num {
    width: 14px;
    text-align: right;
    flex-shrink: 0;
}

.wo-distro-bar {
    min-width: 18px;
    padding: 3px 8px;
    text-align: right;
    border-radius: 4px;
    background: var(--wo-absent-dark);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    transition: width 0.4s cubic-bezier(0.16,1,0.3,1);
}

body.light-mode .wo-distro-bar {
    background: var(--wo-absent-light);
}

.wo-distro-bar.highlight {
    background: var(--wo-correct);
}

/* modal action row */
.wo-modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding-top: 4px;
}

/* ---------- responsive ---------- */
@media (max-width: 600px) {
    .wo-board {
        width: min(300px, 85vw);
    }

    .wo-tile {
        font-size: clamp(1.2rem, 4.5vw, 1.6rem);
        border-radius: 4px;
    }

    .wo-key {
        height: 48px;
        font-size: 0.76rem;
        border-radius: 5px;
    }

    .wo-key.wide {
        font-size: 0.66rem;
    }

    .wo-keyboard {
        gap: 5px;
    }

    .wo-kb-row {
        gap: 4px;
    }
}

@media (max-width: 380px) {
    .wo-board {
        width: 78vw;
    }

    .wo-key {
        height: 44px;
        min-width: 24px;
        font-size: 0.7rem;
    }
}

/* ---------- accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
    .wo-tile,
    .wo-tile.flip,
    .wo-tile.bounce,
    .wo-row.shake,
    .wo-toast,
    .wo-modal {
        animation: none !important;
        transition: none !important;
    }
}
