:root {
    --bg1: #f8fbff; --bg2: #eaf6ff; --line: #d8e7f3;
    --ink: #18314a; --muted: #64809a;
    --green: #58cc6a; --green-dark: #39a84d;
    --blue: #32b7ff; --blue-dark: #1294da;
    --coral: #ff8677; --coral-dark: #eb5d4d;
    --purple: #b989ff;
    --safe-top: max(14px, env(safe-area-inset-top));
    --safe-bottom: max(14px, env(safe-area-inset-bottom));
    --app-h: 100dvh;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; font-family: Inter, system-ui, sans-serif; }

/* FULL RESPONSIVE BASE */
body, html { 
    margin: 0; padding: 0; background: var(--bg1); color: var(--ink); 
    width: 100%; height: 100%; overflow: hidden; touch-action: none; overscroll-behavior: none; 
}

.app-container {
    width: 100%; height: var(--app-h); 
    display: flex; flex-direction: column; overflow: hidden;
}

/* HEADER */
.app-header {
    flex-shrink: 0; height: 60px; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; z-index: 40; padding-top: var(--safe-top); height: calc(60px + var(--safe-top));
}
.header-left { display: flex; align-items: center; gap: 12px; }
.btn-menu { background: transparent; border: none; font-size: 26px; color: var(--ink); cursor: pointer; padding: 4px; display: grid; place-items: center; transition: 0.2s; }
.btn-menu:active { opacity: 0.5; }
.logo { font-weight: 900; font-size: 22px; letter-spacing: -.03em; }
.logo span { color: var(--blue); }
.auth-btn { background: #f0f6ff; border: none; color: var(--blue-dark); font-weight: 800; font-size: 13px; padding: 8px 16px; border-radius: 20px; cursor: pointer; transition: 0.1s;}
.auth-btn:active { background: #dceafc; }

/* SCROLLABLE MAIN CONTENT (Centered for Desktop) */
.app-main {
    flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth;
    padding-bottom: 20px; background: var(--bg1); touch-action: pan-y;
}
.tab-view { display: none; padding: 20px; animation: fadeIn 0.3s ease; max-width: 800px; margin: 0 auto; width: 100%; }
.tab-view.active { display: block; }

/* HOME PAGE UI */
.hero-banner { background: linear-gradient(135deg, var(--blue), var(--purple)); border-radius: 24px; padding: 40px 20px; text-align: center; color: #fff; margin-bottom: 24px; box-shadow: 0 10px 20px rgba(50,183,255,0.2); }
.hero-banner h1 { margin: 0 0 10px; font-size: 32px; font-weight: 900; }
.hero-banner p { margin: 0 0 24px; font-size: 16px; opacity: 0.9; }
.btn-play-large { background: #fff; color: var(--blue-dark); border: none; padding: 16px 36px; border-radius: 30px; font-weight: 900; font-size: 18px; box-shadow: 0 6px 0 rgba(0,0,0,0.1); cursor: pointer; transition: 0.1s; }
.btn-play-large:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.1); }

/* ADSENSE MOCKUPS */
.ad-slot { background: #f0f3f6; border: 1px dashed #c0cdd8; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 800; font-size: 12px; flex-direction: column; text-align: center; overflow: hidden; }
.ad-slot.square { height: 250px; margin: 24px 0; }
.ad-slot.banner { height: 50px; margin: 10px 0; border-radius: 8px; flex-shrink: 0; background: rgba(255,255,255,0.6); }

/* SEO TEXT AREA */
.seo-content { background: #fff; padding: 30px; border-radius: 24px; border: 1px solid var(--line); line-height: 1.6; color: #4a637a; font-size: 15px; margin-bottom: 24px; }
.seo-content h2 { color: var(--ink); margin-top: 0; font-size: 22px; }
.seo-content h3 { color: var(--ink); font-size: 18px; margin-top: 20px; }

.mock-panel { background: #fff; padding: 40px 20px; border-radius: 24px; border: 1px solid var(--line); text-align: center; color: var(--muted); }

/* BOTTOM NAV (Optimized for both Mobile & Desktop) */
.bottom-nav {
    flex-shrink: 0; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom); z-index: 40; width: 100%;
}
.bottom-nav-inner {
    max-width: 600px; margin: 0 auto; width: 100%; height: 70px;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; justify-items: center;
}
.nav-item { background: transparent; border: none; color: var(--muted); font-size: 11px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; transition: 0.2s; }
.nav-item.active { color: var(--blue-dark); }
.nav-icon { font-size: 22px; }

.play-fab-wrap { position: relative; width: 100%; display: flex; justify-content: center; }
.play-fab {
    position: absolute; bottom: -5px; width: 56px; height: 56px; border-radius: 50%;
    background: var(--green); color: #fff; border: 4px solid #fff; display: grid; place-items: center;
    font-size: 24px; font-weight: 900; box-shadow: 0 4px 14px rgba(88,204,106,.3); cursor: pointer;
    padding-left: 4px; transition: transform 0.1s;
}
.play-fab:active { transform: scale(0.9); }

/* ========================================= */
/* SIDEBAR (DRAWER) MENU */
/* ========================================= */
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; background: #fff;
    z-index: 1001; transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
    display: flex; flex-direction: column; box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
    padding: 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; 
    align-items: center; padding-top: calc(20px + var(--safe-top));
}
.btn-close-sidebar { background: #f0f6ff; border: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--blue-dark); font-weight: 900; cursor: pointer; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 0; }
.sidebar-link {
    display: flex; align-items: center; gap: 16px; padding: 14px 24px; color: var(--ink);
    text-decoration: none; font-weight: 700; font-size: 16px; transition: background 0.2s;
    cursor: pointer; border-left: 4px solid transparent;
}
.sidebar-link:hover, .sidebar-link:active { background: var(--bg2); color: var(--blue-dark); border-left-color: var(--blue); }
.sidebar-link .icon { font-size: 20px; }

/* ========================================= */
/* GAME OVERLAY (RESPONSIVE) */
/* ========================================= */
.game-overlay {
    position: absolute; inset: 0; z-index: 100; display: none;
    background: linear-gradient(180deg, #eefaff 0%, #c9edff 100%);
    padding-top: var(--safe-top); 
    transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
}
.game-overlay.open { display: flex; transform: translateY(0); }

.game-wrapper {
    max-width: 600px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; height: 100%;
}

.game-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px 8px; background: rgba(255,255,255,0.8); backdrop-filter: blur(10px); z-index: 10; border-radius: 0 0 20px 20px;}
.player-card { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 900; font-size: 14px; }
.avatar { width: 44px; height: 44px; border-radius: 14px; background: #fff; display: grid; place-items: center; font-size: 22px; box-shadow: 0 4px 12px rgba(29,75,115,.1); transition: 0.3s; border: 2px solid transparent;}
.avatar.active { border-color: var(--green); transform: scale(1.1); box-shadow: 0 8px 16px rgba(88,204,106,.2); }
.hp-bar { width: 60px; height: 8px; background: #dfeaf3; border-radius: 4px; overflow: hidden; }
.hp-fill { height: 100%; background: var(--green); width: 100%; transition: width 0.3s, background-color 0.3s; }
.btn-close-game { background: transparent; border: none; font-size: 24px; color: var(--muted); padding: 5px; cursor: pointer; }

.timer-wrap { height: 4px; background: rgba(255,255,255,0.8); width: 100%; border-bottom: 1px solid var(--line); z-index: 10; position: relative; }
.timer-fill { height: 100%; width: 100%; background: var(--green); transition: width 1s linear, background-color 0.3s; }

.arena { flex: 1; overflow-y: auto; padding: 10px 16px 30px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; touch-action: pan-y; }
.bubble-wrap { display: flex; flex-direction: column; max-width: 80%; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
.bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.bot { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 14px 20px; border-radius: 20px; font-size: 16px; font-weight: 900; letter-spacing: 0.02em; box-shadow: 0 4px 12px rgba(29,75,115,.06); word-break: break-all; }
.bubble.user { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { background: #fff; color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.letter-hint { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 700; padding: 0 4px; }
.typing-indicator { display: flex; gap: 4px; padding: 16px 20px; background: #fff; border-radius: 20px; border-bottom-left-radius: 4px; width: fit-content; border: 1px solid var(--line); align-self: flex-start; display: none; }
.typing-indicator.active { display: flex; }
.dot { width: 8px; height: 8px; background: var(--muted); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

.control-panel { background: rgba(240, 246, 252, 0.95); backdrop-filter: blur(12px); border-top: 1px solid var(--line); display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); box-shadow: 0 -4px 20px rgba(29,75,115,.05); z-index: 50; }
.input-display-area { padding: 12px 16px 8px; display: flex; justify-content: center; }
.real-input { width: 100%; max-width: 360px; height: 48px; background: #fff; border: 1px solid #d0deec; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 900; color: var(--ink); letter-spacing: 2px; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02); text-align: center; text-transform: uppercase; outline: none; caret-color: var(--blue); }
.real-input:focus { border-color: var(--blue); }
.real-input::placeholder { color: #a4b9cc; font-size: 15px; font-weight: 700; letter-spacing: normal; text-transform: none; }
.real-input:disabled { background: #f0f7ff; opacity: 0.8; }

.virtual-keyboard { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.kb-row { display: flex; justify-content: center; gap: 6px; }
.kb-key { flex: 1; height: 50px; min-width: 0; padding: 0; border: none; border-radius: 8px; background: #fff; color: var(--ink); font-weight: 800; font-size: 18px; box-shadow: 0 4px 0 rgba(29,75,115,.12); cursor: pointer; transition: 0.05s; user-select: none; touch-action: manipulation; }
.kb-key:active { transform: translateY(4px); box-shadow: 0 0 0 rgba(29,75,115,.12); background: #eaf6ff; }
.kb-key.wide { flex: 1.5; font-size: 16px; background: #e2eef7; }
.kb-key.enter { flex: 2; background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-dark); font-size: 16px; }
.kb-key.enter:active { box-shadow: 0 0 0 var(--green-dark); }
.kb-key:disabled { opacity: 0.5; pointer-events: none; }

/* ========================================= */
/* RESULT MODAL */
/* ========================================= */
.result-modal {
    position: absolute; inset: 0; background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(8px);
    z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px;
}
.result-modal.open { display: flex; animation: fadeIn 0.3s; }
.result-card {
    background: #fff; width: 100%; max-width: 380px; border-radius: 24px; padding: 24px;
    text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.result-title { font-size: 32px; font-weight: 900; margin: 0 0 10px; color: var(--ink); }
.result-title.win { color: var(--green); }
.result-title.lose { color: var(--coral); }
.result-desc { font-size: 16px; font-weight: 600; color: var(--muted); margin: 0 0 20px; }

.modal-btn { width: 100%; padding: 14px; border-radius: 16px; font-weight: 800; font-size: 16px; border: none; cursor: pointer; margin-bottom: 10px; transition: 0.1s; }
.modal-btn:active { transform: scale(0.97); }
.modal-btn.primary { background: var(--blue); color: #fff; }
.modal-btn.secondary { background: #eefaff; color: var(--blue-dark); border: 2px solid var(--line); }
.modal-btn.tertiary { background: transparent; color: var(--muted); margin-bottom: 0; }

@keyframes popIn { 0% { opacity: 0; transform: scale(0.8) translateY(10px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
