/* style.css - EquaCards Professional Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700;14..32,800;14..32,900&family=Outfit:wght@500;600;700;800&display=swap');

:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --bg2: #f1f3f6;
    --border: #e4e7ec;
    --border2: #d0d4db;
    --text: #1a1d23;
    --text2: #5f6672;
    --text3: #8b919d;
    --blue: #3b6df0;
    --blue2: #2b5cd4;
    --red: #e84c5b;
    --green: #10b981;
    --purple: #7c5ce7;
    --gray50: #f9fafb;
    --gray900: #111827;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 16px 48px rgba(0,0,0,0.12);
    --shadow-sm: 0 4px 12px rgba(0,0,0,0.08);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'SF Mono', 'Consolas', 'Courier New', monospace;
    --transition: 0.2s ease;
}

.theme-dark {
    --bg: #0f1117;
    --surface: #1a1d27;
    --bg2: #222636;
    --border: #2a2d3a;
    --border2: #363a4a;
    --text: #f0f0f8;
    --text2: #a0a0b8;
    --text3: #6b6e7e;
    --gray50: #1a1d27;
    --gray900: #f0f0f8;
}

.theme-ocean {
    --bg: #f0f7fa;
    --surface: #ffffff;
    --bg2: #e8f4f8;
    --border: #c8e0e8;
    --border2: #a0c8d4;
    --text: #1a3a4a;
    --text2: #4a6a7a;
    --text3: #6a8a9a;
    --blue: #0891b2;
    --blue2: #0e7490;
    --gray50: #f0f7fa;
    --gray900: #0a4050;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg);
    font-family: var(--font);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    padding: 20px;
    color: var(--text);
    transition: background 0.4s ease, color 0.4s ease;
    background-image: radial-gradient(ellipse at 50% 0%, rgba(59,109,240,0.06) 0%, transparent 60%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Loading Screen */
.loading-screen {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 1.2s cubic-bezier(.4,0,.2,1);
}
.loading-screen.hide { opacity:300ms; visibility: hidden; pointer-events: none; }
.loading-logo { font-size: 4rem; font-weight: 900; color: var(--blue); animation: logoPulse 2s infinite; }
.loading-title { font-size: 1.5rem; font-weight: 800; font-family: 'Outfit', var(--font); letter-spacing: 0.05em; margin-bottom: 4px; }
.loading-subtitle { font-size: 0.8rem; color: var(--text3); letter-spacing: 3px; text-transform: uppercase; margin-bottom: 30px; }
.loading-bar { width: 200px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.loading-bar-fill { height: 100%; background: var(--blue); border-radius: 2px; animation: loadProgress 2s ease-in-out infinite; }
.loading-credit { position: absolute; bottom: 40px; text-align: center; font-size: 0.8rem; color: var(--text3); }

@keyframes logoPulse { 50% { opacity: 0.6; transform: scale(0.97); } }
@keyframes loadProgress { 0% { width: 0; margin-left: 0; } 50% { width: 60%; margin-left: 20%; } 100% { width: 0; margin-left: 100%; } }

/* App Container */
.app { width: 100%; max-width: 680px; }

/* Screen Management */
.screen { display: none; animation: screenFadeIn 0.3s ease; }
.screen.show { display: block; }
@keyframes screenFadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }

/* Card Base */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 35px 30px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.menu-card { text-align: center; }
.signin-card, .online-play-card, .waiting-card, .profile-card { max-width: 400px; margin: 0 auto; text-align: center; }

/* Screen Titles */
.screen-title { margin-bottom: 5px; font-size: 1.3rem; }
.screen-desc { font-size: 0.8rem; color: var(--text3); margin-bottom: 20px; }
.screen-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

/* Buttons - FIXED for dark theme */
.btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    font-family: var(--font);
    border: 2px solid transparent;
    text-align: center;
    transition: var(--transition);
    margin: 6px 0;
    background: var(--bg2);
    color: var(--text);
    line-height: 1.2;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.primary { background: var(--gray900); color: var(--bg); border-color: var(--gray900); }
