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

:root {
    --bg-primary: #f8f9fc;
    --bg-surface: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-sidebar: rgba(255, 255, 255, 0.9);
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --green: #4caf50;
    --yellow: #d4a017;
    --gray: #e0e0e0;
    --red: #d32f2f;
    --border: rgba(0, 0, 0, 0.06);
    --tile-border: rgba(0, 0, 0, 0.12);
    --tile-bg: rgba(255, 255, 255, 0.9);
    --tile-filled: rgba(0, 0, 0, 0.08);
    --glass: rgba(0, 0, 0, 0.02);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glow-green: rgba(76, 175, 80, 0.25);
    --glow-yellow: rgba(212, 160, 23, 0.25);
    --glow-red: rgba(211, 47, 47, 0.15);
    --key-bg: rgba(0, 0, 0, 0.04);
    --key-hover: rgba(0, 0, 0, 0.08);
    --key-border: rgba(0, 0, 0, 0.06);
    --btn-glass-bg: rgba(0, 0, 0, 0.04);
    --btn-glass-hover: rgba(0, 0, 0, 0.08);
    --btn-glass-border: rgba(0, 0, 0, 0.08);
    --modal-bg: rgba(255, 255, 255, 0.98);
    --hist-item-bg: rgba(0, 0, 0, 0.02);
    --hist-correct-bg: rgba(76, 175, 80, 0.08);
    --hist-wrong-bg: rgba(211, 47, 47, 0.05);
    --dist-bar-bg: rgba(0, 0, 0, 0.05);
    --timer-color: #6366f1;
    --title-gradient: linear-gradient(135deg, #6366f1, #a855f7, #6366f1);
    --score-gradient: linear-gradient(135deg, #f59e0b, #f97316);
    --orb-opacity: 0.08;
    --gradient-bg: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99, 102, 241, 0.06), transparent),
                   radial-gradient(ellipse 60% 50% at 90% 80%, rgba(168, 85, 247, 0.04), transparent),
                   radial-gradient(ellipse 50% 40% at 20% 70%, rgba(59, 130, 246, 0.03), transparent);
    --radius: 14px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    position: relative;
}

.bg-gradient {
    position: fixed;
    inset: 0;
    background: var(--gradient-bg);
    pointer-events: none;
    z-index: 0;
}

.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.3;
}

.orb-1, .orb-2, .orb-3 {
    opacity: var(--orb-opacity);
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.3), transparent);
    top: -15%;
    left: -10%;
    animation: float1 20s ease-in-out infinite;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.25), transparent);
    bottom: -10%;
    right: -8%;
    animation: float2 25s ease-in-out infinite;
}

.orb-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(34, 211, 238, 0.15), transparent);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float3 18s ease-in-out infinite;
}

@keyframes float1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(40px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

@keyframes float2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(-30px, 40px) scale(1.03); }
    66% { transform: translate(20px, -25px) scale(0.97); }
}

@keyframes float3 {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-45%, -55%) scale(1.08); }
}

/* Layout */
.layout {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    width: 100%;
    max-width: 1200px;
    min-height: 100vh;
    padding: 0 8px;
}

.container {
    z-index: 1;
    width: 100%;
    max-width: 480px;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    flex-shrink: 0;
}

/* Header */
header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 16px;
}

.title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 2px;
    background: var(--title-gradient);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s ease-in-out infinite;
    user-select: none;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    position: relative;
}

.icon-btn:hover {
    background: var(--key-hover);
    border-color: var(--tile-filled);
    transform: translateY(-1px);
}

#sidebarToggle { display: none; }

/* Board */
.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 330px;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid var(--tile-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-primary);
    background: var(--tile-bg);
    backdrop-filter: blur(12px);
    transition: all 0.15s ease;
    user-select: none;
}

.tile.filled {
    border-color: var(--tile-filled);
}

.tile.active-row {
    border-color: rgba(255, 255, 255, 0.2);
}

.tile.correct {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
    animation: flipIn 0.5s ease forwards;
    box-shadow: 0 0 20px var(--glow-green);
}

