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

:root {
    --bg: #7ee0ff;
    --surface: #ffffff;
    --surface2: #f0fdf4;
    --text: #334155;
    --sub: #94a3b8;
    --accent: #8b5cf6;
    --accent2: #f472b6;
    --green: #10b981;
    --red: #ef4444;
    --gold: #f59e0b;
    --shadow: rgba(0,0,0,0.1);
    --border: #cbd5e1;
    --r: 24px;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg) url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="20" cy="20" r="4" fill="white" opacity="0.2"/><circle cx="70" cy="60" r="8" fill="white" opacity="0.2"/><circle cx="40" cy="90" r="3" fill="white" opacity="0.2"/></svg>') repeat;
    color: var(--text);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, .btn, nav .logo, .tab, .title, .card-name, .st-n, .res-v {
    font-family: 'Fredoka', 'Nunito', sans-serif;
}

/* ======= Animations ======= */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

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

@keyframes float {
    0% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
    100% { transform: translateY(0); }
}

.anim-pop { animation: pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.anim-shake { animation: shake 0.3s ease-in-out; }

/* ======= Buttons ======= */
.btn {
    border: none; cursor: pointer;
    border-radius: 999px; padding: 14px 32px; font-size: 1.1rem; font-weight: 600;
    transition: transform 0.1s, box-shadow 0.1s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    letter-spacing: 0.5px;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(6px) !important; box-shadow: 0 0 0 transparent !important; }

.btn-accent  { background: var(--accent); color: white; border: 2px solid #7c3aed; box-shadow: 0 6px 0 #7c3aed, 0 8px 16px var(--shadow); }
.btn-green   { background: var(--green); color: white; border: 2px solid #059669; box-shadow: 0 6px 0 #059669, 0 8px 16px var(--shadow); }
.btn-gold    { background: var(--gold); color: white; border: 2px solid #d97706; box-shadow: 0 6px 0 #d97706, 0 8px 16px var(--shadow); }
.btn-red     { background: var(--red); color: white; border: 2px solid #dc2626; box-shadow: 0 6px 0 #dc2626, 0 8px 16px var(--shadow); }
.btn-ghost   { background: white; color: var(--sub); border: 2px solid var(--border); box-shadow: 0 6px 0 var(--border); }
.btn-ghost:hover { background: #f8fafc; color: var(--text); border-color: #94a3b8; box-shadow: 0 6px 0 #94a3b8; }

.btn-sm { padding: 10px 20px; font-size: .95rem; box-shadow: 0 4px 0 currentColor; }
.btn-sm:active { transform: translateY(4px) !important; }

/* ======= Layout ======= */
.screen { display: none; height: 100%; flex-direction: column; width: 100%; }
.screen.active { display: flex; animation: float 1.5s ease-out forwards; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ======= Shared Game Panels ======= */
.game-panel {
    background: var(--surface);
    border: 4px solid white;
    border-radius: var(--r);
    box-shadow: 0 10px 0 rgba(0,0,0,0.06), 0 16px 24px rgba(0,0,0,0.1);
}

/* ======= Login ======= */
.login-wrap {
    max-width: 440px; margin: 80px auto; padding: 40px; text-align: center;
    background: var(--surface); border: 4px solid white; border-radius: 36px;
    box-shadow: 0 12px 0 rgba(0,0,0,0.08), 0 20px 40px rgba(0,0,0,0.15);
    position: relative; z-index: 10;
}
.login-wrap h1 { font-size: 2.8rem; color: var(--accent); margin-bottom: 8px; text-shadow: 0 4px 0 #d8b4fe; }
.login-wrap p { color: var(--sub); font-weight: 700; font-size: 1.2rem; margin-bottom: 30px; }

.user-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }
.user-btn {
    width: 100%; padding: 18px; border-radius: 20px;
    background: white; border: 3px solid var(--border);
    font-family: inherit; font-weight: 800; font-size: 1.2rem;
    color: var(--text); cursor: pointer; transition: 0.1s;
    box-shadow: 0 6px 0 var(--border);
}
.user-btn:hover { border-color: var(--accent2); color: var(--accent2); box-shadow: 0 6px 0 var(--accent2); transform: translateY(-2px); }
.user-btn:active { transform: translateY(4px); box-shadow: 0 0 0 transparent; }

.sep { height: 4px; background: #f1f5f9; border-radius: 4px; margin: 30px 0; }

.create-form { display: flex; flex-direction: column; gap: 14px; }
.create-form input {
    padding: 16px 20px; background: #f8fafc; border: 3px solid #e2e8f0;
    border-radius: 18px; font-family: inherit; font-weight: 700; font-size: 1.1rem;
    color: var(--text); outline: none; transition: 0.2s;
}
.create-form input::placeholder { color: #cbd5e1; }
.create-form input:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 4px #ddd6fe; }

/* ======= Nav ======= */
nav {
    display: flex; align-items: center; gap: 16px;
    padding: 18px 30px; background: rgba(255,255,255,0.9);
    backdrop-filter: blur(10px); border-bottom: 4px solid rgba(255,255,255,0.5);
    margin-bottom: 20px; border-radius: 0 0 30px 30px; box-shadow: 0 8px 16px rgba(0,0,0,0.05);
    flex-shrink: 0;
}
nav .logo { font-weight: 900; color: var(--accent); font-size: 1.5rem; margin-right: auto; }
nav .uname { color: var(--accent2); font-weight: 800; font-size: 1.2rem; background: #fce7f3; padding: 6px 16px; border-radius: 50px; }

/* ======= Main ======= */
main { 
    max-width: 900px; width: 100%; margin: 0 auto; padding: 0 20px 20px; 
    flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.view { display: none; animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ======= Picker ======= */
.picker-box {
    background: var(--surface); border: 4px solid white; border-radius: 36px;
    box-shadow: 0 12px 0 rgba(0,0,0,0.06), 0 20px 40px rgba(0,0,0,0.1); overflow: hidden;
    display: flex; flex-direction: column; flex: 1;
}
.tabs {
    display: flex; padding: 10px; background: #f8fafc; border-bottom: 4px solid #e2e8f0; gap: 8px;
    overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
}
.tab {
    flex: 1; padding: 14px 12px; font-weight: 700; font-size: 1.1rem;
    background: white; border: 3px solid var(--border); color: var(--sub);
    border-radius: 20px; cursor: pointer; transition: 0.15s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 4px 0 var(--border); min-width: 130px;
}
.tab:hover { background: #f1f5f9; transform: translateY(-2px); }
.tab:active { transform: translateY(2px); box-shadow: 0 0 0 transparent; }
.tab.on {
    color: white; background: var(--accent); border-color: #7c3aed; box-shadow: 0 4px 0 #7c3aed; transform: translateY(-2px);
}
.tab.on svg { filter: drop-shadow(0 2px 0 rgba(0,0,0,0.2)); }

.cards-area { padding: 24px; background: white; flex: 1; overflow-y: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card {
    padding: 20px; background: white; border: 3px solid var(--border);
    border-radius: 20px; cursor: pointer; font-family: inherit; text-align: left;
    transition: 0.1s; box-shadow: 0 6px 0 var(--border);
}
.card:hover { border-color: var(--green); box-shadow: 0 6px 0 var(--green); transform: translateY(-4px); }
.card:active { transform: translateY(2px); box-shadow: 0 0 0 transparent; }
.card-name { font-weight: 800; font-size: 1.4rem; margin-bottom: 4px; color: var(--text); }
.card-sub { font-size: 1rem; color: var(--sub); font-weight: 700; }

/* ======= Typing ======= */
.type-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-shrink: 0; }
.type-bar .title { flex: 1; text-align: left; font-size: 1.4rem; color: white; text-shadow: 0 4px 0 rgba(0,0,0,0.1); margin-left: 12px; }

.live-stats {
    display: flex; gap: 8px; background: white; padding: 6px 12px;
    border-radius: 20px; border: 3px solid var(--border); box-shadow: 0 4px 0 var(--border);
}
.lst { font-family: 'Fredoka', 'Nunito', sans-serif; font-size: 1rem; font-weight: 700; color: var(--sub); display: flex; align-items: center; gap: 6px; padding: 0 8px; border-right: 2px solid #f1f5f9; }
.lst:last-child { border-right: none; }
.lst b { font-size: 1.3rem; color: var(--accent2); }

.prog { flex-shrink: 0; height: 16px; background: rgba(255,255,255,0.4); border: 3px solid white; border-radius: 20px; margin-bottom: 16px; box-shadow: inset 0 4px 10px rgba(0,0,0,0.05); }
.prog-fill { height: 100%; width: 0; background: var(--green); border-radius: 12px; transition: width 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: inset 0 -4px 0 rgba(0,0,0,0.1); }

.type-area {
    background: white; border: 4px solid var(--border); border-radius: 36px;
    overflow: hidden; margin-bottom: 16px; box-shadow: 0 10px 0 var(--border), 0 20px 40px rgba(0,0,0,0.1);
    transition: 0.2s; position: relative;
    display: flex; flex-direction: column; flex: 1; /* Allow it to flex properly */
    cursor: text;
}
.type-area.on { border-color: var(--accent); box-shadow: 0 10px 0 #7c3aed, 0 20px 50px rgba(139,92,246,0.3); }

.display {
    padding: 36px 48px; font-family: 'Courier New', Courier, monospace;
    font-size: 3rem; font-weight: bold; line-height: 1.8;
    user-select: none; text-align: left; white-space: pre-wrap; /* Crucial for space width and left-align non-bouncing! */
    flex: 1; overflow-y: auto; overflow-x: hidden;
}
.display span {
    border-radius: 6px;
    border-bottom: 4px solid transparent; 
}
.ch-ok  { color: var(--green); text-shadow: 0 2px 0 #059669; }
.ch-err { color: white; background: var(--red); border-bottom-color: #dc2626; box-shadow: 0 0 0 2px var(--red); }
.ch-now { background: #f1f5f9; color: var(--accent); border-bottom-color: var(--accent); }
.ch-wait { color: var(--sub); opacity: 0.5; }

.input-box {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.input-box:focus { opacity: 0; }

.stats { display: flex; gap: 16px; justify-content: center; }
.st {
    text-align: center; padding: 16px 24px; background: white;
    border: 4px solid white; border-radius: 24px; min-width: 140px;
    box-shadow: 0 8px 0 rgba(0,0,0,0.05), 0 12px 24px rgba(0,0,0,0.05);
}
.st-n { font-size: 2.4rem; color: var(--accent2); text-shadow: 0 3px 0 #fbcfe8; }
.st-l { font-size: 1rem; font-weight: 800; color: var(--sub); text-transform: uppercase; }

/* ======= Keyboard ======= */
.kb {
    margin-top: 4px; padding: 14px; background: white;
    border: 4px solid white; border-radius: 28px; display: flex; flex-direction: column;
    gap: 6px; align-items: center; box-shadow: 0 8px 0 rgba(0,0,0,0.05);
    flex-shrink: 0; /* Keyboard stays solid and fixed */
}
.kb.hidden { display: none; }
.kb-row { display: flex; gap: 4px; }
.k {
    width: 38px; height: 42px; display: flex; align-items: center; justify-content: center;
    border-radius: 10px; font-size: 0.95rem; font-weight: 800;
    background: #f8fafc; border: 2px solid var(--border); border-bottom: 5px solid var(--border);
    transition: 0.1s; color: var(--text); user-select: none;
}
.k.dn { background: #cbd5e1; border-color: var(--sub); } /* Pure color change, ZERO movement */
.k.hi { background: #fef08a !important; color: #854d0e !important; border-color: #facc15 !important; } /* Highlight next key */
.k-sp { width: 170px; }
.k-w15 { width: 56px; }
.k-w175 { width: 66px; }
.k-w2 { width: 76px; }
.k-w225 { width: 86px; font-size: 0.8rem; }

/* Finger coloring */
.k[data-f="lp"] { background: #fdf2f8; border-color: #fbcfe8; color: #db2777; }
.k[data-f="lr"] { background: #fffbeb; border-color: #fde68a; color: #d97706; }
.k[data-f="lm"] { background: #ecfdf5; border-color: #a7f3d0; color: #059669; }
.k[data-f="li"], .k[data-f="ri"] { background: #eff6ff; border-color: #bfdbfe; color: #2563eb; }
.k[data-f="rm"] { background: #ecfdf5; border-color: #a7f3d0; color: #059669; }
.k[data-f="rr"] { background: #fffbeb; border-color: #fde68a; color: #d97706; }
.k[data-f="rp"] { background: #fdf2f8; border-color: #fbcfe8; color: #db2777; }

.k.hi {
    z-index: 10;
    color: white !important; text-shadow: 0 2px 0 rgba(0,0,0,0.2);
    border-bottom-width: 5px; /* Match base .k */
}
.k.hi[data-f="lp"] { background: #db2777; border-color: #9d174d; }
.k.hi[data-f="lr"] { background: #d97706; border-color: #92400e; }
.k.hi[data-f="lm"] { background: #059669; border-color: #065f46; }
.k.hi[data-f="li"], .k.hi[data-f="ri"] { background: #2563eb; border-color: #1e40af; }
.k.hi[data-f="rm"] { background: #059669; border-color: #065f46; }
.k.hi[data-f="rr"] { background: #d97706; border-color: #92400e; }
.k.hi[data-f="rp"] { background: #db2777; border-color: #9d174d; }
.k.hi.dn { border-bottom-width: 0; filter: brightness(0.9); }

/* ======= Modal ======= */
.modal {
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(15,23,42,0.6); backdrop-filter: blur(8px);
    align-items: center; justify-content: center;
}
.modal.active { display: flex; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.mbox {
    background: var(--surface); padding: 40px; border: 6px solid white; border-radius: 36px;
    max-width: 480px; width: 92%; text-align: center;
    box-shadow: 0 20px 0 rgba(0,0,0,0.1), 0 30px 60px rgba(0,0,0,0.2);
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.mbox.wide { max-width: 720px; }
.mbox h2 { font-size: 2.5rem; margin-bottom: 24px; color: var(--accent); text-shadow: 0 3px 0 #e9d5ff; }

.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 30px; }
.res-item { background: #f8fafc; padding: 20px; border: 3px solid #e2e8f0; border-radius: 20px; box-shadow: 0 6px 0 #e2e8f0; }
.res-v { font-size: 2.2rem; color: var(--green); text-shadow: 0 2px 0 #a7f3d0; line-height: 1; margin-bottom: 6px; }
.res-l { font-size: 1rem; font-weight: 800; color: var(--sub); text-transform: uppercase; }

.pills { display: flex; gap: 10px; justify-content: center; margin-bottom: 24px; flex-wrap: wrap; }
.pill { background: #f0fdf4; color: var(--green); padding: 10px 20px; border: 2px solid #bbf7d0; border-radius: 30px; font-size: 1.1rem; font-weight: 800; }

.tw { max-height: 300px; overflow-y: auto; margin-bottom: 24px; border: 3px solid #e2e8f0; border-radius: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 1rem; font-weight: 600; text-align: center; }
th, td { padding: 14px 16px; border-bottom: 2px solid #f1f5f9; }
th { background: #f8fafc; color: var(--sub); font-weight: 900; position: sticky; top: 0; text-transform: uppercase; z-index: 2; border-bottom: 3px solid #e2e8f0; }
tr:nth-child(even) td { background: #f8fafc; }
tr:hover td { background: #f0f9ff; }
td { color: var(--text); }

/* ======= Bubbles ======= */
.bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bubble { position: absolute; border-radius: 50%; opacity: 0.6; animation: up linear infinite; }
@keyframes up {
    0% { transform: translateY(100vh) scale(0.4) rotate(0deg); opacity: 0; }
    10% { opacity: 0.6; } 90% { opacity: 0.6; }
    100% { transform: translateY(-10vh) scale(1) rotate(360deg); opacity: 0; }
}
.screen, nav { position: relative; z-index: 1; }

/* ======= Responsive ======= */
@media (max-width: 600px) {
    .tabs { flex-wrap: nowrap; overflow-x: auto; }
    .tab { flex: none; min-width: 120px; }
    .stats { flex-direction: column; align-items: stretch; }
    .display { font-size: 1.5rem; padding: 20px; }
    .input-box { font-size: 1.2rem; }
    .login-wrap { margin: 40px 20px; padding: 30px 20px; }
    .login-wrap h1 { font-size: 2.2rem; }
}