.btn.primary:hover { filter: brightness(1.2); }
.btn.accent { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.accent:hover { background: var(--blue2); }
.btn.outline { border-color: var(--border2); }
.btn.outline:hover { background: var(--bg2); }
.btn.warn { border-color: #fde68a; color: #b45309; background: #fffbeb; }
.btn.warn:hover { background: #fef3c7; }
.btn.danger { border-color: #fecaca; color: #dc2626; background: #fef2f2; }
.btn.danger:hover { background: #fee2e2; }
.btn-sm { width: auto; padding: 8px 16px; font-size: 0.7rem; letter-spacing: 0.5px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; font-size: 0.75rem; padding: 12px 10px; }
.btn-row .btn.primary { flex: 2; }
.btn-row-duo { display: flex; gap: 8px; margin: 6px 0; }
.btn-row-duo .btn { flex: 1; }

/* Dark theme button overrides */
.theme-dark .btn {
    background: var(--bg2);
    color: var(--text);
    border-color: var(--border);
}
.theme-dark .btn.primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}
.theme-dark .btn.primary:hover {
    background: var(--text2);
    border-color: var(--text2);
}
.theme-dark .btn.accent {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.theme-dark .btn.accent:hover {
    background: var(--blue2);
    border-color: var(--blue2);
}
.theme-dark .btn.outline {
    background: transparent;
    border-color: var(--border2);
    color: var(--text);
}
.theme-dark .btn.outline:hover {
    background: var(--bg2);
}
.theme-dark .btn.warn {
    background: #451a03;
    border-color: #78350f;
    color: #fbbf24;
}
.theme-dark .btn.warn:hover {
    background: #78350f;
}
.theme-dark .btn.danger {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fca5a5;
}
.theme-dark .btn.danger:hover {
    background: #991b1b;
}

/* Menu */
.menu-logo { font-size: 2.5rem; font-weight: 900; text-align: center; font-family: 'Outfit', var(--font); }
.menu-sub { text-align: center; font-size: 0.75rem; color: var(--text3); letter-spacing: 2px; margin: 5px 0 25px; }
.menu-user-badge { margin-top: 20px; font-size: 0.7rem; color: var(--text3); }
.user-badge-name { color: var(--blue); font-weight: 600; }

/* Stats */
.stats-row { display: flex; justify-content: center; gap: 25px; margin-bottom: 25px; }
.stat-item { text-align: center; }
.stat-val { font-size: 1.5rem; font-weight: 900; font-family: var(--mono); }
.stat-lbl { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text3); }

/* Inputs */
.input-group { margin-bottom: 15px; text-align: left; }
.input-group label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text2); display: block; margin-bottom: 5px; }
.input-group input {
    width: 100%; padding: 12px 15px; border-radius: 8px;
    border: 2px solid var(--border2); font-family: var(--font);
    font-size: 0.9rem; background: var(--bg); color: var(--text);
    outline: none; transition: var(--transition);
}
.input-group input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,109,240,0.1); }
.uppercase-input { text-transform: uppercase; }

/* Dark theme input overrides */
.theme-dark .input-group input {
    background: var(--bg2);
    border-color: var(--border);
    color: var(--text);
}
.theme-dark .input-group input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,109,240,0.2);
}