.tile.present {
    background: var(--yellow);
    border-color: var(--yellow);
    color: #fff;
    animation: flipIn 0.5s ease forwards;
    box-shadow: 0 0 20px var(--glow-yellow);
}

.tile.absent {
    background: var(--gray);
    border-color: var(--gray);
    color: #fff;
    animation: flipIn 0.5s ease forwards;
}

.tile.shake { animation: shake 0.5s ease; }
.tile.pop { animation: pop 0.1s ease; }

.tile.win-bounce {
    animation: winPop 0.6s ease;
}

@keyframes flipIn {
    0% { transform: rotateX(0deg); }
    40% { transform: rotateX(90deg); }
    100% { transform: rotateX(0deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

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

@keyframes winPop {
    0% { transform: scale(1); }
    25% { transform: scale(1.2) rotate(-3deg); }
    50% { transform: scale(0.95) rotate(3deg); }
    75% { transform: scale(1.08) rotate(-1deg); }
    100% { transform: scale(1) rotate(0); }
}

/* Message */
.message {
    height: 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.message.error { color: #ef4444; }

/* Keyboard */
.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 480px;
    margin-top: auto;
    padding-bottom: 8px;
}

.keyboard-row {
    display: flex;
    gap: 5px;
    width: 100%;
    justify-content: center;
}

.key {
    height: 52px;
    min-width: 32px;
    padding: 0 6px;
    border: none;
    border-radius: 5px;
    background: var(--key-bg);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    backdrop-filter: blur(8px);
    border: 1px solid var(--key-border);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    flex: 1;
    max-width: 42px;
}

.key:hover {
    background: var(--key-hover);
    transform: translateY(-1px);
}

.key:active {
    transform: scale(0.94);
    transition: transform 0.05s ease;
}

.key.wide { flex: 1.5; max-width: 60px; font-size: 12px; }

.key.correct { background: var(--green); color: #fff; border-color: var(--green); }
.key.present { background: var(--yellow); color: #fff; border-color: var(--yellow); }
.key.absent { background: rgba(0, 0, 0, 0.03); color: rgba(0, 0, 0, 0.18); border-color: transparent; }

/* === SIDEBAR === */
.sidebar {
    min-height: 100vh;
    background: var(--bg-sidebar);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.sidebar-left {
    width: 240px;
    border-right: 1px solid var(--glass-border);
}

.sidebar-right {
    width: 280px;
    border-left: 1px solid var(--glass-border);
}

.sidebar-section {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 16px;
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.guess-counter {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

/* Game History */
.guess-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 420px;
    overflow-y: auto;
    min-height: 40px;
}

.guess-list::-webkit-scrollbar { width: 4px; }
.guess-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.guess-empty {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: 8px 0;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--hist-item-bg);
    border: 1px solid var(--glass-border);
}

.history-item.is-correct {
    border-color: var(--green);
    background: var(--hist-correct-bg);
}
.history-item.is-wrong {
    border-color: var(--red);
    background: var(--hist-wrong-bg);
}

.history-item.is-correct {
    border-color: var(--green);
    background: rgba(83, 141, 78, 0.08);
    box-shadow: 0 0 10px rgba(83, 141, 78, 0.1);
}

.history-item.is-wrong {
    border-color: var(--red);
    background: rgba(192, 57, 43, 0.06);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.history-word {
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-primary);
}

.is-correct .history-word { color: #6ece6e; }
.is-wrong .history-word { color: #e57373; }

.history-status {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.is-correct .history-status { color: var(--green); background: rgba(83, 141, 78, 0.15); }
.is-wrong .history-status { color: var(--red); background: rgba(192, 57, 43, 0.12); }

.history-tiles {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 6px;
}

.guess-row-tiles {
    display: flex;
    gap: 2px;
}

.mini-tile {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #fff;
    background: var(--gray);
}

.mini-tile.correct { background: var(--green); box-shadow: 0 0 6px var(--glow-green); }
.mini-tile.present { background: var(--yellow); box-shadow: 0 0 6px var(--glow-yellow); }
.mini-tile.absent { background: rgba(0, 0, 0, 0.04); color: rgba(0, 0, 0, 0.25); }

.history-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* Live Stats */
.sidebar-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.live-stat {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.live-stat svg {
    color: var(--text-secondary);
    flex-shrink: 0;
}

#timer {
    font-variant-numeric: tabular-nums;
    font-size: 18px;
    font-weight: 700;
    color: var(--timer-color);
}

#score {
    font-size: 18px;
    font-weight: 700;
    background: var(--score-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal {
    background: var(--modal-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 420px;
    width: 100%;
    backdrop-filter: blur(20px);
    animation: slideUp 0.3s ease;
}

.modal h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

.modal h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    margin: 20px 0 12px;
}

.modal p {
    color: var(--text-secondary);
    line-height: 1.6;
    text-align: center;
    margin-bottom: 12px;
}

.modal ul {
    color: var(--text-secondary);
    padding-left: 20px;
    margin-bottom: 16px;
    line-height: 1.8;
}

.examples {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.example-row {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

.example-row .tile {
    width: 36px;
    height: 36px;
    font-size: 18px;
    border-radius: 5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-value { font-size: 28px; font-weight: 800; }
.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.distribution {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}

.dist-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.dist-bar-bg {
    flex: 1;
    height: 20px;
    background: var(--dist-bar-bg);
    border-radius: 4px;
    overflow: hidden;
}

.dist-bar {
    height: 100%;
    background: var(--green);
    border-radius: 4px;
    transition: width 0.5s ease;
    min-width: 8px;
    padding-right: 6px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn {
    padding: 10px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn:active { transform: scale(0.97); }

.btn-secondary {
    background: var(--btn-glass-bg);
    border: 1px solid var(--btn-glass-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--btn-glass-hover);
    box-shadow: none;
}

.btn-danger {
    border-color: rgba(192, 57, 43, 0.3);
    color: #e74c3c;
}

.btn-danger:hover {
    background: rgba(192, 57, 43, 0.15);
    border-color: rgba(192, 57, 43, 0.5);
    box-shadow: none;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* Inline Stats */
.stats-grid-inline {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.stats-grid-inline .stat-value { font-size: 22px; }
.stats-grid-inline .stat-label { font-size: 10px; }

.dist-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.distribution-inline {
    margin-bottom: 12px;
}

.distribution-inline .dist-row {
    font-size: 11px;
    gap: 6px;
}

.distribution-inline .dist-bar-bg {
    height: 16px;
}

.sidebar-actions {
    display: flex;
    gap: 8px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Confetti */
#confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 150;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar-left { display: none; }
    .sidebar-right {
        position: fixed;
        right: -300px;
        top: 0;
        bottom: 0;
        z-index: 50;
        transition: right 0.3s ease;
        width: 280px;
    }
    .sidebar-right.open { right: 0; }
    #sidebarToggle { display: flex; }
    .layout { padding: 0 4px; }
}

@media (max-width: 500px) {
    .container { padding: 8px 6px; }
    .title { font-size: 22px; }
    .board { max-width: 100%; gap: 4px; }
    .row { gap: 4px; }
    .tile { font-size: 20px; border-width: 1.5px; }
    .keyboard { gap: 4px; }
    .keyboard-row { gap: 3px; }
    .key { height: 44px; font-size: 11px; max-width: 30px; border-radius: 4px; }
    .key.wide { max-width: 44px; font-size: 11px; }
    .sidebar-right { width: 260px; }
}

    .sidebar-right {
        position: fixed;
        right: -300px;
        top: 0;
        bottom: 0;
        z-index: 50;
        transition: right 0.3s ease;
        width: 280px;
    }
    .sidebar-right.open { right: 0; }

    #sidebarToggle { display: flex; }

    .layout { padding: 0 4px; }
}

@media (max-width: 400px) {
    .container { padding: 12px 8px; }
    .title { font-size: 24px; }
    .tile { font-size: 22px; }
    .board { max-width: 300px; gap: 4px; }
    .row { gap: 4px; }
    .key { height: 46px; font-size: 12px; max-width: 28px; }
    .key.wide { max-width: 48px; }
}
