/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary:      #111111;
    --bg-secondary:    #191919;
    --bg-card:         #1c1c1c;
    --bg-card-hover:   #232323;
    --bg-input:        #181818;
    --text-primary:    #ffffff;
    --text-secondary:  #9a9a9a;
    --text-muted:      #5a5a5a;
    --accent:          #ee7a30;
    --accent-dim:      rgba(238,122,48,.15);
    --border:          #272727;
    --border-light:    #333;
    --btn-light-bg:    #e9e9e9;
    --btn-light-text:  #111;
    --error:           #ff4d4d;
    --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px; --r-full: 999px;
    --ease: cubic-bezier(.4,0,.2,1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #080808;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== POPUP ===== */
.popup-container {
    width: 375px;
    height: 620px;
    background: var(--bg-primary);
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    box-shadow:
        0 0 0 1px rgba(255,255,255,.06),
        0 32px 64px -16px rgba(0,0,0,.85),
        0 0 100px rgba(238,122,48,.04);
}

/* ===== PAGES ===== */
.page {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(28px);
    pointer-events: none;
    transition: opacity .32s var(--ease), transform .32s var(--ease);
    overflow-y: auto;
    overflow-x: hidden;
}
.page.active  { opacity: 1; transform: translateX(0); pointer-events: auto; }
.page.exit-left { opacity: 0; transform: translateX(-28px); }

/* ===== PAGE 1: WELCOME ===== */
.welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 28px 28px 32px;
    text-align: center;
    gap: 0;
}

/* ===== LANGUAGE DROPDOWN ===== */
.lang-dropdown-wrap {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 50;
}

.lang-trigger {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px 8px 11px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
    white-space: nowrap;
    user-select: none;
}
.lang-trigger:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}
.lang-trigger.open {
    background: var(--bg-card-hover);
    border-color: rgba(238,122,48,.4);
    color: var(--text-primary);
}

.lang-globe { display: flex; align-items: center; color: var(--accent); }

.lang-chevron {
    display: flex;
    align-items: center;
    transition: transform .25s var(--ease);
    color: var(--text-muted);
}
.lang-trigger.open .lang-chevron { transform: rotate(180deg); }

/* Dropdown menu */
.lang-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 168px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--r-lg);
    padding: 6px;
    box-shadow:
        0 8px 32px rgba(0,0,0,.6),
        0 2px 8px rgba(0,0,0,.4),
        0 0 0 1px rgba(255,255,255,.04);
    opacity: 0;
    transform: translateY(-6px) scale(.97);
    transform-origin: top right;
    pointer-events: none;
    transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.lang-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--r-md);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    text-align: left;
}
.lang-option:hover { background: rgba(255,255,255,.05); color: var(--text-primary); }
.lang-option.active { color: var(--text-primary); }

.lang-flag { font-size: 18px; line-height: 1; }
.lang-name  { flex: 1; }

.lang-check { color: var(--accent); display: flex; align-items: center; }
.lang-check.hidden { visibility: hidden; }

/* Separator between options */
.lang-option + .lang-option {
    border-top: 1px solid rgba(255,255,255,.04);
}

/* ===== LOGO AREA ===== */
.logo-area {
    position: relative;
    width: 190px;
    height: 190px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.circle-decoration {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.055);
}
.circle-1 { width: 270px; height: 270px; animation: spin-slow 22s linear infinite; }
.circle-2 { width: 210px; height: 210px; animation: spin-slow 16s linear infinite reverse; }

@keyframes spin-slow { to { transform: rotate(360deg); } }

.logo-img {
    width: 78px;
    height: 78px;
    border-radius: 18px;
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 8px 24px rgba(238,122,48,.22));
}

.welcome-title {
    font-size: 23px;
    font-weight: 600;
    line-height: 1.38;
    margin-bottom: 40px;
    letter-spacing: -.3px;
}

/* ===== BUTTONS ===== */
.welcome-buttons { width: 100%; display: flex; flex-direction: column; gap: 11px; }

.btn {
    width: 100%;
    padding: 15px 24px;
    border-radius: var(--r-md);
    border: none;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all .25s var(--ease);
    letter-spacing: -.1px;
}
.btn-primary { background: var(--btn-light-bg); color: var(--btn-light-text); }
.btn-primary:hover  { background: #fff; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(255,255,255,.1); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover  { background: var(--bg-card-hover); border-color: var(--border-light); transform: translateY(-1px); }
.btn-secondary:active { transform: translateY(0); }

/* ===== PAGE HEADER ===== */
.page-header { padding: 18px 20px 6px; flex-shrink: 0; }

.back-btn {
    background: none; border: none; color: var(--text-primary);
    cursor: pointer; padding: 5px; border-radius: var(--r-sm);
    display: flex; align-items: center; justify-content: center;
    transition: background .2s;
}
.back-btn:hover { background: rgba(255,255,255,.06); }

/* ===== PAGE BODY ===== */
.page-body { padding: 6px 24px 28px; flex: 1; display: flex; flex-direction: column; }

.page-title   { font-size: 23px; font-weight: 700; margin-bottom: 10px; letter-spacing: -.5px; }
.page-desc    { font-size: 14px; color: var(--text-secondary); line-height: 1.65; margin-bottom: 24px; }

/* ===== RESTORE OPTIONS ===== */
.restore-options { display: flex; flex-direction: column; gap: 10px; }

.restore-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    cursor: pointer;
    transition: all .22s var(--ease);
    text-align: left;
    width: 100%;
    font-family: inherit;
    color: var(--text-primary);
}
.restore-option:hover  { background: var(--bg-card-hover); border-color: var(--border-light); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.restore-option:active { transform: translateY(0); }

.option-icon    { width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-secondary); }
.option-text    { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.option-title   { font-size: 14.5px; font-weight: 600; }
.option-subtitle{ font-size: 12.5px; color: var(--text-secondary); line-height: 1.4; }
.option-arrow   { color: var(--text-muted); flex-shrink: 0; }

/* ===== SEED PAGE ===== */
.seed-body { position: relative; }

.input-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--r-md);
    padding: 3px;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}
