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

/* ---------- colour tokens ---------- */
:root {
    --wo-correct: #22c55e;
    --wo-correct-shadow: #15803d;
    --wo-present: #eab308;
    --wo-present-shadow: #a16207;
    --wo-absent-dark: #3f3f46;
    --wo-absent-light: #64748b;
    --wo-key-bg-dark: #71717a;
    --wo-key-bg-light: #e2e8f0;
    --wo-key-text-light: #0f172a;
    --wo-tile-bg-light: #ffffff;
    --wo-tile-border-dark: rgba(255,255,255,0.22);
    --wo-tile-border-light: #cbd5e1;
    --wo-tile-filled-border-dark: rgba(255,255,255,0.50);
    --wo-tile-filled-border-light: #475569;
}

/* ---------- layout ---------- */
html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    padding-top: var(--app-header-offset);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: 8px;
    padding-right: 8px;
    box-sizing: border-box;
}

.wo-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 500px;
    height: 100%;
    flex: 1;
    margin: 0 auto;
    padding: 0 4px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    box-sizing: border-box;
    overflow: hidden;
}

.wo-board-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    min-height: 0;
    padding: 4px 0;
}

.wo-bottom-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
    margin-top: auto;
    padding-bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
}

/* ---------- board ---------- */
.wo-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    width: min(350px, calc((100dvh - var(--app-header-offset) - 275px) * 5 / 6), 100%);
    max-height: 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:not(.correct):not(.present):not(.absent) {
    background: var(--wo-tile-bg-light);
    border-color: var(--wo-tile-border-light);
    color: var(--text-light);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

/* filled (typed but not revealed) */
.wo-tile.filled {
    border-color: var(--wo-tile-filled-border-dark);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.12);
    animation: pop 0.1s ease;
}

body.light-mode .wo-tile.filled:not(.correct):not(.present):not(.absent) {
    border-color: var(--wo-tile-filled-border-light);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}

/* revealed states */
.wo-tile.correct,
body.light-mode .wo-tile.correct {
    background: var(--wo-correct) !important;
    border-color: var(--wo-correct) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35) !important;
}

.wo-tile.present,
body.light-mode .wo-tile.present {
    background: var(--wo-present) !important;
    border-color: var(--wo-present) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(234, 179, 8, 0.35) !important;
}

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

body.light-mode .wo-tile.absent {
    background: var(--wo-absent-light) !important;
    border-color: var(--wo-absent-light) !important;
    color: #ffffff !important;
    box-shadow: none !important;
}

/* ---------- 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-top: 4px;
    margin-bottom: 14px;
}

.wo-btn-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-dark);
    background: var(--surface-strong-dark);
    color: var(--muted-dark);
    cursor: not-allowed;
    opacity: 0.65;
    transition: all 0.2s ease;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

body.light-mode .wo-btn-hint {
    border-color: var(--border-light);
    background: var(--surface-strong-light);
    color: var(--muted-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.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 12px rgba(234, 179, 8, 0.3);
    animation: hintPulse 2.2s infinite ease-in-out;
}

body.light-mode .wo-btn-hint.unlocked {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #b45309;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.35), 0 2px 6px rgba(0, 0, 0, 0.06);
}

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

.wo-btn-hint.used {
    opacity: 0.75;
    cursor: pointer;
    border-color: var(--border-dark);
    animation: none;
    box-shadow: none;
}

body.light-mode .wo-btn-hint.used {
    border-color: var(--border-light);
}

.wo-btn-hint.used:hover {
    opacity: 1;
}

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

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

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

.wo-kb-row {
    display: flex;
    gap: 6px;
    width: 100%;
    justify-content: center;
    touch-action: manipulation;
}

.wo-key-spacer {
    flex: 0.5;
    pointer-events: none;
}

.wo-key {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    min-width: 0;
    flex: 1;
    border-radius: 6px;
    border: none;
    background: var(--wo-key-bg-dark);
    color: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 3px 0 #52525b;
    transition: background 0.15s ease, transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

body.light-mode .wo-key:not(.correct):not(.present):not(.absent) {
    background: var(--wo-key-bg-light);
    color: var(--wo-key-text-light);
    box-shadow: 0 3px 0 #cbd5e1;
}

.wo-key:active {
    transform: translateY(2px) scale(0.97);
    box-shadow: 0 1px 0 #52525b;
}

body.light-mode .wo-key:not(.correct):not(.present):not(.absent):active {
    box-shadow: 0 1px 0 #cbd5e1;
}

.wo-key.wide {
    flex: 1.5;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
}

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

.wo-key.correct,
body.light-mode .wo-key.correct {
    background: var(--wo-correct) !important;
    color: #ffffff !important;
    box-shadow: 0 3px 0 var(--wo-correct-shadow), 0 0 10px rgba(34, 197, 94, 0.25) !important;
}

.wo-key.present,
body.light-mode .wo-key.present {
    background: var(--wo-present) !important;
    color: #ffffff !important;
    box-shadow: 0 3px 0 var(--wo-present-shadow), 0 0 10px rgba(234, 179, 8, 0.25) !important;
}

.wo-key.absent {
    background: var(--wo-absent-dark);
    color: #a1a1aa;
    box-shadow: 0 3px 0 #27272a;
    opacity: 0.75;
}

body.light-mode .wo-key.absent {
    background: var(--wo-absent-light) !important;
    color: #ffffff !important;
    box-shadow: 0 3px 0 #475569 !important;
    opacity: 0.85 !important;
}

/* ---------- 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(320px, calc((100dvh - var(--app-header-offset) - 270px) * 5 / 6), 85vw);
    }

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

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

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

    .wo-keyboard {
        gap: 6px;
    }

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

    .wo-hint-bar {
        margin-bottom: 12px;
    }
}

@media (max-width: 380px) {
    .wo-board {
        width: min(280px, calc((100dvh - var(--app-header-offset) - 250px) * 5 / 6), 78vw);
    }

    .wo-key {
        height: 46px;
        font-size: 0.92rem;
    }

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

    .wo-hint-bar {
        margin-bottom: 10px;
    }
}

/* ---------- 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;
    }
}

/* ---------- keep awake / screen lock button ---------- */
.keep-awake-btn[hidden] {
    display: none !important;
}
.keep-awake-btn .lightbulb-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease, fill 0.3s ease, stroke 0.3s ease;
}
.keep-awake-btn[data-active="true"] {
    background: rgba(245, 158, 11, 0.18) !important;
    border-color: rgba(245, 158, 11, 0.5) !important;
    color: #fbbf24 !important;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}
.keep-awake-btn[data-active="true"] .lightbulb-icon {
    fill: #fbbf24;
    stroke: #fbbf24;
    filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.7));
    transform: scale(1.08);
}
body.light-mode .keep-awake-btn[data-active="true"] {
    background: #fef3c7 !important;
    border-color: #f59e0b !important;
    color: #d97706 !important;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}
body.light-mode .keep-awake-btn[data-active="true"] .lightbulb-icon {
    fill: #d97706;
    stroke: #d97706;
    filter: drop-shadow(0 0 3px rgba(217, 119, 6, 0.6));
}
