@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Fredoka+One&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --purple-deep:   #3d1f6e;
    --purple-mid:    #6b4499;
    --purple-panel:  rgba(80, 45, 130, 0.88);
    --purple-border: rgba(60, 30, 100, 0.85);
    --gold:          #f59e0b;
    --gold-light:    #fbbf24;
    --green:         #22c55e;
    --green-dark:    #16a34a;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Nunito', 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #6b4499 0%, #8b5aa8 100%);
    display: flex;
    flex-direction: column;
}

.topbar {
    width: 100%;
    height: 46px;
    flex-shrink: 0;
    background: rgba(30, 10, 65, 0.7);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    padding: 0 18px;
    gap: 10px;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.topbar-logo-mini {
    font-family: 'Fredoka One', cursive;
    font-size: 1rem;
    color: rgba(255,255,255,0.5);
    letter-spacing: 1px;
    margin-right: auto;
}

.topbar-spacer { flex: 1; }

.topbar-link {
    font-family: 'Fredoka One', cursive;
    font-size: 0.9rem;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.08);
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.topbar-link:hover { background: rgba(255,255,255,0.18); color: #fff; }

.lang-selector {
    position: relative;
    z-index: 999;
}

.lang-selector::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 8px;
}

.lang-btn {
    background: rgba(255,255,255,0.12);
    border: 1.5px solid rgba(255,255,255,0.28);
    border-radius: 9px;
    padding: 6px 13px;
    color: white;
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.18s;
    backdrop-filter: blur(6px);
}

.lang-btn:hover {
    background: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.5);
}

.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: auto;
    background: rgba(15, 5, 40, 0.97);
    border: 1.5px solid rgba(255,255,255,0.15);
    border-radius: 11px;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 250px;
    min-width: 150px;
    box-shadow: 0 10px 35px rgba(0,0,0,0.55);
    backdrop-filter: blur(12px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}

.lang-selector:hover .lang-dropdown,
.lang-selector.open .lang-dropdown {
    display: block;
    animation: fadeDown 0.16s ease;
}