.tab-btn {
    flex: 1; padding: 10px 14px;
    border: none; background: transparent;
    color: var(--text-muted);
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; border-radius: 9px;
    transition: all .2s var(--ease);
}
.tab-btn.active  { background: var(--bg-card-hover); color: var(--text-primary); }
.tab-btn:hover:not(.active) { color: var(--text-secondary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.input-label {
    display: block; font-size: 13.5px; font-weight: 500;
    color: var(--text-secondary); margin-bottom: 9px;
}

.seed-textarea {
    width: 100%; min-height: 118px; padding: 15px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-family: 'Inter', monospace; font-size: 13.5px; line-height: 1.65;
    resize: none; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.seed-textarea::placeholder { color: var(--text-muted); }
.seed-textarea:focus  { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(238,122,48,.1); }
.seed-textarea.error  { border-color: var(--error); box-shadow: 0 0 0 3px rgba(255,77,77,.1); }
.seed-textarea.valid  { border-color: #3ecf8e; box-shadow: 0 0 0 3px rgba(62,207,142,.08); }

/* Word count / hint below textarea */
.input-hint {
    margin-top: 7px;
    font-size: 12px;
    color: var(--text-muted);
    min-height: 16px;
    transition: color .2s;
}
.input-hint.ok   { color: #3ecf8e; }
.input-hint.warn { color: var(--accent); }
.input-hint.err  { color: var(--error); }

/* Help link */
.help-link {
    display: flex; align-items: center; gap: 7px;
    margin-top: 14px; color: var(--text-secondary);
    font-size: 13px; cursor: pointer; transition: color .2s;
}
.help-link:hover { color: var(--text-primary); }

/* ===== ERROR MESSAGE ===== */
.error-message {
    margin-top: 14px; padding: 13px 15px;
    background: rgba(255,77,77,.07);
    border: 1px solid rgba(255,77,77,.18);
    border-radius: var(--r-md);
    color: var(--error); font-size: 13px; font-weight: 500;
    display: flex; align-items: flex-start; gap: 8px;
    animation: shake .38s var(--ease);
}
.error-message::before { content: "⚠"; font-size: 15px; flex-shrink: 0; margin-top: 1px; }

@keyframes shake {
    0%,100% { transform: translateX(0); }
    20%      { transform: translateX(-5px); }
    40%      { transform: translateX(5px); }
    60%      { transform: translateX(-3px); }
    80%      { transform: translateX(3px); }
}

.hidden { display: none !important; }

/* ===== FOOTER ===== */
.seed-footer { margin-top: auto; padding-top: 18px; }

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: absolute; inset: 0;
    background: rgba(14,14,14,.94);
    backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    animation: fadeIn .28s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.loading-content { display: flex; flex-direction: column; align-items: center; gap: 22px; }

/* Double-ring spinner */
.spinner-ring {
    width: 52px; height: 52px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,.07);
    border-top-color: var(--accent);
    animation: spin .75s linear infinite;
    position: relative;
}
.spinner-inner {
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,.04);
    border-bottom-color: rgba(238,122,48,.4);
    animation: spin .5s linear infinite reverse;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text  { font-size: 14.5px; color: var(--text-secondary); font-weight: 500; }

/* ===== SCROLLBAR ===== */
.page::-webkit-scrollbar { width: 3px; }
.page::-webkit-scrollbar-track { background: transparent; }
.page::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

/* ===== RTL ===== */
.rtl { direction: rtl; }
.rtl .page-body,
.rtl .option-text,
.rtl .help-link,
.rtl .error-message { text-align: right; }
.rtl .restore-option { flex-direction: row-reverse; }
.rtl .option-arrow svg { transform: rotate(180deg); }
.rtl .back-btn svg    { transform: rotate(180deg); }
.rtl .help-link       { flex-direction: row-reverse; }
.rtl .error-message   { flex-direction: row-reverse; }
.rtl .seed-textarea   { direction: rtl; text-align: right; }

/* RTL: flip dropdown to left side */
.rtl .lang-dropdown-wrap { right: auto; left: 20px; }
.rtl .lang-menu { right: auto; left: 0; transform-origin: top left; }

/* ===== RESPONSIVE ===== */
@media (max-width: 400px) {
    .popup-container { width: 100vw; height: 100vh; border-radius: 0; }
}
