:root {
    --bg-color: #0a0e1a;
    --bg-secondary: #12182b;
    --surface-color: #1a2138;
    --surface-elevated: #222d45;
    --primary-color: #4f9fff;
    --primary-hover: #6bb0ff;
    --secondary-color: #14b8a6;
    --secondary-hover: #2dd4bf;
    --success-color: #10b981;
    --success-hover: #34d399;
    --danger-color: #f43f5e;
    --text-color: #e8edf4;
    --text-muted: #8b95a8;
    --text-dim: #5f6b7f;
    --grid-line: #2d3a54;
    --block-color: #1e2639;
    --white-cell: #2a3550;
    --white-cell-text: #e8edf4;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --border-color: rgba(79, 159, 255, 0.15);
    --accent-glow: rgba(79, 159, 255, 0.2);
}

/* Light Theme */
[data-theme="light"] {
    --bg-color: #fafbfc;
    --bg-secondary: #f3f4f6;
    --surface-color: #ffffff;
    --surface-elevated: #fafbfc;
    --primary-color: #0369a1;
    --primary-hover: #0284c7;
    --secondary-color: #0d9488;
    --secondary-hover: #14b8a6;
    --success-color: #059669;
    --success-hover: #10b981;
    --danger-color: #e11d48;
    --text-color: #0f172a;
    --text-muted: #475569;
    --text-dim: #64748b;
    --grid-line: #d1d5db;
    --block-color: #e5e7eb;
    --white-cell: #ffffff;
    --white-cell-text: #0f172a;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.1);
    --border-color: rgba(3, 105, 161, 0.12);
    --accent-glow: rgba(3, 105, 161, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Space Mono', 'Courier New', monospace;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

#root {
    width: 100%;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===============================================
   DESKTOP HEADER - Refined & Streamlined
   =============================================== */
.header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 2.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-header {
    display: none;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1800px;
    margin: 0 auto;
    gap: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
}

.brand-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header h1 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.02em;
    font-family: 'JetBrains Mono', 'Space Mono', monospace;
}

.subtitle {
    display: none;
}

/* Theme Toggle - Minimal Icon Button */
.btn-theme-toggle {
    padding: 0.625rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
}

.btn-theme-toggle:hover {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
}

.btn-theme-toggle .tool-icon {
    font-size: 1.1rem;
}

.btn-theme-toggle.btn-icon-only {
    padding: 0.625rem;
    width: auto;
    height: auto;
}

.btn-theme-toggle.btn-icon-only .tool-label {
    display: none;
}

/* Header Right - Auth */
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.auth-buttons {
    display: flex;
    gap: 0.75rem;
}

.btn-auth {
    padding: 0.625rem 1.25rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
}

.btn-auth:hover {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
}

.btn-auth-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-auth-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-admin-nav {
    background: rgba(20, 184, 166, 0.1) !important;
    border-color: rgba(20, 184, 166, 0.3) !important;
    color: var(--secondary-color) !important;
    text-decoration: none;
}

.btn-admin-nav:hover {
    background: rgba(20, 184, 166, 0.2) !important;
    border-color: var(--secondary-color) !important;
}

/* User Menu */
.user-menu {
    position: relative;
}

.btn-user {
    padding: 0.625rem 1rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn-user:hover {
    border-color: var(--primary-color);
}

.user-avatar {
    font-size: 1.1rem;
}

.user-name {
    font-family: inherit;
}

.dropdown-arrow {
    font-size: 0.7rem;
    opacity: 0.6;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 220px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.user-menu.open .user-dropdown {
    display: block;
    animation: fadeInScale 0.2s ease;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.user-stats {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.user-email {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.user-solved {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.dropdown-item {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    font-family: inherit;
}

.dropdown-item:hover {
    background: var(--surface-elevated);
}

/* ===============================================
   MAIN LAYOUT - Fluid 3-Column Desktop Grid
   =============================================== */
.main-layout {
    display: grid;
    grid-template-columns: minmax(240px, 280px) 1fr minmax(240px, 280px);
    gap: 0;
    flex: 1;
    width: 100%;
    padding: 0;
    animation: fadeIn 0.6s ease;
    position: relative;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ===============================================
   SIDEBARS - Borderless, Seamless Design with Collapse
   =============================================== */
.sidebar-left,
.sidebar-right {
    background: var(--surface-color);
    padding: 1.5rem;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - 80px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

/* Collapsed state */
.sidebar-left.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    border-right: none;
    overflow: hidden;
}

.sidebar-right.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    border-left: none;
    overflow: hidden;
}

/* Toggle buttons for sidebars */
.sidebar-toggle {
    position: absolute;
    top: 1rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    color: var(--text-muted);
    font-weight: 700;
}

.sidebar-toggle:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.sidebar-left .sidebar-toggle {
    right: -16px;
}

.sidebar-right .sidebar-toggle {
    left: -16px;
}

.sidebar-left.collapsed .sidebar-toggle {
    position: fixed;
    top: 100px;
    left: 0;
    border-radius: 0 50% 50% 0;
    right: auto;
}

.sidebar-right.collapsed .sidebar-toggle {
    position: fixed;
    top: 100px;
    right: 0;
    left: auto;
    border-radius: 50% 0 0 50%;
}

/* Adjust main layout when sidebars collapse */
.main-layout.left-collapsed {
    grid-template-columns: 0 1fr minmax(240px, 280px);
}

.main-layout.right-collapsed {
    grid-template-columns: minmax(240px, 280px) 1fr 0;
}

.main-layout.both-collapsed {
    grid-template-columns: 0 1fr 0;
}

/* Control Cards - Clean, No Borders */
.control-card {
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border: none;
    transition: none;
}

.control-card:hover {
    box-shadow: none;
    border-color: transparent;
}

.card-title {
    margin: 0 0 1rem 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Control Groups */
.control-group {
    margin-bottom: 1rem;
}

.control-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.styled-select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%234f9fff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 3rem;
    font-family: inherit;
}

.styled-select:hover {
    border-color: var(--primary-color);
    background-color: var(--surface-elevated);
}

.styled-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Buttons */
.btn-large {
    width: 100%;
    padding: 0.875rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.btn-large::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
}

.btn-large:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 159, 255, 0.25);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 159, 255, 0.35);
}

.btn-icon {
    font-size: 1.3rem;
    z-index: 1;
}

.btn-large span {
    z-index: 1;
}

/* Tool Buttons - Minimalist Design */
.tools-panel {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.btn-tool {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
}

.btn-tool:hover {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
    transform: translateX(2px);
}

.btn-tool.active {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
    box-shadow: 0 0 12px var(--accent-glow);
}

.tool-icon {
    font-size: 1.2rem;
}

.tool-label {
    font-size: 0.875rem;
    font-weight: 600;
}

.tool-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-color);
    border-radius: 4px;
    font-weight: 700;
    color: var(--text-muted);
}

.btn-tool.active .tool-status {
    background: var(--primary-color);
    color: white;
}

/* Notebook Panel */
.notebook-panel-inline {
    max-height: 0;
    overflow: hidden;
    background: var(--surface-color);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        margin 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s ease;
    opacity: 0;
    display: flex;
    flex-direction: column;
}

.notebook-panel-inline.open {
    max-height: 600px;
    padding: 1.5rem;
    margin-top: 1.25rem;
    opacity: 1;
}

.notebook-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 1rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.notebook-header h3 {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.notebook-textarea {
    flex: 1;
    min-height: 300px;
    width: 100%;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: 'Georgia', serif;
    font-size: 0.95rem;
    line-height: 1.8;
    resize: none;
    outline: none;
}

.notebook-textarea::placeholder {
    color: var(--text-dim);
    font-style: italic;
}

.notebook-textarea::-webkit-scrollbar {
    width: 8px;
}

.notebook-textarea::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.notebook-textarea::-webkit-scrollbar-thumb {
    background: rgba(79, 159, 255, 0.3);
    border-radius: 4px;
}

.notebook-textarea::-webkit-scrollbar-thumb:hover {
    background: rgba(79, 159, 255, 0.5);
}

/* ===============================================
   GAME AREA - Centered & Spacious
   =============================================== */
.game-area {
    background: var(--bg-secondary);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    overflow-y: auto;
    max-height: calc(100vh - 80px);
}

.board-container {
    background: transparent;
    border-radius: 0;
    padding: 1rem;
    box-shadow: none;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.kakuro-grid {
    display: inline-block;
}

/* Note Help */
.note-help {
    padding: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 600px;
    text-align: center;
}

/* Action Bar */
.action-bar {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-action {
    padding: 0.875rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-family: inherit;
}

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

.btn-secondary:hover {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-color);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

/* ===============================================
   KAKURO GRID CELLS
   =============================================== */
.kakuro-grid {
    display: grid;
    gap: 0;
    background-color: var(--grid-line);
    border: 1px solid var(--grid-line);
}

.kakuro-grid.mode-notes {
    cursor: crosshair;
}

.kakuro-grid.mode-notes .cell.white.selected,
.kakuro-grid.mode-notes .cell.white.multi-selected {
    background-color: rgba(79, 159, 255, 0.12);
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.cell {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-size: 1.5rem;
    font-weight: 700;
    transition: background-color 0.2s, transform 0.1s;
    border: 1px solid var(--grid-line);
}

.cell.block {
    background: var(--block-color);
    color: var(--text-dim);
    font-size: 0.8rem;
}

.cell.white {
    background-color: var(--white-cell);
    color: var(--white-cell-text);
    cursor: pointer;
    transition: background-color 0.2s;
}

.cell.white:hover {
    background-color: rgba(79, 159, 255, 0.05);
}

.cell.white:active {
    transform: scale(0.98);
}

.cell.white.selected {
    background-color: rgba(79, 159, 255, 0.12);
    box-shadow: inset 0 0 0 2px var(--primary-color);
    z-index: 5;
}

.cell.white.multi-selected {
    background-color: rgba(20, 184, 166, 0.12);
    box-shadow: inset 0 0 0 2px var(--secondary-color);
    z-index: 5;
}

.cell.white.incorrect {
    color: var(--danger-color);
    background-color: rgba(244, 63, 94, 0.08);
}

.cell.white.correct {
    color: var(--success-color);
    background-color: rgba(16, 185, 129, 0.08);
}

/* Cell Content Wrapper */
.cell-content-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-value {
    font-size: 1.5rem;
    font-weight: 700;
    z-index: 1;
}

.cell-value.incorrect {
    color: var(--danger-color);
}

.cell-value.correct {
    color: var(--success-color);
}

/* Cell Notes - Corner Note */
.cell-corner-note {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.55rem;
    color: var(--text-color);
    background: rgba(79, 159, 255, 0.15);
    padding: 2px 4px;
    border-radius: 3px;
    max-width: 35px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 2;
    font-weight: 600;
}

/* Boundary notes as overlays between cells */
.boundary-note-overlay {
    position: absolute;
    font-size: 0.65rem;
    color: #ffffff;
    background: var(--secondary-color);
    padding: 4px 8px;
    border-radius: 6px;
    z-index: 10;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
    transform: translate(-50%, -50%) !important;
    pointer-events: none;
    border: 2px solid rgba(255, 255, 255, 0.3);
    letter-spacing: 0.02em;
}

/* Clues in Block Cells */
.clue-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.clue-h {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.9rem;
    color: var(--secondary-color);
    font-weight: 700;
}

.clue-v {
    position: absolute;
    bottom: 5px;
    left: 5px;
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 700;
}

.diagonal-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to top right,
            transparent calc(50% - 1px),
            var(--grid-line) calc(50% - 0.5px),
            var(--grid-line) calc(50% + 0.5px),
            transparent calc(50% + 1px));
    opacity: 0.5;
}

/* Notes Grid (3x3 inside cell) */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.note-num {
    font-size: 0.6rem;
    color: var(--text-muted);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
}

/* Grid Layout Structures */
.board-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--grid-line);
    background-color: var(--grid-line);
}

.col-notes-row {
    display: grid;
    gap: 0;
    background-color: var(--grid-line);
}

.main-grid-area {
    display: grid;
    gap: 0;
    background-color: var(--grid-line);
}

.main-grid-area-with-gaps {
    display: grid;
    gap: 0;
    background-color: var(--grid-line);
    position: relative;
}

/* Margin Corner */
.margin-corner {
    width: 40px;
    height: 28px;
    background: transparent;
}

/* Margin Notes */
.margin-note {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.margin-note:hover {
    background: rgba(79, 159, 255, 0.12);
}

.margin-note-col {
    width: 60px;
    height: 28px;
    background: rgba(20, 184, 166, 0.06);
    border: 1px solid var(--grid-line);
}

.margin-note-row {
    width: 40px;
    height: 60px;
    background: rgba(79, 159, 255, 0.06);
    border: 1px solid var(--grid-line);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
}

.note-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text-color);
    text-align: center;
    font-size: 0.7rem;
    outline: none;
    padding: 2px;
    box-sizing: border-box;
    font-family: inherit;
    font-weight: 600;
}

.margin-note {
    position: relative;
    /* Ensure absolute child aligns to this */
}

.note-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg-secondary);
    /* Solid background to hide underlying text/glitches */
    color: var(--text-color);
    text-align: center;
    font-size: 0.9rem;
    /* Slightly larger for visibility */
    outline: none;
    padding: 0;
    margin: 0;
    font-family: inherit;
    font-weight: 700;
    z-index: 50;
    line-height: normal;
}

