:root {
            --primary: #FF4757;
            --primary-shadow: #FF1E33;
            --secondary: #2ED573;
            --secondary-shadow: #1EAE55;
            --bg-gradient: linear-gradient(135deg, #5352ED 0%, #3742FA 100%);
            --panel-bg: #FFFFFF;
            --text-main: #2F3542;
            --text-soft: #747d8c;
            --input-bg: #FFFFFF;
            --input-border: #DFE4EA;
            --muted-panel: #f1f3f8;
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: 'Cairo', 'Tajawal', 'Nunito', Arial, sans-serif;
            direction: rtl;
            background: var(--bg-gradient);
            margin: 0;
            padding: 20px;
            color: var(--text-main);
            min-height: 100vh;
            min-height: 100dvh;
            display: flex;
            align-items: center; /* Centers the app vertically */
            justify-content: center;
            overflow-y: auto;
        }

        body.phone-in-game {
            align-items: flex-start;
            padding: 12px;
        }

        body.phone-dark {
            --primary: #FF5C7A;
            --primary-shadow: #B51D38;
            --secondary: #35D99D;
            --secondary-shadow: #16865C;
            --bg-gradient: linear-gradient(135deg, #111827 0%, #1f2937 54%, #312e81 100%);
            --panel-bg: #121826;
            --text-main: #F8FAFC;
            --text-soft: #CBD5E1;
            --input-bg: #0F172A;
            --input-border: #334155;
            --muted-panel: #1E293B;
        }

        .phone-theme-toggle {
            position: fixed;
            top: 12px;
            left: 12px;
            z-index: 60;
            width: 44px;
            height: 44px;
            min-width: 44px;
            display: grid;
            place-items: center;
            padding: 0;
            border-radius: 15px;
            background: rgba(255,255,255,0.92);
            color: #2F3542;
            border: 2px solid rgba(255,255,255,0.56);
            box-shadow: 0 6px 0 rgba(47,53,66,0.22), 0 12px 22px rgba(0,0,0,0.16);
            font-size: 22px;
            line-height: 1;
        }

        body.phone-dark .phone-theme-toggle {
            background: #1E293B;
            color: #F8FAFC;
            border-color: rgba(148,163,184,0.32);
            box-shadow: 0 6px 0 #0F172A, 0 12px 24px rgba(0,0,0,0.32);
        }

        .wrap {
            width: 100%;
            max-width: 500px; /* Slimmer for mobile feel */
            margin: 0 auto;
        }

        .panel {
            background: var(--panel-bg);
            border-radius: 24px;
            padding: 30px 24px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.2);
            text-align: center;
        }

        body.phone-dark .panel {
            border: 1px solid rgba(148,163,184,0.18);
            box-shadow: 0 14px 34px rgba(0,0,0,0.34);
        }

        .host-controls {
            margin: 16px 0;
            padding: 10px;
            border-radius: 18px;
        }

        .row.host-control-row {
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 10px;
            margin-top: 0;
        }

        .host-control-btn {
            width: 48px;
            height: 48px;
            min-width: 48px;
            display: inline-grid;
            place-items: center;
            padding: 0;
            border-radius: 15px;
        }

        .host-control-btn.host-control-secondary {
            background: var(--secondary);
            box-shadow: 0 6px 0 var(--secondary-shadow);
        }

        .host-control-btn.host-control-danger {
            background: var(--primary);
            box-shadow: 0 6px 0 var(--primary-shadow);
        }

        .host-control-icon {
            display: block;
            color: #ffffff;
            font-size: 22px;
            font-weight: 900;
            line-height: 1;
        }

        .host-confirm-overlay {
            position: fixed;
            inset: 0;
            z-index: 50;
            display: grid;
            place-items: center;
            padding: 18px;
            background: rgba(47, 53, 66, 0.46);
            backdrop-filter: blur(8px);
        }

        .host-confirm-card {
            width: min(100%, 420px);
            padding: 22px 18px 18px;
            border-radius: 24px;
            text-align: center;
            background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
            border: 2px solid rgba(255, 71, 87, 0.18);
            box-shadow:
                0 18px 40px rgba(0,0,0,0.24),
                inset 0 1px 0 rgba(255,255,255,0.76);
            animation: phoneCardIn 0.24s ease both;
        }

        body.phone-dark .host-confirm-card {
            background: linear-gradient(180deg, #172033 0%, #111827 100%);
            border-color: rgba(255, 92, 122, 0.26);
        }

        .host-confirm-icon {
            width: 58px;
            height: 58px;
            margin: 0 auto 12px;
            display: grid;
            place-items: center;
            border-radius: 18px;
            color: #ffffff;
            background: var(--primary);
            box-shadow: 0 7px 0 var(--primary-shadow);
            font-size: 28px;
            font-weight: 900;
        }

        .host-confirm-card h2 {
            margin: 0 0 8px;
            color: var(--text-main);
            font-size: 23px;
            line-height: 1.15;
        }

        .host-confirm-card p {
            margin: 0;
            color: var(--text-soft);
            font-size: 16px;
            font-weight: 800;
            line-height: 1.45;
        }

        .host-confirm-actions {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 18px;
        }

        .host-confirm-btn {
            min-height: 46px;
            padding: 10px 12px;
            border-radius: 15px;
            font-size: 15px;
        }

        .host-confirm-cancel {
            color: #2F3542;
            background: #CED6E0;
            box-shadow: 0 5px 0 #A4B0BE;
        }

        .host-confirm-danger {
            background: var(--primary);
            box-shadow: 0 5px 0 var(--primary-shadow);
        }

        .waiting-panel {
            min-height: min(70vh, 560px);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 14px;
        }

        .waiting-icon {
            width: 76px;
            height: 76px;
            display: grid;
            place-items: center;
            border-radius: 24px;
            font-size: 42px;
            background: #e8f2ff;
            color: #1769e0;
            box-shadow: 0 8px 0 #9bbcff, 0 16px 28px rgba(0,0,0,0.14);
            animation: waitingPulse 1.8s ease-in-out infinite;
        }

        .waiting-panel p {
            margin: 0;
            max-width: 320px;
            font-size: 18px;
            font-weight: 800;
            line-height: 1.45;
            color: #747d8c;
        }

        .waiting-room-code {
            margin-top: 6px;
            padding: 10px 18px;
            border-radius: 16px;
            background: #f1f3f8;
            color: var(--primary);
            font-size: 30px;
            font-weight: 900;
            letter-spacing: 5px;
            direction: ltr;
        }

        @keyframes waitingPulse {
            0%,
            100% {
                transform: translateY(0) scale(1);
            }
            50% {
                transform: translateY(-4px) scale(1.03);
            }
        }

        h1 {
            margin-top: 0;
            font-weight: 800;
            font-size: 32px;
            color: var(--text-main);
            margin-bottom: 24px;
        }

        .row {
            display: flex;
            flex-direction: column;
            gap: 16px;
            margin-top: 16px;
        }

        .avatar-picker {
            display: grid;
            grid-template-columns: repeat(6, minmax(0, 1fr));
            gap: 10px;
            margin: 10px 0 18px;
        }

        .avatar-choice {
            aspect-ratio: 1;
            display: grid;
            place-items: center;
            padding: 0;
            min-height: 48px;
            font-size: 26px;
            border-radius: 16px;
            background: #f1f3f8;
            color: var(--text-main);
            border: 2px solid #dfe4ea;
            box-shadow: 0 4px 0 #c8d0dc;
        }

        .avatar-choice.selected {
            background: #e8f2ff;
            border-color: #7ab0ff;
            box-shadow: 0 4px 0 #9bbcff;
            transform: translateY(0);
        }

        body.phone-dark .avatar-choice {
            background: #1E293B;
            color: #F8FAFC;
            border-color: #334155;
            box-shadow: 0 4px 0 #0F172A;
        }

        body.phone-dark .avatar-choice.selected {
            background: #213A63;
            border-color: #60A5FA;
            box-shadow: 0 4px 0 #1D4ED8;
        }

        input {
            font-family: inherit;
            font-size: 18px;
            font-weight: 800;
            padding: 16px;
            border: 2px solid var(--input-border);
            border-radius: 16px;
            text-align: center;
            outline: none;
            transition: border-color 0.2s;
            width: 100%;
            color: var(--text-main);
            background: var(--input-bg);
        }

        input:focus {
            border-color: var(--primary);
        }

        /* Specific styling to make the room code look like a code */
        #roomInput {
            text-transform: uppercase;
            letter-spacing: 6px;
            font-size: 24px;
        }

        button {
            font-family: inherit;
            font-size: 18px;
            font-weight: 800;
            padding: 18px;
            border: none;
            border-radius: 16px;
            background: var(--primary);
            color: white;
            cursor: pointer;
            box-shadow: 0 6px 0 var(--primary-shadow);
            transform: translateY(0);
            transition: transform 0.1s, box-shadow 0.1s;
            width: 100%;
        }

        button:active {
            box-shadow: 0 0 0 transparent;
            transform: translateY(6px);
        }

        .hidden {
            display: none !important;
        }

        .phone-game-panel {
            min-height: min(70vh, calc(100dvh - 24px));
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            --timer-ratio: 0%;
            --timer-color: var(--secondary);
        }

        .phone-topbar {
            display: flex;
            justify-content: flex-end;
            margin-bottom: 14px;
        }

        .phone-timer {
            --progress: 1turn;
            --timer-color: var(--secondary);

            width: 92px;
            height: 92px;
            border-radius: 50%;
            position: relative;
            flex: 0 0 auto;

            background: conic-gradient(
                var(--timer-color) var(--progress),
                var(--muted-panel) 0
            );

            box-shadow:
                0 10px 24px rgba(0,0,0,0.12),
                inset 0 0 0 3px rgba(255,255,255,0.35);

            transition: transform 0.15s ease;
        }

        .phone-timer::before {
            content: "";
            position: absolute;
            inset: 14px;
            border-radius: 50%;
            background: var(--panel-bg);
            box-shadow: inset 0 0 0 2px rgba(148,163,184,0.22);
        }

        .phone-timer::after {
            content: "";
            position: absolute;
            inset: 34px;
            border-radius: 50%;
            background: var(--timer-color);
            opacity: 0.16;
        }

        .phone-timer.warn {
            --timer-color: #7C3AED;
        }

        .phone-timer.danger {
            --timer-color: #FF4757;
            animation: timerPulsePhone 0.75s ease-in-out infinite;
        }

        .phone-game-panel.timer-warn {
            --timer-color: #7C3AED;
        }

        .phone-game-panel.timer-danger {
            --timer-color: #FF4757;
        }

        .phone-timer.idle {
            --progress: 0turn;
            opacity: 0.28;
        }

        @keyframes timerPulsePhone {
            0%,
            100% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.06);
            }
        }

        .phone-question {
            font-size: 26px;
            font-weight: 800;
            font-family: 'Noto Kufi Arabic', 'Cairo', 'Tajawal', Arial, sans-serif;
            line-height: 1.4;
            margin-bottom: 30px;
        }

        .phone-question.question-poem {
            white-space: pre-line;
            line-height: 1.75;
            font-size: 24px;
        }

        .phone-option {
            display: block;
            width: 100%;
            text-align: center;
            margin-top: 16px;
            padding: 20px;
            font-size: 20px;
            font-weight: 800;
            border-radius: 16px;
            border: 2px solid var(--input-border);
            background: var(--input-bg);
            color: var(--text-main);
            box-shadow: 0 4px 0 rgba(100,116,139,0.34);
            cursor: pointer;
            transition: all 0.1s;
            overflow-wrap: anywhere;
        }

        .timer-frame {
            position: relative;
            isolation: isolate;
            border-radius: 22px;
        }

        .timer-frame::before {
            content: "";
            position: absolute;
            inset: -5px;
            z-index: -1;
            border-radius: 26px;
            background:
                linear-gradient(
                    to left,
                    var(--timer-color) 0 var(--timer-ratio),
                    var(--muted-panel) var(--timer-ratio) 100%
                );
            box-shadow:
                0 10px 22px rgba(0,0,0,0.12),
                0 0 0 2px rgba(255,255,255,0.48);
            transition: background 0.12s linear, transform 0.15s ease;
        }

        .timer-frame::after {
            content: "";
            position: absolute;
            inset: 1px;
            z-index: -1;
            border-radius: 20px;
            background: var(--panel-bg);
        }

        .phone-game-panel.timer-danger .timer-frame::before {
            animation: timerFramePulse 0.72s ease-in-out infinite;
            box-shadow:
                0 10px 24px rgba(255,71,87,0.22),
                0 0 0 2px rgba(255,71,87,0.22);
        }

        @keyframes timerFramePulse {
            0%,
            100% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.018);
            }
        }

        .phone-option:active {
            box-shadow: 0 0 0 transparent;
            transform: translateY(4px);
            border-color: var(--primary);
            color: var(--primary);
        }

        .phone-message {
            margin-top: 24px;
            font-size: 20px;
            font-weight: 800;
            color: var(--secondary);
        }

        /* Specific style for utility buttons */
        #reconnectBtn {
            background: #CED6E0;
            color: #2F3542;
            box-shadow: 0 6px 0 #A4B0BE;
        }

        body.phone-dark #reconnectBtn,
        body.phone-dark .host-confirm-cancel {
            background: #334155;
            color: #F8FAFC;
            box-shadow: 0 5px 0 #0F172A;
        }

        .phone-topbar {
    align-items: center;
    gap: 14px;
}

