body {
    font-family: 'Inter', system-ui, sans-serif;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    background-color: #0f172a;
    transition: background-color 0.3s ease;
}

body.light-theme {
    background-color: #f3f4f6;
}

body.light-theme .glass-panel {
    background: white;
}

.grid-cell {
    width: 100%;
    padding-bottom: 100%;
    transition: background-color 0.05s ease;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.grid-cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 2px, transparent 2px, transparent 4px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 1;
}

.pattern-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 2;
    opacity: 0.3;
}

.pattern-overlay.white-pattern {
    background-color: rgba(255, 255, 255, 0.3);
}

.pattern-overlay.black-pattern {
    background-color: rgba(0, 0, 0, 0.3);
}

body:not(.game-active) .grid-cell::before {
    opacity: 0.5;
}

.grid-cell.bg-black::before {
    background-image: repeating-linear-gradient(45deg, rgba(255,215,0,0.1) 0px, rgba(255,215,0,0.1) 2px, transparent 2px, transparent 4px);
}

.grid-cell.bg-white::before {
    background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.1) 0px, rgba(0,0,0,0.1) 2px, transparent 2px, transparent 4px);
}

.highlight-current {
    box-shadow: 0 0 0 3px #0e7ec9;
    transform: scale(1.05);
    z-index: 10;
}

#game-grid {
    display: grid;
    width: 100%;
    margin: 0 auto;
    position: relative;
}

/* Ultra mode row numbers */
.row-number {
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    font-weight: bold;
    color: #60a5fa;
    background: rgba(30, 41, 59, 0.8);
    padding: 2px 4px;
    border-radius: 4px;
    z-index: 20;
}

body.light-theme .row-number {
    background: rgba(255, 255, 255, 0.8);
    color: #2563eb;
}

.grid-container {
    position: relative;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(8px);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: #1e293b;
    padding: 2rem;
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 90%;
    width: 450px;
}

.modal-overlay.open .modal-content {
    transform: scale(1);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.rank-pop {
    animation: popIn 0.6s ease-out forwards;
}

/* UI Components */
.glass-panel {
    background: rgb(211,211,222);
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(229, 231, 235, 0.5);
}

.random-pattern-die {
    display: inline-block;
    cursor: pointer;
    filter: invert(65%) sepia(15%) saturate(207%) hue-rotate(179deg) brightness(96%) contrast(91%);
}

.tab-btn {
    padding: 0.5rem 0.5rem;
    font-size: 0.70rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    border-bottom-width: 2px;
    border-color: transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: #374151;
}

.tab-btn.active {
    color: #2563eb;
    border-color: #2563eb;
}

.stat-card {
    background: #f9fafb;
    border-radius: 0.75rem;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.stat-label {
    font-size: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #9ca3af;
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
    text-align: center;
    line-height: 1.1;
}

.stat-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 700;
    color: #1f2937;
    font-size: 0.85rem;
}

.custom-scroll::-webkit-scrollbar {
    width: 5px;
}

.custom-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scroll::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

#xp-bar-fill {
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

#mobile-controls {
    display: none;
}

.mobile-btn {
    touch-action: manipulation;
}

/* small medal badge used in skill leaderboard rows */
.skill-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    color: white;
    font-weight: 700;
    font-size: 11px;
    min-width: 72px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.no-badge {
    background: transparent;
    box-shadow: none;
    color: inherit;
    padding: 0;
    min-width: 0;
}

/* Pending warning */
.pending-warning {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #f59e0b;
    color: #92400e;
    animation: pulse 2s infinite;
}

.remap-warning {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border: 2px solid #ef4444;
    color: #7f1d1d;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.9;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.9;
    }
}