.margin-note-row .note-input {
    /* Force horizontal orientation for typing */
    writing-mode: horizontal-tb !important;
    transform: none !important;
}

.note-input:focus {
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* ===============================================
   MODALS
   =============================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Also center modal when display is set to block (legacy compatibility) */
.modal[style*="display: block"],
.modal[style*="display:block"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary-color);
    color: white;
    padding: 1rem 2rem;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    z-index: 3000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 50px);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.modal-content {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    margin: 0;
}


@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close:hover {
    background: var(--surface-elevated);
    color: var(--text-color);
}

.modal-content h2 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    color: var(--text-color);
}

/* Rating Modal */
.rating-modal .modal-content {
    text-align: center;
}

.rating-content h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.rating-content p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.stars-container {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.star {
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    filter: grayscale(1);
}

.star:hover,
.star.active {
    filter: grayscale(0);
    transform: scale(1.1);
}

.rating-comment-box {
    width: 100%;
    min-height: 100px;
    padding: 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.875rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 1.5rem;
}

.rating-comment-box:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.rating-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Library Modal */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    padding: 0.75rem 1.25rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--text-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.library-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
}

.puzzle-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.puzzle-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(79, 159, 255, 0.2);
}

.puzzle-thumbnail {
    width: 140px;
    height: 140px;
    background: var(--surface-elevated);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    display: grid;
    gap: 1px;
    padding: 4px;
    border: 1px solid var(--border-color);
    margin-left: auto;
    margin-right: auto;
}