.phone-topbar-simple {
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 18px;
}

.phone-feedback-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    margin: 0 0 18px;
    padding: 16px;
    border-radius: 20px;
    text-align: left;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 2px solid #eef2f7;
    box-shadow: 0 10px 22px rgba(0,0,0,0.10);
    animation: phoneCardIn 0.28s ease both;
}

body.phone-dark .phone-feedback-card {
    background: linear-gradient(180deg, #172033 0%, #111827 100%);
    border-color: rgba(148,163,184,0.22);
    box-shadow: 0 12px 26px rgba(0,0,0,0.28);
}

body.phone-dark .phone-feedback-card.locked,
body.phone-dark .phone-feedback-card.success {
    background: linear-gradient(180deg, rgba(22,101,52,0.34) 0%, #111827 100%);
}

body.phone-dark .phone-feedback-card.danger {
    background: linear-gradient(180deg, rgba(153,27,27,0.34) 0%, #111827 100%);
}

.phone-feedback-card.locked {
    border-color: rgba(46, 213, 115, 0.35);
    background: linear-gradient(180deg, #f0fff6 0%, #ffffff 100%);
}

.phone-feedback-card.success {
    border-color: rgba(46, 213, 115, 0.45);
    background: linear-gradient(180deg, #eafff2 0%, #ffffff 100%);
}

.phone-feedback-card.danger {
    border-color: rgba(255, 71, 87, 0.32);
    background: linear-gradient(180deg, #fff0f2 0%, #ffffff 100%);
}

.phone-feedback-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 16px;
    font-size: 28px;
    background: var(--muted-panel);
}

.phone-feedback-title {
    font-size: 18px;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1.15;
}

.phone-feedback-body {
    margin-top: 4px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text-soft);
    line-height: 1.3;
}

[dir="rtl"] input,
[dir="rtl"] textarea {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] #roomInput {
    direction: ltr;
    text-align: center;
}

.phone-option:disabled {
    cursor: not-allowed;
    opacity: 0.62;
    transform: none;
}

.phone-option.own-fake {
    background: var(--muted-panel);
    color: var(--text-soft);
    border-color: var(--input-border);
}

.phone-option.category-option {
    background: linear-gradient(135deg, #1769e0 0%, #00a8ff 100%);
    color: white;
    border-color: rgba(255,255,255,0.62);
    box-shadow: 0 5px 0 #0b55c4;
}

.phone-option.category-option:nth-child(2n) {
    background: linear-gradient(135deg, #ff5b7f 0%, #ff8b4b 100%);
    box-shadow: 0 5px 0 #cf4d3d;
}

#fakeAnswerBox.timer-frame {
    margin-top: 10px;
    padding: 7px;
    gap: 10px;
}

#fakeAnswerBox.timer-frame input {
    border-color: transparent;
    box-shadow: none;
    background: var(--input-bg);
}

#fakeAnswerBox.timer-frame button {
    margin: 0;
}

#phoneOptions.options-timer-frame {
    margin-top: 10px;
    padding: 8px;
}

#phoneOptions.options-timer-frame .phone-option:first-child {
    margin-top: 0;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none !important;
    box-shadow: 0 6px 0 rgba(0,0,0,0.18);
}

