:root {
    --c-primary: #7c5cff;
    --c-primary-2: #b06aff;
    --c-accent: #ffb800;
    --c-accent-2: #ff6b6b;
    --c-success: #2ecc71;
    --c-danger: #e74c3c;
    --c-bg-top: #1b1035;
    --c-bg-bottom: #2c1e5e;
    --c-glass: rgba(255, 255, 255, 0.08);
    --c-glass-border: rgba(255, 255, 255, 0.18);
    --c-text: #ffffff;
    --c-text-dim: rgba(255, 255, 255, 0.65);
    --radius: 18px;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font);
    color: var(--c-text);
    background: radial-gradient(circle at 20% 0%, #3a2577 0%, #1b1035 55%, #120a28 100%);
    user-select: none;
    -webkit-user-select: none;
}

button {
    font-family: var(--font);
    border: none;
    cursor: pointer;
    color: inherit;
    background: none;
}

button:focus-visible {
    outline: 3px solid var(--c-accent);
    outline-offset: 2px;
}

#app {
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* ============ SCREENS ============ */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px
             calc(env(safe-area-inset-bottom, 0px) + 12px) 16px;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
}

/* ============ MENU ============ */
.glass-card {
    background: var(--c-glass);
    border: 1px solid var(--c-glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 28px;
    max-width: 460px;
    width: 100%;
    text-align: center;
}

.menu-title {
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 900;
    background: linear-gradient(135deg, #ffd76a, #ff9f43, #ff6b6b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1;
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.menu-subtitle {
    color: var(--c-text-dim);
    font-size: 1rem;
    margin-bottom: 24px;
}

.menu-stats {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 22px;
    padding: 14px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 14px;
}

.stat-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-box .label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--c-text-dim);
}

.stat-box .value {
    font-size: 1.15rem;
    font-weight: 800;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px 22px;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-2));
    box-shadow: 0 6px 20px rgba(124, 92, 255, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    width: 100%;
    min-height: 50px;
}

.btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-accent {
    background: linear-gradient(135deg, #ffb800, #ff8a00);
    box-shadow: 0 6px 20px rgba(255, 138, 0, 0.4);
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
    border: 1px solid var(--c-glass-border);
}

.btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.btn.hidden {
    display: none;
}

.menu-footer {
    margin-top: 18px;
    font-size: 0.8rem;
    color: var(--c-text-dim);
}

/* ============ LEVEL SELECT ============ */
.screen-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 820px;
    margin-bottom: 16px;
}

.screen-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
}

.icon-btn {
    width: 46px;
    height: 46px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    border-radius: 12px;
    background: var(--c-glass);
    border: 1px solid var(--c-glass-border);
    transition: background 0.15s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.levels-wrap {
    width: 100%;
    max-width: 820px;
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 12px;
}

.level-tile {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 14px;
    font-weight: 800;
    font-size: 1.05rem;
    transition: transform 0.15s;
}

.level-tile.unlocked {
    background: linear-gradient(135deg, rgba(124, 92, 255, 0.55), rgba(176, 106, 255, 0.45));
    border: 1px solid var(--c-glass-border);
}

.level-tile.unlocked:hover {
    transform: translateY(-3px) scale(1.03);
}

.level-tile.locked {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: not-allowed;
}

.tile-num {
    font-size: 1.05rem;
}

.tile-stars {
    font-size: 0.7rem;
    line-height: 1;
}

/* ============ GAME SCREEN ============ */
.game-shell {
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
}

.game-topbar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.topbar-item {
    background: var(--c-glass);
    border: 1px solid var(--c-glass-border);
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: 0.95rem;
    white-space: nowrap;
}

.topbar-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.1;
}

.topbar-score .small {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--c-text-dim);
}