.mini-cell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7px;
    font-weight: 800;
    color: var(--white-cell-text);
    overflow: hidden;
    line-height: 1;
    aspect-ratio: 1/1;
}

.mini-cell.block {
    background: var(--block-color);
}

.mini-cell.white {
    background: var(--white-cell);
}

.puzzle-info h3 {
    margin: 0 0 5px 0;
    font-size: 1rem;
    color: var(--text-color);
}

.puzzle-info p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.puzzle-card .delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.2rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0.5;
    transition: all 0.2s;
}

.puzzle-card .delete-btn:hover {
    opacity: 1;
    background: rgba(244, 63, 94, 0.3);
    transform: none;
}

/* Auth Modal */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-input {
    padding: 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.95rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-error {
    color: var(--danger-color);
    font-size: 0.875rem;
    padding: 0.75rem;
    background: rgba(244, 63, 94, 0.1);
    border-radius: var(--radius-sm);
    display: none;
}

.auth-error.show {
    display: block;
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 0.5rem 0;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.auth-divider span {
    padding: 0 1rem;
    color: var(--text-dim);
    font-size: 0.875rem;
}

.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-oauth {
    padding: 0.875rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    font-family: inherit;
}

.btn-oauth:hover {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
}

.auth-switch {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Verification Code */
.verification-code-container {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin: 2rem 0;
}

.code-input {
    width: 50px;
    height: 60px;
    text-align: center;
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-color);
    transition: all 0.3s ease;
    font-family: 'JetBrains Mono', monospace;
}

.code-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
    transform: scale(1.05);
}

.code-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.code-input.error {
    border-color: var(--danger-color);
    animation: shake 0.4s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.resend-text {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.resend-text a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.resend-text a:hover {
    text-decoration: underline;
}

#verify-email-display {
    color: var(--primary-color);
}

/* ===============================================
   MOBILE STYLES (Preserve Your Clean Design)
   =============================================== */
.mobile-bottom-nav {
    display: none;
}

#mobile-settings-modal,
#mobile-notebook-modal {
    display: none;
}

.mobile-numpad {
    display: none;
}

@media (max-width: 968px) {

    /* Preserve your mobile design exactly as is */
    #root {
        padding: 0;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }

    .app-container {
        width: 100%;
        margin: 0;
        padding-bottom: 70px;
    }

    .header {
        display: none;
    }

    .sidebar-left,
    .sidebar-right {
        display: none !important;
    }

    .action-bar {
        display: none;
    }

    .main-layout {
        display: block;
        padding: 10px;
    }

    .game-area {
        margin-top: 20px;
        width: 100%;
        padding: 0;
        background: transparent;
    }

    .board-container {
        padding: 10px;
        width: 100%;
        overflow: auto;
        display: flex;
        justify-content: center;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .cell {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
        touch-action: manipulation;
        -webkit-touch-callout: none;
        user-select: none;
        -webkit-user-select: none;
    }

    .main-grid-area-with-gaps {
        grid-template-columns: 30px repeat(var(--cols), 45px) !important;
        grid-template-rows: repeat(var(--rows), 45px) !important;
    }

    .col-notes-row {
        grid-template-columns: 30px repeat(var(--cols), 45px) !important;
    }

    .margin-note-col {
        width: 45px !important;
        font-size: 0.6rem;
    }

    .margin-note-row {
        height: 45px !important;
        width: 30px !important;
        font-size: 0.6rem;
    }

    .margin-corner {
        width: 30px !important;
    }

    .note-input {
        font-size: 0.6rem !important;
    }

    /* REMOVED .app-container::before pseudo-header */

    /* MOBILE HEADER */
    .mobile-header {
        display: block;
        background: var(--surface-color);
        border-bottom: 1px solid var(--border-color);
        padding: 0.75rem 1rem;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-header-content {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    .mobile-brand {
        margin: 0;
        font-size: 1.2rem;
        font-weight: 800;
        color: var(--primary-color);
        font-family: 'JetBrains Mono', 'Space Mono', monospace;
    }

    /* Position the button absolutely to the left */
    .mobile-header .btn-theme-toggle {
        position: absolute;
        left: 0;
        border: none;
        padding: 0.5rem;
    }

    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 65px;
        background: var(--surface-color);
        border-top: 1px solid var(--border-color);
        z-index: 1000;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
    }

    .nav-item {
        background: none;
        border: none;
        color: var(--text-muted);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 0.7rem;
        gap: 4px;
        flex: 1;
        height: 100%;
        cursor: pointer;
    }

    .nav-item.active {
        color: var(--primary-color);
    }

    .nav-icon {
        font-size: 1.4rem;
    }

    .mobile-numpad {
        display: none;
        position: absolute;
        z-index: 2000;
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
        width: 300px;
        background: var(--surface-elevated);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 10px;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(10px);
        transform: translateX(-50%);
    }

    .mobile-numpad.active {
        display: grid !important;
        animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    @keyframes popIn {
        from {
            opacity: 0;
            transform: translate(-50%, 10px);
        }

        to {
            opacity: 1;
            transform: translate(-50%, 0);
        }
    }

    .num-btn {
        height: 50px;
        width: 100%;
        border: none;
        border-radius: 8px;
        background: var(--bg-secondary);
        color: var(--text-color);
        font-size: 1.3rem;
        font-weight: 700;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        transition: all 0.1s;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    .num-btn:active {
        transform: scale(0.95);
        background: var(--primary-color);
        color: white;
    }

    .delete-btn {
        background: rgba(244, 63, 94, 0.15);
        color: var(--danger-color);
    }

    .delete-btn:active {
        background: var(--danger-color);
        color: white;
    }

    .modal-content {
        max-width: 90%;
        padding: 1.5rem;
    }

    .code-input {
        width: 40px;
        height: 50px;
        font-size: 1.5rem;
    }

    .verification-code-container {
        gap: 0.5rem;
    }
}

/* Responsive adjustments for medium screens */
@media (max-width: 1400px) and (min-width: 969px) {
    .main-layout {
        grid-template-columns: 260px 1fr 260px;
        gap: 0;
    }

    .sidebar-left,
    .sidebar-right {
        padding: 1.25rem;
    }

    .game-area {
        padding: 1.5rem;
    }
}

@media (max-width: 1200px) and (min-width: 969px) {
    .main-layout {
        grid-template-columns: 240px 1fr 240px;
    }

    .cell {
        width: 50px;
        height: 50px;
        font-size: 1.4rem;
    }

    .margin-note-col {
        width: 50px;
    }

    .margin-note-row {
        height: 50px;
    }
}

/* Tutorial Modal Styles */
.tutorial-content {
    max-width: 600px;
    text-align: left;
}

.tutorial-content h2 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.tutorial-content h3 {
    color: var(--text-color);
    font-size: 1.1rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.tutorial-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tutorial-content li {
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    line-height: 1.5;
}

.tutorial-content kbd {
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-family: inherit;
    font-size: 0.85em;
    box-shadow: 0 2px 0 var(--border-color);
}

/* Responsive Display Logic */
@media (min-width: 769px) {
    .tutorial-mobile {
        display: none;
    }
}

@media (max-width: 768px) {
    .tutorial-desktop {
        display: none;
    }

    .tutorial-content {
        padding: 1.5rem;
        width: 90%;
    }
}

/* ===============================================
   LEADERBOARD MODAL
   =============================================== */
.leaderboard-modal-content {
    max-width: 600px;
}

.leaderboard-container {
    margin-top: 1.5rem;
    max-height: 50vh;
    overflow-y: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table th {
    background: var(--surface-elevated);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.leaderboard-table tr:hover {
    background: rgba(79, 159, 255, 0.05);
}

.leaderboard-table tr.current-user {
    background: rgba(79, 159, 255, 0.1);
    color: var(--primary-color);
    font-weight: 700;
}

.rank-cell {
    width: 60px;
    font-weight: 700;
    color: var(--primary-color);
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.leaderboard-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-cell {
    font-weight: 700;
    color: var(--secondary-color);
}

.leaderboard-loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.user-score-display {
    font-size: 0.75rem;
    color: var(--secondary-color);
    font-weight: 700;
    margin-top: 2px;
}