@keyframes fadeDown {
    from { opacity: 0; transform: translateY(-5px); }
    to   { opacity: 1; transform: translateY(0); }
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 14px;
    color: white;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    transition: background 0.12s;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.lang-option:last-child { border-bottom: none; }
.lang-option:hover  { background: rgba(255,255,255,0.1); }
.lang-option.active { background: rgba(245,158,11,0.22); color: #fbbf24; }
.lang-flag { font-size: 1.05rem; }

.game-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 15px;
    padding: 15px;
    box-sizing: border-box;
    overflow: hidden;
}

.ad-left, .ad-right {
    width: 200px;
    min-width: 200px;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.ad-left {
    background: linear-gradient(180deg, #8b5cf6 0%, #7c3aed 100%);
}

.ad-right {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
}

.ad-left::before, .ad-right::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><circle cx="10" cy="10" r="2" fill="rgba(255,255,255,0.1)"/><circle cx="30" cy="20" r="3" fill="rgba(255,255,255,0.05)"/><circle cx="20" cy="35" r="1" fill="rgba(255,255,255,0.1)"/></svg>') repeat;
    animation: float-pattern 20s linear infinite;
    z-index: 1;
}

@keyframes float-pattern {
    0%   { transform: translate(0,0) rotate(0deg); }
    100% { transform: translate(-20px,-20px) rotate(360deg); }
}

.ad-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 10px 8px;
    color: white;
    flex-shrink: 0;
}

.ad-title {
    font-family: 'Fredoka One', cursive;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 6px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    letter-spacing: 0.5px;
}

.ad-label {
    display: inline-block;
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    padding: 2px 9px;
    border-radius: 20px;
    background: rgba(0,0,0,0.2);
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.18);
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.ad-slot-wrap {
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 0 0 8px;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
}

.adsbygoogle {
    background: rgba(255,255,255,0.1) !important;
    border-radius: 12px !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    display: block;
    width: 100% !important;
    flex: 1;
    min-height: 0 !important;
}

.ad-placeholder {
    width: 100%;
    flex: 1;
    min-height: 0;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    border: 1px dashed rgba(255,255,255,0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50%       { opacity: 1; }
}

.ad-placeholder-icon {
    font-size: 2rem;
    opacity: 0.5;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}

.ad-placeholder-text {
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0.6;
    text-align: center;
    line-height: 1.4;
    color: white;
}

.game-center {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7%;
    overflow: hidden;
}

.logo-header { text-align: center; flex-shrink: 0; }

.logo-circle {
    width: min(18vh, 160px);
    height: min(18vh, 160px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    padding: 6px;
    filter: drop-shadow(0 5px 16px rgba(0,0,0,0.4));
}

.logo-circle img { width: 130%; height: 130%; object-fit: contain; }

.auth-container {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    align-items: start;
    flex-shrink: 1;
    min-height: 0;
}

.auth-box {
    background: var(--purple-panel);
    border: 3px solid var(--purple-border);
    border-radius: 20px;
    padding: 20px 17px;
    backdrop-filter: blur(12px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-box h2 {
    color: white;
    text-align: center;
    font-family: 'Fredoka One', cursive;
    font-size: 1.28rem;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.form-group { margin-bottom: 11px; }

.form-group label {
    display: block;
    margin-bottom: 4px;
    color: rgba(255,255,255,0.9);
    font-weight: 700;
    font-size: 0.82rem;
}

.form-group input {
    width: 100%;
    padding: 9px 12px;
    border: 2px solid rgba(255,255,255,0.4);
    background: rgba(255,255,255,0.95);
    border-radius: 9px;
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: #2d1060;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--gold);
    background: white;
    box-shadow: 0 0 0 3px rgba(245,158,11,0.2);
}

.btn-primary {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 11px;
    background: white;
    color: var(--purple-deep);
    font-family: 'Fredoka One', cursive;
    font-size: 0.97rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    letter-spacing: 0.4px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 18px rgba(0,0,0,0.28);
    background: #f8f4ff;
}

.btn-primary:active { transform: translateY(-1px); }

.anon-section { text-align: center; }

.anon-avatar {
    width: 78px;
    height: 78px;
    background: rgba(60, 30, 100, 0.6);
    border: 4px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 5px 14px rgba(0,0,0,0.3);
    transition: border-color 0.25s;
}

.anon-avatar:hover { border-color: var(--gold-light); }
.anon-avatar img { width: 100%; height: 100%; object-fit: cover; }

.anon-section h3 {
    color: rgba(255,255,255,0.9);
    font-family: 'Fredoka One', cursive;
    font-size: 0.88rem;
    margin-bottom: 9px;
}

.btn-anon {
    background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.97rem;
    box-shadow: 0 4px 12px rgba(34,197,94,0.35) !important;
}

.btn-anon:hover {
    background: linear-gradient(135deg, #4ade80 0%, var(--green) 100%) !important;
    box-shadow: 0 8px 20px rgba(34,197,94,0.45) !important;
}

.play-icon {
    width: 0; height: 0;
    border-left: 11px solid white;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

.avatar-option {
    width: 100%;
    aspect-ratio: 1;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    background: rgba(60, 30, 100, 0.4);
}

.avatar-option img { width: 100%; height: 100%; object-fit: cover; }
.avatar-option:hover { transform: scale(1.08); border-color: var(--gold-light); }
.avatar-option.selected {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(245,158,11,0.3);
    transform: scale(1.05);
}

.error-message, .success-message {
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 700;
    font-size: 0.87rem;
    display: none;
    animation: slideDown 0.22s ease;
    width: 100%;
    flex-shrink: 0;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to   { opacity: 1; transform: translateY(0); }
}

.error-message   { background: #fef2f2; color: #991b1b; border: 2px solid #fca5a5; }
.success-message { background: #f0fdf4; color: #14532d; border: 2px solid #86efac; }

.main-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

@media (max-width: 1200px) {
    html, body { overflow: auto; height: auto; }
    html { background: #6b4499; -webkit-text-size-adjust: 100%; }
    body {
        min-height: 100vh;
        min-height: 100dvh;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .topbar {
        position: sticky; top: 0;
        padding-top: env(safe-area-inset-top);
        height: calc(46px + env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .ad-left, .ad-right { display: none; }

    .game-layout { gap: 0; padding: 0; overflow: visible; flex: none; }

    .game-center {
        justify-content: flex-start;
        padding: 16px 14px calc(28px + env(safe-area-inset-bottom));
        gap: 14px;
        overflow: visible;
    }

    .auth-container {
        grid-template-columns: 1fr;
        max-width: 460px;
        margin: 0 auto;
        gap: 16px;
    }

    .logo-circle { width: 150px; height: 150px; padding: 0; }
    .logo-circle img { width: 125%; height: 125%; }

    .auth-box { padding: 22px 18px; border-radius: 22px; border-width: 2px; }
    .auth-box h2 { font-size: 1.35rem; margin-bottom: 16px; }

    .form-group { margin-bottom: 14px; }
    .form-group label { font-size: 0.9rem; margin-bottom: 6px; }
    .form-group input {
        min-height: 50px;
        padding: 12px 14px;
        font-size: 16px;
        border-radius: 12px;
    }
    .btn-primary {
        min-height: 52px;
        padding: 13px;
        font-size: 1.08rem;
        border-radius: 14px;
    }

    .anon-avatar { width: 88px; height: 88px; }
    .anon-section h3 { font-size: 0.95rem; }
    .avatar-grid { gap: 10px; }
    .avatar-option { border-radius: 14px; }
    .avatar-option:hover { transform: none; }
    .avatar-option.selected { transform: scale(1.06); }

    .auth-box .auth-switch-btn {
        position: static;
        display: block;
        margin: 0 0 10px auto;
        min-height: 38px;
        padding: 8px 14px;
        font-size: 0.82rem;
        border-radius: 10px;
    }

    .auth-box .login-extras { margin-top: 0; margin-bottom: 14px; gap: 10px; }
    .auth-box .remember-label { font-size: 0.88rem; min-height: 40px; gap: 8px; }
    .auth-box .remember-label input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--gold); }
    .auth-box .forgot-link { font-size: 0.88rem; padding: 10px 0; }
    .auth-box .forgot-desc { font-size: 0.9rem; }

    .auth-box .oauth-divider { margin: 16px 0 12px; }
    .auth-box .oauth-divider span { font-size: 0.8rem; }
    .auth-box .oauth-btns { gap: 10px; }
    .auth-box .btn-oauth {
        min-height: 50px;
        padding: 12px;
        font-size: 1rem;
        border-radius: 14px;
    }
    .auth-box .oauth-icon { width: 22px; height: 22px; }

    .lang-btn { min-height: 36px; }
    .lang-option { min-height: 46px; padding: 10px 16px; font-size: 0.95rem; }

    .auth-box.howto-panel { display: none; }
}

@media (hover: none) {
    .btn-primary:hover, .btn-oauth:hover, .auth-switch-btn:hover { transform: none; }
    .btn-primary:active, .btn-oauth:active, .auth-switch-btn:active, .avatar-option:active {
        transform: scale(0.97);
        transition-duration: 0.08s;
    }
    .lang-selector:hover .lang-dropdown { display: none; }
    .lang-selector.open .lang-dropdown { display: block; }
}

@media (max-width: 768px) {
    .game-center { padding-top: 12px; }
}

@media (max-width: 480px) {
    .topbar-logo-mini { font-size: 0.95rem; }
    .game-center { padding-left: 12px; padding-right: 12px; gap: 12px; }
    .logo-circle { width: 124px; height: 124px; }
    .auth-box { padding: 20px 16px; border-radius: 20px; }
    .auth-box h2 { font-size: 1.25rem; margin-bottom: 14px; }
    .anon-avatar { width: 78px; height: 78px; margin-bottom: 8px; }
}

@media (max-width: 360px) {
    .auth-box { padding: 18px 13px; }
    .logo-circle { width: 108px; height: 108px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 1400px) {
    .ad-left, .ad-right { width: 220px; min-width: 220px; }
    .logo-circle { width: 185px; height: 185px; }
    .auth-box { padding: 24px 22px; }
    .auth-box h2 { font-size: 1.42rem; }
}

@media (min-width: 1201px) and (max-height: 720px) {

    .topbar { height: 40px; }
    .game-layout { padding: 10px 15px; gap: 12px; }

    .game-center {
        justify-content: flex-start;
        gap: 10px;
        overflow-x: hidden;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.25) transparent;
    }
    .game-center > .logo-header    { margin-top: auto; }
    .game-center > .auth-container { margin-bottom: auto; flex-shrink: 0; gap: 12px; }

    .logo-circle { width: min(16vh, 120px); height: min(16vh, 120px); padding: 0; }

    .auth-box { padding: 14px 15px; border-radius: 18px; }
    .auth-box h2 { font-size: 1.15rem; margin-bottom: 9px; }

    .auth-box .auth-switch-btn { top: 8px; right: 10px; font-size: 0.68rem; padding: 3px 9px; }
    .auth-box.login-panel h2,
    .auth-box.register-panel h2 { margin-top: 20px; }

    .auth-box .form-group { margin-bottom: 8px; }
    .auth-box .form-group label { margin-bottom: 3px; font-size: 0.78rem; }
    .auth-box .form-group input { padding: 7px 11px; font-size: 0.86rem; }
    .auth-box .login-extras { margin-top: 0; }
    .auth-box .btn-primary { padding: 9px; font-size: 0.92rem; margin-top: 3px; }
    .auth-box .oauth-divider { margin: 8px 0 6px; }
    .auth-box .oauth-btns { gap: 6px; margin-top: 2px; }
    .auth-box .btn-oauth { padding: 7px 12px; font-size: 0.84rem; }

    .anon-avatar { width: 62px; height: 62px; margin-bottom: 7px; border-width: 3px; }
    .anon-section h3 { margin-bottom: 7px; font-size: 0.82rem; }
    .anon-section .avatar-grid { gap: 6px; margin-bottom: 10px !important; }
    .anon-section .form-group { margin-bottom: 10px !important; }

    .auth-box.howto-panel { padding: 14px 12px 12px; }
    .howto-slide { padding: 6px 6px 26px; }
}

@media (min-width: 1201px) and (max-height: 600px) {
    .logo-circle { width: 84px; height: 84px; }
    .auth-box { padding: 11px 14px; }
    .auth-box h2 { font-size: 1.05rem; margin-bottom: 7px; }
    .auth-box.login-panel h2,
    .auth-box.register-panel h2 { margin-top: 16px; }
    .auth-box .form-group { margin-bottom: 6px; }
    .auth-box .form-group input { padding: 6px 10px; }
    .auth-box .btn-primary { padding: 7px; }
    .auth-box .btn-oauth { padding: 6px 12px; }
    .anon-avatar { width: 52px; height: 52px; margin-bottom: 5px; }
}