/* KPS display */
.kps-display {
    font-size: 10px;
    font-weight: bold;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

/* Collapsible sections */
.collapse-header {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.collapse-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.collapse-icon {
    transition: transform 0.3s ease;
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

/* Header & Navigation */
.main-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    margin-bottom: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

body.light-theme .main-header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: white;
    letter-spacing: -0.02em;
}

body.light-theme .logo {
    color: #1f2937;
}

.logo span {
    color: #9ca3af;
}

.nav-menu {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-link {
    color: #d1d5db;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.2s;
    cursor: pointer;
}

body.light-theme .nav-link {
    color: #4b5563;
}

.nav-link:hover {
    color: #2e63d6;
}

.nav-link.active {
    color: #1067b9;
    border-bottom: 2px solid #3d10b9;
}

.hamburger-btn {
    display: none;
    flex-direction: column;
    gap: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger-btn span {
    width: 25px;
    height: 2px;
    background: white;
    transition: all 0.3s;
}

body.light-theme .hamburger-btn span {
    background: #1f2937;
}

.hamburger-btn.open span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger-btn.open span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.open span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

.mobile-menu {
    display: none;
    position: fixed;
    top: 61px;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1e293b;
    z-index: 99;
    padding: 2rem;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

body.light-theme .mobile-menu {
    background: white;
}

.mobile-menu.open {
    display: flex;
}

.mobile-nav-link {
    color: #d1d5db;
    font-weight: 700;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1rem;
    border-bottom: 1px solid #334155;
    cursor: pointer;
}

body.light-theme .mobile-nav-link {
    color: #1f2937;
    border-bottom: 1px solid #e5e7eb;
}

.mobile-nav-link:hover {
    color: #0f50c9;
}

.theme-toggle {
    background: #334155;
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

body.light-theme .theme-toggle {
    background: #e5e7eb;
    color: #1f2937;
}

@media (max-width: 1024px) {
    .nav-menu {
        display: none;
    }
    .hamburger-btn {
        display: flex;
    }
    .main-header {
        padding: 0;
    }
}

/* Page content containers (for other pages) */
.page-content {
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
    display: none;
}

body.light-theme .page-content {
    background: white;
    color: #1f2937;
}

.page-content.active {
    display: block;
}

.page-content h1 {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 1.5rem;
    color: #0e67db;
    text-transform: uppercase;
}

.page-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 1.5rem 0 1rem;
    color: #1f2937;
}

.page-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
    color: #4b5563;
}

.page-content ul, .page-content ol {
    margin: 1rem 0 1rem 2rem;
    color: #4b5563;
}

.page-content li {
    margin-bottom: 0.5rem;
}

.rule-section {
    background: #f9fafb;
    padding: 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid #0e7ec9;
}

.faq-item {
    border-bottom: 1px solid #e5e7eb;
    padding: 1rem 0;
}

.faq-question {
    font-weight: 700;
    color: #1683e9;
    margin-bottom: 0.5rem;
}

/* Custom Mode Styles */
.custom-mode-panel {
    background: rgba(255,255,255,0.05);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.75rem;
}

.pattern-preset-btn {
    background: #334155;
    color: white;
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    cursor: pointer;
    width: 100%;
    margin-bottom: 0.25rem;
}

.pattern-preset-btn:hover {
    background: #475569;
}

.custom-input {
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 0.25rem;
    padding: 0.5rem;
    color: white;
    font-size: 0.8rem;
    width: 100%;
}

.ultra-timer {
    font-size: 0.8rem;
    color: #60a5fa;
    font-family: monospace;
    margin-top: 0.25rem;
}

.opacity-slider {
    width: 100%;
    margin: 0.5rem 0;
}

.custom-mode-btn {
    width: 100%;
    padding: 0.75rem;
    background: #4f46e5;
    color: white;
    font-weight: bold;
    border-radius: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.custom-mode-btn:hover {
    background: #4338ca;
}

.custom-mode-btn.active {
    background: #7c3aed;
}

.mode-btn {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
    font-weight: bold;
}

.survival-stats {
    background: #1e293b;
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-top: 0.5rem;
    border: 1px solid #4f46e5;
}

.survival-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.survival-stat-label {
    color: #9ca3af;
    font-weight: 600;
}

.survival-stat-value {
    color: #4f46e5;
    font-weight: 700;
    font-family: monospace;
}

/* Saved Patterns */
.saved-pattern-item {
    background: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.saved-pattern-item:hover {
    background: #4a5568;
}

.saved-pattern-name {
    font-weight: bold;
    color: white;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.saved-pattern-preview {
    font-family: monospace;
    font-size: 0.7rem;
    color: #a0aec0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-pattern-attempts {
    font-size: 0.7rem;
    color: #48bb78;
    font-weight: bold;
}

.delete-pattern-btn {
    color: #fc8181;
    font-size: 0.8rem;
    margin-left: 0.5rem;
    cursor: pointer;
}

.delete-pattern-btn:hover {
    color: #f56565;
}

/* Customization Tab */
.customization-panel {
    background: #1e293b;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 1rem;
    border: 2px solid #4f46e5;
}

.color-picker {
    width: 100%;
    height: 40px;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 30px;
    cursor: pointer;
    color: #9ca3af;
}

.close-btn:hover {
    color: white;
}

#xp-factor, #rank-points {
    display: none !important;
}

.grid-cols-2.gap-2.text-center.mb-3 {
    display: none !important;
}