.combo-badge {
    background: linear-gradient(135deg, #ffd76a, #ff9f43);
    color: #3a2500;
    border-radius: 999px;
    padding: 6px 14px;
    font-weight: 900;
    font-size: 0.95rem;
    box-shadow: 0 4px 14px rgba(255, 159, 67, 0.5);
    display: none;
}

.combo-badge.show {
    display: inline-block;
}

.puzzle-card {
    width: 100%;
    background: var(--c-glass);
    border: 1px solid var(--c-glass-border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 26px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.level-banner {
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--c-accent);
    text-transform: uppercase;
}

.emoji-area {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    min-height: 120px;
    padding: 10px 0;
}

.emoji-item {
    font-size: clamp(2.6rem, 9vw, 4.5rem);
    line-height: 1;
    animation: emojiIn 0.35s ease backwards;
}

.emoji-plus {
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    color: var(--c-accent);
    font-weight: 900;
    animation: emojiIn 0.35s ease backwards;
}

.question-label {
    font-size: 1.05rem;
    color: var(--c-text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

#game-options {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

#game-options.disabled {
    pointer-events: none;
}

.answer-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 14px;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 800;
    text-align: left;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--c-glass-border);
    transition: transform 0.13s ease, background 0.13s, border-color 0.13s;
    min-height: 56px;
}

.answer-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.answer-btn:active {
    transform: scale(0.98);
}

.opt-letter {
    width: 30px;
    height: 30px;
    min-width: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-2));
    font-size: 0.85rem;
    font-weight: 900;
}

.opt-text {
    flex: 1;
    word-break: break-word;
}

.answer-btn.correct {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.6), rgba(39, 174, 96, 0.6));
    border-color: var(--c-success);
    animation: correctGlow 0.5s ease;
}

.answer-btn.wrong {
    background: rgba(231, 76, 60, 0.35);
    border-color: var(--c-danger);
}

.answer-btn.hinted-away {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: all 0.25s ease;
}

/* game action row */
.game-actions {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.game-actions .spacer {
    flex: 1;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 0.95rem;
    background: var(--c-glass);
    border: 1px solid var(--c-glass-border);
    min-height: 48px;
    transition: background 0.15s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.action-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ==========================================================
   Arcade correct/complete state
   On a correct answer: hide options + action buttons,
   reveal the NEXT button in the SKIP position.
   ========================================================== */
.next-btn {
    display: none;
    background: linear-gradient(135deg, var(--c-success), #27ae60);
    box-shadow: 0 6px 18px rgba(46, 204, 113, 0.45);
    color: #fff;
}

/* feedback area hidden until shown */
.game-feedback {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    min-height: 0;
    animation: modalIn 0.25s ease;
}

.game-feedback.show-correct,
.game-feedback.show-complete {
    display: flex;
}

.feedback-kind {
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: 1px;
}

.game-feedback.show-correct .feedback-kind {
    color: var(--c-success);
}

.game-feedback.show-complete .feedback-kind {
    color: var(--c-accent);
}

.feedback-result {
    font-size: 1.05rem;
    color: var(--c-text);
    font-weight: 800;
}

.feedback-stars {
    font-size: 1.8rem;
    letter-spacing: 4px;
}

.feedback-stars.shine {
    animation: starShine 0.6s ease;
}

/* glow on emojis when correct/complete */
#game-emojis.glow .emoji-item {
    animation: correctGlowPulse 0.9s ease;
}

@keyframes correctGlowPulse {
    0% { filter: drop-shadow(0 0 0 rgba(46,204,113,0)); transform: scale(1); }
    40% { filter: drop-shadow(0 0 24px rgba(46,204,113,0.9)); transform: scale(1.12); }
    100% { filter: drop-shadow(0 0 12px rgba(46,204,113,0.5)); transform: scale(1); }
}

/* when the shell is in correct/complete state */
.game-shell.game-correct #game-options,
.game-shell.game-complete #game-options {
    display: none;
}

.game-shell.game-correct .action-btn:not(.next-btn),
.game-shell.game-complete .action-btn:not(.next-btn) {
    display: none;
}

.game-shell.game-correct .next-btn,
.game-shell.game-complete .next-btn {
    display: inline-flex;
}

/* Next button fills the row on mobile */
@media (max-width: 767px) {
    .game-shell.game-correct .next-btn,
    .game-shell.game-complete .next-btn {
        flex: 1;
        width: 100%;
        justify-content: center;
        min-height: 56px;
        font-size: 1.1rem;
    }
    .mobile-actions .next-btn {
        flex: 1;
    }
}

/* Desktop: center a large NEXT button in the action row on correct/complete */
@media (min-width: 768px) {
    .game-shell.game-correct #desktop-actions,
    .game-shell.game-complete #desktop-actions {
        justify-content: center;
    }
    .game-shell.game-correct #desktop-actions .spacer,
    .game-shell.game-complete #desktop-actions .spacer {
        display: none;
    }
    .game-shell.game-correct .next-btn,
    .game-shell.game-complete .next-btn {
        min-width: 220px;
        min-height: 56px;
        justify-content: center;
        font-size: 1.15rem;
        padding: 14px 34px;
    }
}

