:root {
        /* Modern Blue Theme (Light) */
        --bg: #f4f7f6;
        --panel: #ffffff;
        --sidebar-bg: #ffffff;
        --text: #1a2533;
        --accent: #0059b3;
        --accent-soft: #007bff;
        --border-thick: #00448a;
        --border-medium: #007bff;
        --border-thin: #d8e1e8;
        --cell-bg: #ffffff;
        --btn-primary: #0059b3;
        --btn-primary-hover: #00448a;
        --btn-secondary: #5a6b7d;
        --btn-secondary-hover: #42505e;
        --cell-trying-bg: #e0f0ff;
        --cell-backtrack-bg: #fff8e0;
        --cell-invalid-bg: #ffe0e0;
        --cell-active-bg: #dcedff;
        --cell-peer-bg: #f0f4f8;
        --toast-bg: #1a2533;
        --toast-text: #ffffff;
      }

      body.dark {
        /* Modern Blue Theme (Dark) */
        --bg: #121a22;
        --panel: #1a2430;
        --sidebar-bg: #16202a;
        --text: #e1e9f2;
        --accent: #0095ff;
        --accent-soft: #38abff;
        --border-thick: #0095ff;
        --border-medium: #007bff;
        --border-thin: #2c3a4a;
        --cell-bg: #1a2430;
        --btn-primary: #007bff;
        --btn-primary-hover: #006ae0;
        --btn-secondary: #3e4d5e;
        --btn-secondary-hover: #4f637a;
        --cell-trying-bg: #2a4a6c;
        --cell-backtrack-bg: #6c5a2a;
        --cell-invalid-bg: #6c2a2a;
        --cell-active-bg: #2a5a8c;
        --cell-peer-bg: #233140;
        --toast-bg: #e1e9f2;
        --toast-text: #121a22;
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      html {
        height: 100%;
      }

      body {
        font-family: "Poppins", system-ui, Segoe UI, Arial;
        background: var(--bg);
        color: var(--text);
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        transition: background 0.3s, color 0.3s;
      }

      header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 24px;
        background: var(--panel);
        box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
        border-bottom: 1px solid var(--border-thin);
        z-index: 100;
        flex-shrink: 0;
      }

      .brand {
        font-weight: 700;
        font-size: 22px;
        color: var(--accent);
      }

      .header-controls {
        display: flex;
        align-items: center;
        gap: 20px;
      }
      #userInfo {
        display: flex;
        align-items: center;
        gap: 12px;
        font-size: 15px;
      }
      #logoutBtn {
        all: unset;
        cursor: pointer;
        font-weight: 600;
        color: var(--btn-secondary);
        font-size: 14px;
        padding: 4px 8px;
        border-radius: 6px;
        transition: background 0.2s, color 0.2s;
      }
      #logoutBtn:hover {
        background: var(--btn-secondary-hover);
        color: #fff;
      }
      body.dark #logoutBtn {
        color: var(--text);
        opacity: 0.7;
      }
      body.dark #logoutBtn:hover {
        background: var(--btn-secondary-hover);
        color: var(--text);
        opacity: 1;
      }

      .btn {
        padding: 10px 16px;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        font-weight: 500;
        font-size: 15px;
        transition: background 0.2s, transform 0.1s;
        width: 100%;
      }
      .btn:disabled {
        background: var(--btn-secondary-hover);
        cursor: not-allowed;
        opacity: 0.7;
      }
      .btn.primary {
        background: var(--btn-primary);
        color: #fff;
      }
      .btn.primary:hover:not(:disabled) {
        background: var(--btn-primary-hover);
      }
      .btn.secondary {
        background: var(--btn-secondary);
        color: #fff;
      }
      .btn.secondary:hover:not(:disabled) {
        background: var(--btn-secondary-hover);
      }
      .btn:active {
        transform: scale(0.98);
      }
      
      .app-layout {
        flex: 1 1 auto;
        display: none;
        min-height: 0;
      }
      body.loggedIn .app-layout {
        display: grid;
        grid-template-columns: 320px 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
          "sidebar puzzle"
          "sidebar submission"
          "sidebar footer-area";
        gap: 0 24px;
        padding: 24px;
      }
      
      .sidebar {
        grid-area: sidebar;
        background: var(--sidebar-bg);
        padding: 24px;
        border: 1px solid var(--border-thin);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        display: flex;
        flex-direction: column;
        gap: 24px;
        overflow-y: auto;
        border-radius: 12px;
      }

      .sidebar-panel {
        background: var(--panel);
        border: 1px solid var(--border-thin);
        border-radius: 12px;
        padding: 20px;
      }
      .sidebar-panel h2 {
        font-size: 18px;
        font-weight: 600;
        color: var(--accent);
        margin-bottom: 16px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-thin);
      }
      
      main {
        grid-area: puzzle;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }

      section.puzzle-area {
        background: var(--panel);
        border-radius: 12px;
        padding: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        border: 1px solid var(--border-thin);
        width: auto;
      }

      .grid-wrapper {
        background: var(--border-thick);
        padding: 4px;
        border-radius: 8px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
      }

      .grid {
        display: grid;
        grid-template-columns: repeat(9, 44px);
        grid-template-rows: repeat(9, 44px);
        background: var(--border-thick);
      }

      #timerDisplay {
        font-size: 28px;
        font-weight: 700;
        color: var(--accent);
        text-align: center;
        margin-top: 16px;
        font-family: monospace;
      }

      .cell {
        width: 44px;
        height: 44px;
        text-align: center;
        font-size: 18px;
        border: 1px solid var(--border-thin);
        background: var(--cell-bg);
        color: var(--text);
        outline: none;
        transition: background 0.1s, color 0.1s, border-color 0.1s;
      }

      .cell:nth-child(-n + 9) {
        border-top: 3px solid var(--border-thick);
      }
      .cell:nth-child(9n + 1) {
        border-left: 3px solid var(--border-thick);
      }
      .cell:nth-child(9n) {
        border-right: 3px solid var(--border-thick);
      }
      .cell:nth-child(n + 73) {
        border-bottom: 3px solid var(--border-thick);
      }
      .cell:nth-child(3n) {
        border-right: 2px solid var(--border-medium);
      }
      .cell:nth-child(n + 19):nth-child(-n + 27),
      .cell:nth-child(n + 46):nth-child(-n + 54) {
        border-bottom: 2px solid var(--border-medium);
      }

      .cell:focus {
        border-color: var(--accent-soft);
      }
      .cell.original {
        font-weight: 700;
      }
      .cell.original[readonly] {
        background: var(--panel);
      }
      .cell.solved {
        color: var(--accent);
      }

      .cell.trying {
        background: var(--cell-trying-bg);
      }
      .cell.backtrack {
        background: var(--cell-backtrack-bg);
      }
      .cell.invalid {
        background: var(--cell-invalid-bg);
      }

      .cell.highlight-peer {
        background: var(--cell-peer-bg);
      }
      .cell.highlight-active {
        background: var(--cell-active-bg);
      }

      .controls {
        display: flex;
        flex-direction: column;
        gap: 16px;
        width: 100%;
      }
      .control-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
      }
      .control-group label {
        font-weight: 500;
        font-size: 14px;
        display: flex;
        flex-direction: column;
        gap: 6px;
      }
      .control-group .btn-group {
        display: flex;
        gap: 10px;
      }
      .btn-group .btn {
        flex: 1;
      }


      select {
        padding: 10px;
        border-radius: 8px;
        border: 1px solid var(--border-thin);
        background: var(--bg);
        color: var(--text);
        font-size: 15px;
        width: 100%;
      }

      #toast {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translate(-50%, 100%);
        background: var(--toast-bg);
        color: var(--toast-text);
        padding: 12px 24px;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        font-weight: 500;
        opacity: 0;
        visibility: hidden;
        transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s;
        z-index: 1000;
      }
      #toast.show {
        transform: translate(-50%, 0);
        opacity: 1;
        visibility: visible;
      }

      .submission-card {
        grid-area: submission;
        text-align: center;
        padding: 24px 40px;
        border-radius: 12px;
        background: var(--panel);
        box-shadow: 0 0 16px rgba(0, 0, 0, 0.05);
        border: 1px solid var(--border-thin);
        margin-top: 24px;
      }
      .submission-card h2 {
        color: var(--accent);
        font-size: 24px;
        margin-bottom: 8px;
      }
      .submission-card p {
        font-size: 17px;
        line-height: 1.6;
        color: var(--text);
      }

      footer {
        grid-area: footer-area;
        font-size: 14px;
        padding: 24px;
        background: var(--panel);
        border: 1px solid var(--border-thin);
        border-radius: 12px;
        margin-top: 24px;
      }
      
      .footer-grid {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 20px;
      }
      .stats-list {
        list-style: none;
        padding: 0;
      }
      .stats-list li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 4px;
        font-size: 15px;
        border-bottom: 1px solid var(--border-thin);
      }
      .stats-list li:last-child {
        border-bottom: none;
      }
      .stats-list span {
        font-weight: 600;
        color: var(--accent);
        font-size: 16px;
      }

      table {
        border-collapse: collapse;
        width: 100%;
        margin-top: 6px;
        font-size: 14px;
      }
      th,
      td {
        border: 1px solid var(--border-thin);
        padding: 6px 10px;
        text-align: left;
      }
      thead {
        background: var(--accent-soft);
        color: #fff;
      }
      body.dark thead {
        color: var(--text);
      }

      @media (max-width: 930px) {
        body.loggedIn .app-layout {
          display: flex;
          flex-direction: column;
          padding: 16px;
          gap: 16px;
        }
        
        main {
          order: 1;
        }
        
        .sidebar {
          order: 2;
          width: 100%;
          border-right: none;
          padding: 16px;
          flex-direction: column;
          gap: 16px;
        }
        .sidebar-panel {
          flex: 1;
          min-width: 0;
        }

        .submission-card {
          order: 3;
          width: 100%;
          margin-top: 0;
          padding: 20px;
        }
        
        footer {
          order: 4;
          width: 100%;
          margin-top: 0;
          padding: 16px;
        }

        section.puzzle-area {
          margin: 0 auto;
          transform: scale(0.95);
        }
      }
      
      #confetti {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 9999;
      }
      #themeBtn {
        all: unset;
        cursor: pointer;
        padding: 8px 18px;
        border-radius: 8px;
        border: 2px solid var(--accent);
        background: var(--panel);
        color: var(--accent);
        font-size: 15px;
        font-weight: 600;
        transition: background 0.25s ease, color 0.25s ease,
          border-color 0.25s ease, transform 0.1s;
        user-select: none;
      }
      #themeBtn:hover {
        background: var(--accent);
        color: var(--panel);
      }
      #themeBtn:active {
        transform: scale(0.97);
      }
      body.dark #themeBtn {
        border-color: var(--accent-soft);
        color: var(--accent-soft);
        background: var(--panel);
      }
      body.dark #themeBtn:hover {
        background: var(--accent-soft);
        color: #000;
      }

      #loginModal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(5px);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 2000;
      }
      body.loggedIn #loginModal {
        display: none;
      }
      .login-box {
        background: var(--panel);
        padding: 32px 40px;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
        text-align: center;
      }
      .login-box h2 {
        font-size: 22px;
        color: var(--accent);
        margin-bottom: 20px;
      }
      #usernameInput {
        font-size: 16px;
        padding: 12px 14px;
        border-radius: 8px;
        border: 1px solid var(--border-thin);
        width: 300px;
        margin-bottom: 20px;
        background: var(--bg);
        color: var(--text);
      }
      #loginBtn {
        width: 100%;
        min-width: 300px;
      }