/* ===== Prevent page scroll – keyboard is fixed (game page only) ===== */
html:has(.body-game),
.body-game {
    overflow: hidden;
    height: 100%;
}

.body-game {
    margin-bottom: 0 !important;
}

.body-game .footer {
    display: none;
}

:root {
    --viewport-height: 100vh;
}

/* ===== Layout ===== */
.game-container {
    padding-top: 0.5rem;
    max-width: 600px;
    min-height: calc(var(--viewport-height) - 80px);
    padding-bottom: 240px; /* room for keyboard */
}

/* ===== Help button ===== */
.game-header {
    padding-right: 2.25rem;
}

.help-btn {
    position: absolute;
    top: 0.5rem;
    right: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.help-btn:hover,
.help-btn:focus {
    opacity: 1;
}

/* ===== Rules modal letter boxes ===== */
.rules-letter-box {
    width: 32px;
    height: 32px;
    border: 2px solid;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    flex-shrink: 0;
}

.rules-letter-box.correct-position {
    background: #198754;
    color: white;
    border-color: #146c43;
}

.rules-letter-box.wrong-position {
    background: #ffc107;
    color: #000;
    border-color: #ffca2c;
}

.rules-letter-box.not-in-word {
    background: #6c757d;
    color: white;
    border-color: #565e64;
}

/* ===== Mini funnel ===== */
.mini-funnel {
    order: 1;
    flex-shrink: 0;
    align-self: flex-start;
    margin-left: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    z-index: 10;
}

.funnel-seed {
    width: 28px;
    height: 28px;
    border-radius: 3px;
    background: #198754;
    color: white;
    border: 1px solid #146c43;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.funnel-word {
    display: flex;
    gap: 3px;
    justify-content: center;
    animation: funnelPop 0.3s ease;
}

.funnel-word-tip {
    cursor: pointer;
    outline: none;
}

.funnel-letter {
    width: 28px;
    height: 28px;
    background: #198754;
    color: white;
    border: 1px solid #146c43;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

@keyframes funnelPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes funnelDrop {
    0% { transform: translateY(-10px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }

}
/* Word-found celebration animation */
.funnel-word-new {
    animation: none;
}

.funnel-word-new .funnel-letter {
    animation: letterFound 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.funnel-word-new .funnel-letter:nth-child(1) { animation-delay: 0.05s; }
.funnel-word-new .funnel-letter:nth-child(2) { animation-delay: 0.12s; }
.funnel-word-new .funnel-letter:nth-child(3) { animation-delay: 0.19s; }
.funnel-word-new .funnel-letter:nth-child(4) { animation-delay: 0.26s; }
.funnel-word-new .funnel-letter:nth-child(5) { animation-delay: 0.33s; }
.funnel-word-new .funnel-letter:nth-child(6) { animation-delay: 0.40s; }

@keyframes letterFound {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); }
}

/* ===== Active word area ===== */
.active-word-area {
    flex: 1;
    min-width: 0;
    max-width: 400px;
    order: 0;
}

.word-box {
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 0.75rem;
    background: white;
    transition: all 0.3s ease;
}

.word-box.active {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.score-breakdown {
    border: 2px solid #0d6efd;
}

.attempts-list {
    border-bottom: 2px dashed #dee2e6;
    padding-bottom: 0.5rem;
}

.letter-boxes {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.letter-box {
    width: 50px;
    height: 50px;
    border: 2px solid #ced4da;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    background: white;
    transition: all 0.15s ease;
    text-transform: uppercase;
}

.letter-box.empty {
    background: #f8f9fa;
}

.letter-box.filled {
    border-color: #0d6efd;
    background: #e7f1ff;
    animation: popIn 0.1s ease;
}

@keyframes popIn {
    0% { transform: scale(0.85); }
    100% { transform: scale(1); }
}

.letter-box.correct-position {
    background: #198754;
    color: white;
    border-color: #146c43;
    animation: flip 0.5s ease;
}

.letter-box.wrong-position {
    background: #ffc107;
    color: #000;
    border-color: #ffca2c;
    animation: flip 0.5s ease;
}

.letter-box.not-in-word {
    background: #6c757d;
    color: white;
    border-color: #565e64;
    animation: flip 0.5s ease;
}

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

/* Shake animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
    20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.shake {
    animation: shake 0.6s cubic-bezier(.36,.07,.19,.97) both;
}

.invalid-feedback {
    color: #dc3545;
    font-size: 0.875rem;
    font-weight: 600;
}

/* ===== On-screen keyboard ===== */
.onscreen-keyboard {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #d3d6da;
    padding: 8px 6px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

.keyboard-row {
    display: flex;
    gap: 5px;
    justify-content: center;
    width: 100%;
    max-width: 540px;
}

.keyboard-key {
    flex: 1;
    max-width: 48px;
    height: 58px;
    border: none;
    border-radius: 4px;
    background: #ffffff;
    color: #1a1a1a;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, transform 0.08s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.keyboard-key:active {
    transform: scale(0.92);
}

.keyboard-key.key-action {
    flex: 1.5;
    max-width: 72px;
    background: #e2e3e5;
    font-size: 1.25rem;
}

/* Keyboard letter states */
.keyboard-key.kb-correct {
    background: #198754;
    color: white;
}

.keyboard-key.kb-wrongpos {
    background: #ffc107;
    color: #000;
}

.keyboard-key.kb-wrong {
    background: #86888a;
    color: #fff;
}

.keyboard-key.kb-previous {
    background: #0d6efd;
    color: white;
}

/* ===== Mobile optimizations ===== */
@media (max-width: 576px) {
    .game-container {
        padding-top: 0.25rem;
        padding-bottom: 230px;
    }

    .letter-box {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .word-box {
        padding: 0.5rem;
    }

    .letter-boxes {
        gap: 0.3rem;
    }

    .keyboard-row {
        gap: 4px;
    }

    .keyboard-key {
        max-width: none;
        height: 54px;
        font-size: 1.05rem;
    }

    .keyboard-key.key-action {
        max-width: none;
        flex: 1.5;
    }

    .mini-funnel {
        margin-left: 8px;
    }

    .funnel-seed {
        width: 22px;
        height: 22px;
        font-size: 0.65rem;
        border-radius: 2px;
    }

    .funnel-letter {
        width: 22px;
        height: 22px;
        font-size: 0.65rem;
        border-radius: 2px;
    }
}

/* ===== Junior: small-screen layout fix ===== */
/* Hide the icon sidebar on small screens — icon count is shown in the header badge.
   This frees enough horizontal space for the 5-letter word to fit on one line. */
@media (max-width: 576px) {
    .body-game-jr .icon-sidebar {
        display: none;
    }

    .body-game-jr .letter-boxes {
        flex-wrap: nowrap;
        gap: 0.25rem;
    }

    .body-game-jr .letter-box {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }
}

@media (min-width: 577px) {
    .keyboard-key {
        max-width: 48px;
        height: 62px;
        font-size: 1.15rem;
    }

    .keyboard-key.key-action {
        max-width: 72px;
    }
}

/* ===== Junior: pre-placed seed letter ===== */
.letter-box.seed-letter {
    background: #198754;
    color: white;
    border-color: #146c43;
    cursor: default;
}

/* ===== Junior: eliminated keyboard key ===== */
.keyboard-key.kb-eliminated {
    background: #dee2e6;
    color: #adb5bd;
    cursor: not-allowed;
    opacity: 0.45;
}

/* ===== Icon discovery sidebar ===== */
.icon-sidebar {
    order: -1;           /* left of the active-word-area */
    flex-shrink: 0;
    width: 56px;
    max-height: 340px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 10px;
    align-self: flex-start;
}

.icon-sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    color: #6c757d;
    font-size: 0.65rem;
    font-weight: 600;
}

.icon-sidebar-header .material-symbols-outlined {
    font-size: 20px;
    color: #ffc107;
}

.icon-sidebar-scroll {
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    scrollbar-width: thin;
}

.icon-sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}

.icon-sidebar-scroll::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 2px;
}

.discovered-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #fff9e6, #fff3cd);
    border: 1px solid #ffc107;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    animation: iconPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.discovered-icon .material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-feature-settings: 'liga';
    -webkit-font-feature-settings: 'liga';
    font-size: 24px;
    color: #e67e00;
    display: inline-block;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
}

@keyframes iconPop {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

@media (max-width: 576px) {
    .icon-sidebar {
        width: 44px;
        margin-right: 6px;
    }

    .discovered-icon {
        width: 36px;
        height: 36px;
    }

    .discovered-icon .material-symbols-outlined {
        font-size: 20px;
    }
}

/* ===== Dave's Hint Hut button ===== */
.hint-hut-btn {
    position: fixed;
    bottom: calc(215px + env(safe-area-inset-bottom, 0px));
    right: 0.75rem;
    width: 56px;
    height: 56px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    z-index: 110;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s, transform 0.1s;
}

.hint-hut-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.hint-hut-btn:hover:not(.hint-hut-used) {
    transform: scale(1.08);
}

.hint-hut-btn:active:not(.hint-hut-used) {
    transform: scale(0.92);
}

.hint-hut-btn.hint-hut-used {
    opacity: 0.35;
    cursor: default;
}

.hint-pip {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    padding: 0 4px;
    white-space: nowrap;
    line-height: 1;
    pointer-events: none;
}

/* ===== Dave's Hint Hut store ===== */
.hut-modal-content {
    border: 3px solid #8b6914;
    border-radius: 12px;
    overflow: hidden;
}

.hint-hut-header {
    background: linear-gradient(135deg, #5c3d1a 0%, #8b6914 100%);
    padding: 12px 16px;
}

.hut-header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.hut-modal-logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    object-fit: contain;
    flex-shrink: 0;
}

.hut-token-balance {
    color: #ffd700;
    font-weight: 700;
    font-size: 0.85rem;
    margin-top: 2px;
}

.hut-shop-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hut-shop-item {
    border: 2px solid #d4a843;
    border-radius: 10px;
    padding: 10px 14px;
    background: #fffdf5;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    user-select: none;
}

.hut-shop-item:hover:not(.hut-item-disabled):not(.hut-item-used) {
    background: #fff3d0;
    border-color: #b8860b;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.hut-shop-item:active:not(.hut-item-disabled):not(.hut-item-used) {
    transform: scale(0.98);
}

.hut-shop-item.hut-item-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #f5f5f5;
    border-color: #ccc;
}

.hut-shop-item.hut-item-used {
    opacity: 0.55;
    cursor: default;
    background: #f0f0f0;
    border-color: #aaa;
    position: relative;
}

.hut-shop-item.hut-item-used::after {
    content: '\2713 Purchased';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    color: #28a745;
}

.hut-shop-item.hut-item-used .hut-item-cost {
    visibility: hidden;
}

.hut-item-icon {
    font-size: 1.75rem;
    width: 40px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.hut-item-info {
    flex: 1;
    min-width: 0;
}

.hut-item-name {
    font-weight: 700;
    color: #5c3d1a;
    font-size: 0.92rem;
    margin-bottom: 2px;
}

.hut-item-desc {
    font-size: 0.78rem;
    color: #666;
    line-height: 1.3;
}

.hut-item-cost {
    font-weight: 700;
    color: #b8860b;
    white-space: nowrap;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.hut-cost-free {
    color: #28a745;
}

.hut-result-area {
    text-align: center;
    padding: 8px 4px;
}

.hint-letter-display {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.hint-letter-badge {
    width: 46px;
    height: 46px;
    border-radius: 4px;
    background: #0d6efd;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    text-transform: uppercase;
}

.hut-positional-hint {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #fff3d0;
    border: 2px solid #d4a843;
    border-radius: 10px;
    padding: 10px 18px;
    margin-top: 6px;
    font-size: 1rem;
}

.hut-pos-letter {
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    background: #5c3d1a;
    padding: 4px 12px;
    border-radius: 6px;
    letter-spacing: 0.05em;
}

.letter-box.hint-revealed {
    position: relative;
}

.letter-box.hint-revealed::after {
    content: attr(data-hint);
    position: absolute;
    bottom: 3px;
    right: 4px;
    font-size: 0.55rem;
    font-weight: 700;
    color: #ffd700;
    background: #5c3d1a;
    border-radius: 3px;
    padding: 0 3px;
    line-height: 1.4;
    pointer-events: none;
}

@media (max-width: 576px) {
    .hint-hut-btn {
        bottom: calc(198px + env(safe-area-inset-bottom, 0px));
        width: 48px;
        height: 48px;
    }
}