/* Settings */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.setting-title { font-weight: 600; font-size: 0.9rem; }
.setting-desc { font-size: 0.7rem; color: var(--text3); }
.theme-dots { display: flex; gap: 8px; }
.theme-dot { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: var(--transition); }
.theme-dot.active { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(59,109,240,0.15); }
.theme-dot.light { background: #f8f9fb; border-color: #d0d4db; }
.theme-dot.dark { background: #1a1d27; border-color: #4a4e5e; }
.theme-dot.ocean { background: #e0f0f8; border-color: #a0c8d4; }
select {
    padding: 10px 14px; border-radius: 8px; border: 2px solid var(--border2);
    font-family: var(--font); font-size: 0.85rem; background: var(--bg);
    color: var(--text); cursor: pointer; outline: none; min-width: 150px;
}

/* Dark theme select overrides */
.theme-dark select {
    background: var(--bg2);
    border-color: var(--border);
    color: var(--text);
}

/* Game */
.game-card { padding: 25px 20px; }
.game-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.game-brand { display: flex; align-items: center; gap: 8px; }
.game-level-badge { font-size: 0.65rem; color: var(--blue); font-weight: 700; }
.game-stats { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.gstat {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 15px;
}
.gstat.target { background: #fff9eb; border-color: #fde68a; }
.gstat-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 2px; color: var(--text3); font-weight: 700; }
.gstat-val { font-size: 1.8rem; font-weight: 900; font-family: var(--mono); }
.gstat.target .gstat-val { color: #b45309; }
.gstat.urgent { background: #fef2f2; border-color: #fecaca; animation: urgentPulse 0.8s infinite; }
.gstat.urgent .gstat-val { color: #dc2626; }
@keyframes urgentPulse { 50% { border-color: #f87171; } }

/* Dark theme gstat overrides */
.theme-dark .gstat {
    background: var(--bg2);
    border-color: var(--border);
}
.theme-dark .gstat.target {
    background: #451a03;
    border-color: #78350f;
}
.theme-dark .gstat.target .gstat-val {
    color: #fbbf24;
}
.theme-dark .gstat.urgent {
    background: #7f1d1d;
    border-color: #991b1b;
}
.theme-dark .gstat.urgent .gstat-val {
    color: #f87171;
}

.mini-row { display: flex; flex-direction: column; gap: 6px; }
.mini { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; text-align: center; }
.mini-label { font-size: 0.5rem; text-transform: uppercase; letter-spacing: 2px; color: var(--text3); }
.mini-val { font-size: 1.1rem; font-weight: 800; font-family: var(--mono); }
.mini.combo .mini-val { color: var(--green); }

/* Dark theme mini overrides */
.theme-dark .mini {
    background: var(--bg2);
    border-color: var(--border);
}

.section-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 2px; color: var(--text3); font-weight: 700; margin-bottom: 5px; }
.required-text { color: #dc2626; }

/* Expression Area */
.expr-area {
    background: var(--gray50); border: 2px dashed var(--border2);
    border-radius: 12px; min-height: 75px; padding: 12px 15px;
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
    position: relative; margin-bottom: 20px;
}
.expr-area .ph { color: var(--text3); font-size: 0.85rem; width: 100%; text-align: center; }
.ecard {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 38px; padding: 0 10px; border-radius: 6px;
    font-weight: 700; font-size: 0.9rem; cursor: pointer; font-family: var(--mono);
    border: 2px solid transparent; background: var(--bg); transition: 0.15s;
}
.ecard.num { color: var(--blue); border-color: #c7d7fe; background: #eef3fe; }
.ecard.op { color: var(--red); border-color: #fecdd3; background: #fef0f1; }
.ecard.paren { color: var(--purple); border-color: #ddd6fe; background: #f4f0fd; }
.preview {
    position: absolute; right: 12px; bottom: 8px; font-size: 0.65rem;
    font-weight: 700; padding: 3px 10px; border-radius: 12px; font-family: var(--mono);
    background: var(--bg2); color: var(--text3);
}
.preview.ok { background: #ecfdf5; color: #059669; }
.preview.err { background: #fef2f2; color: #dc2626; }

/* Dark theme expression area overrides */
.theme-dark .expr-area {
    background: var(--bg2);
    border-color: var(--border);
}
.theme-dark .ecard {
    background: var(--bg2);
    color: var(--text);
    border-color: var(--border);
}
.theme-dark .ecard.num {
    background: #1e293b;
    border-color: #334155;
    color: #60a5fa;
}
.theme-dark .ecard.op {
    background: #2a1a1f;
    border-color: #3f1e24;
    color: #f87171;
}
.theme-dark .ecard.paren {
    background: #1f1a2e;
    border-color: #31244a;
    color: #a78bfa;
}
.theme-dark .preview {
    background: var(--bg2);
    color: var(--text3);
}
.theme-dark .preview.ok {
    background: #064e3b;
    color: #34d399;
}
.theme-dark .preview.err {
    background: #7f1d1d;
    color: #f87171;
}

/* Cards Area */
.cards-area {
    display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 15px;
    background: var(--gray50); border-radius: 12px; min-height: 55px;
    align-items: center; border: 1px solid var(--border); margin-bottom: 20px;
}
.acard {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 44px; padding: 0 12px; border-radius: 6px;
    font-weight: 700; font-size: 1.1rem; cursor: pointer; font-family: var(--mono);
    border: 2px solid transparent; background: var(--bg);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04); transition: 0.2s;
}
.acard.num { color: var(--blue); border-color: #c7d7fe; }
.acard.num:hover { border-color: var(--blue); transform: translateY(-2px); }
.acard.op { color: var(--red); border-color: #fecdd3; }
.acard.op:hover { border-color: var(--red); transform: translateY(-2px); }
.acard.paren { color: var(--purple); border-color: #ddd6fe; }
.acard.paren:hover { border-color: var(--purple); transform: translateY(-2px); }

/* Dark theme cards area overrides */
.theme-dark .cards-area {
    background: var(--bg2);
    border-color: var(--border);
}
.theme-dark .acard {
    background: var(--bg2);
    color: var(--text);
    border-color: var(--border);
}
.theme-dark .acard.num {
    background: #1e293b;
    border-color: #334155;
    color: #60a5fa;
}
.theme-dark .acard.num:hover {
    border-color: #60a5fa;
}
.theme-dark .acard.op {
    background: #2a1a1f;
    border-color: #3f1e24;
    color: #f87171;
}
.theme-dark .acard.op:hover {
    border-color: #f87171;
}
.theme-dark .acard.paren {
    background: #1f1a2e;
    border-color: #31244a;
    color: #a78bfa;
}
.theme-dark .acard.paren:hover {
    border-color: #a78bfa;
}

/* Join Code */
.join-code-area { margin-top: 15px; }
.join-code-area.hidden { display: none; }

/* Waiting */
.waiting-code-label { color: var(--text3); font-size: 0.85rem; }
.waiting-code { font-size: 1.5rem; letter-spacing: 0.2em; display: block; margin: 5px 0 15px; }
.waiting-status { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 15px; color: var(--text3); }
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: #f59e0b; animation: dotPulse 1.4s infinite; }
@keyframes dotPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Overlays */
.overlay {
    position: fixed; inset: 0; background: rgba(10,12,16,0.8);
    display: none; align-items: center; justify-content: center;
    z-index: 200; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.overlay.show { display: flex; }
.overlay-content {
    background: var(--surface); border-radius: var(--radius);
    padding: 35px 28px; text-align: center; max-width: 380px;
    width: 90%; box-shadow: var(--shadow);
}
.overlay-icon { font-size: 2.5rem; margin-bottom: 5px; }
.overlay-content h2 { font-size: 1.5rem; margin-bottom: 5px; }
.overlay-content .sub { font-size: 0.8rem; color: var(--text3); margin-bottom: 20px; }
.overlay-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.ostat { background: var(--gray50); padding: 12px; border-radius: 8px; }
.ostat .v { font-size: 1.3rem; font-weight: 900; font-family: var(--mono); display: block; }
.ostat .l { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); }

/* Dark theme overlay stats overrides */
.theme-dark .ostat {
    background: var(--bg2);
}

/* Toast */
.toast-container { position: fixed; top: 25px; right: 25px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: 360px; pointer-events: none; }
.toast {
    padding: 10px 20px; border-radius: 20px; font-weight: 700; font-size: 0.78rem;
    animation: toastIn 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: auto;
}
.toast.removing { opacity: 0; transform: translateX(40px); transition: 0.3s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* Profile */
.profile-avatar {
    width: 80px; height: 80px; border-radius: 50%; background: var(--blue);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: #fff; font-weight: 700; margin: 0 auto 10px;
}
.profile-email { color: var(--text3); font-size: 0.85rem; }

/* Table */
.table-wrap { overflow-x: auto; margin-bottom: 10px; }
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); font-weight: 700; text-align: left; padding: 10px 8px; border-bottom: 2px solid var(--border); }
.leaderboard-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.leaderboard-table td:last-child { text-align: right; }
.table-empty { text-align: center; color: var(--text3); padding: 20px; }

/* Dark theme table overrides */
.theme-dark .leaderboard-table th {
    border-bottom-color: var(--border);
}
.theme-dark .leaderboard-table td {
    border-bottom-color: var(--border);
}

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; }
.history-item {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 15px;
    display: flex; justify-content: space-between; align-items: center;
}
.history-item-detail { font-size: 0.8rem; color: var(--text3); }
.history-item-date { color: var(--text3); font-size: 0.7rem; }

/* Dark theme history overrides */
.theme-dark .history-item {
    background: var(--bg2);
    border-color: var(--border);
}

/* Responsive */
@media (max-width: 540px) {
    body { padding: 10px; }
    .card { padding: 20px 16px; }
    .menu-logo { font-size: 1.8rem; }
    .stats-row { gap: 15px; }
    .game-stats { grid-template-columns: 1fr; }
    .mini-row { flex-direction: row; }
    .mini { flex: 1; }
    .btn-row-duo { flex-direction: column; gap: 0; }
    .overlay-content { padding: 25px 18px; }
    .toast-container { left: 16px; right: 16px; max-width: none; }
}

/* Animation Keyframes */
@keyframes pFly {
    0% { transform: translate(0,0) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(var(--dx),var(--dy)) scale(0.1) rotate(180deg); opacity: 0; }
}
@keyframes shake {
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}