/* ============ TOASTS ============ */
.toast {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translate(-50%, -30px);
    z-index: 60;
    padding: 20px 30px;
    border-radius: 18px;
    font-weight: 900;
    text-align: center;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(86vw, 320px);
}

.toast.show {
    opacity: 1;
    animation: toastIn 0.25s ease forwards;
}

.toast-correct.show {
    pointer-events: auto;
}

.toast-wrong.show {
    pointer-events: none;
}

.toast-correct {
    background: linear-gradient(135deg, #11998e, #38ef7d);
}

.toast-wrong {
    background: linear-gradient(135deg, #eb3349, #f45c43);
}

.toast .t-title {
    font-size: 1.5rem;
}

.toast .t-points {
    font-size: 1.2rem;
}

.toast .t-combo {
    font-size: 0.95rem;
    color: #ffd76a;
}

.toast-correct .btn {
    width: auto;
    min-height: 46px;
    padding: 12px 26px;
    background: rgba(0, 0, 0, 0.3);
    box-shadow: none;
    font-size: 1rem;
}

/* ============ MODALS ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px
             calc(env(safe-area-inset-bottom, 0px) + 16px) 16px;
}

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

.modal {
    background: linear-gradient(160deg, #2c1e5e, #1b1035);
    border: 1px solid var(--c-glass-border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 26px 22px;
    width: min(94vw, 420px);
    max-height: 88vh;
    overflow-y: auto;
    text-align: center;
    animation: modalIn 0.22s ease;
}

.modal h2 {
    font-size: 1.4rem;
    margin-bottom: 12px;
}

.modal .modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 18px;
}

.modal .btn {
    width: 100%;
}

.complete-stars {
    font-size: 2.4rem;
    letter-spacing: 6px;
    margin: 8px 0;
}

.complete-stars.shine {
    animation: starShine 0.6s ease;
}

.complete-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 6px;
}

.complete-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.complete-stat .label {
    font-size: 0.7rem;
    color: var(--c-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.complete-stat .value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--c-accent);
}

/* settings list */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 12px;
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-label {
    font-weight: 700;
    font-size: 0.95rem;
    text-align: left;
}

.toggle {
    position: relative;
    width: 52px;
    height: 30px;
    min-width: 52px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle .slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    transition: background 0.2s;
}

.toggle .slider::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle input:checked + .slider {
    background: linear-gradient(135deg, var(--c-accent), #ff8a00);
}

.toggle input:checked + .slider::before {
    transform: translateX(22px);
}

.confirm-warning {
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid rgba(231, 76, 60, 0.4);
    border-radius: 12px;
    padding: 14px;
    font-size: 0.9rem;
    text-align: left;
    list-style-position: inside;
}

.confirm-warning ul {
    margin-top: 6px;
    margin-left: 8px;
    opacity: 0.85;
}

/* ============ HOW TO PLAY ============ */
.howto-steps {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.howto-step {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.step-num {
    width: 34px;
    height: 34px;
    min-width: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-2));
    font-weight: 900;
}

.howto-example {
    margin: 12px 0;
    padding: 14px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 14px;
    font-size: 1.3rem;
    text-align: center;
}

.howto-example .sub {
    font-size: 0.85rem;
    color: var(--c-text-dim);
    margin-top: 6px;
}

.fatal-error {
    padding: 40px;
    text-align: center;
    font-weight: 800;
}

@media (min-width: 768px) {
    .game-shell {
        gap: 18px;
    }
}