@keyframes phoneCardIn {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 430px) {
    body {
        padding: 12px;
        align-items: flex-start;
    }

    .panel {
        padding: 22px 16px;
    }

    h1 {
        font-size: 28px;
    }

    .avatar-picker {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .phone-topbar-simple {
        justify-content: center;
    }

    .phone-timer {
        width: 0;
        height: 0;
    }

    .phone-question {
        font-size: 22px;
        margin-bottom: 20px;
    }

    .phone-option {
        font-size: 18px;
        padding: 16px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    body {
        align-items: flex-start;
        padding: 10px;
    }

    .wrap {
        max-width: 900px;
    }

    .panel {
        padding: 16px;
        border-radius: 18px;
    }

    h1 {
        margin-bottom: 12px;
        font-size: 24px;
    }

    .avatar-picker {
        grid-template-columns: repeat(12, minmax(42px, 1fr));
        gap: 8px;
        margin-bottom: 10px;
    }

    .avatar-choice {
        min-height: 42px;
        font-size: 22px;
    }

    .row {
        gap: 10px;
        margin-top: 10px;
    }

    .row.host-control-row {
        flex-direction: row;
        margin-top: 0;
    }

    .host-control-btn {
        width: 42px;
        height: 42px;
        min-width: 42px;
        border-radius: 13px;
    }

    .host-control-icon {
        font-size: 20px;
    }

    input,
    button:not(.host-control-btn) {
        padding: 12px;
        font-size: 16px;
        border-radius: 14px;
    }

    .phone-game-panel {
        min-height: auto;
        justify-content: flex-start;
    }

    .phone-topbar-simple {
        justify-content: flex-end;
        margin-bottom: 8px;
    }

    .phone-timer {
        width: 0;
        height: 0;
    }

    .phone-timer::before {
        inset: 10px;
    }

    .phone-timer::after {
        inset: 24px;
    }

    .phone-question {
        margin: 0 0 12px;
        font-size: 20px;
        line-height: 1.2;
    }

    #phoneOptions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .phone-option {
        margin-top: 0;
        min-height: 64px;
        padding: 12px;
        font-size: 16px;
    }

    #fakeAnswerBox.row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    #fakeAnswerBox input,
    #fakeAnswerBox button {
        width: 100%;
    }

    .fake-answer-hint {
        grid-column: 1 / -1;
        order: 3;
    }

    .phone-feedback-card {
        margin-bottom: 10px;
        padding: 12px;
    }

    .phone-message {
        margin-top: 12px;
        font-size: 16px;
    }
}

.fake-answer-hint {
    margin-top: -8px;
    font-size: 14px;
    font-weight: 900;
    color: #747d8c;
    text-align: right;
}

.fake-answer-hint.warn {
    color: #ffa502;
}

.fake-answer-hint.danger {
    color: #ff4757;
}
