:root {
      --bg: #09090b;
      --surface: #18181b;
      --surface-hover: #27272a;
      --border: #27272a;
      --border-focus: #3f3f46;
      --accent: #a3e635;
      --accent-dim: #70a314;
      --accent-light: rgba(163, 230, 53, 0.15);
      --text: #f4f4f5;
      --text-muted: #a1a1aa;
      --text-dark: #52525b;
      --error: #ef4444;
      --error-bg: rgba(239, 68, 68, 0.1);
      --success: #10b981;
      --success-bg: rgba(16, 185, 129, 0.15);
      --warning: #f59e0b;
      --warning-bg: rgba(245, 158, 11, 0.1);
    }

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

    body {
      background: var(--bg);
      color: var(--text);
      font-family: 'Plus Jakarta Sans', sans-serif;
      min-height: 100vh;
      line-height: 1.5;
      overflow-x: hidden;
    }

    /* Layout */
    .app-container {
      max-width: 1200px;
      margin: 0 auto;
      padding: 32px 24px;
    }

    header {
      margin-bottom: 32px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .eyebrow {
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 2px;
      color: var(--accent);
      text-transform: uppercase;
    }

    h1 {
      font-size: clamp(28px, 4vw, 40px);
      font-weight: 800;
      letter-spacing: -0.03em;
      color: var(--text);
    }

    h1 span {
      background: linear-gradient(135deg, var(--accent) 30%, #60a5fa);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .subtitle {
      color: var(--text-muted);
      font-size: 15px;
      max-width: 600px;
    }

    .main-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 32px;
      align-items: start;
    }

    @media (min-width: 900px) {
      .main-grid {
        grid-template-columns: 480px 1fr;
      }
    }

    /* Cards */
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px;
      box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
      transition: border-color 0.2s;
    }

    .card:hover {
      border-color: var(--border-focus);
    }

    .card-title {
      font-size: 16px;
      font-weight: 700;
      margin-bottom: 16px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      letter-spacing: -0.01em;
    }

    /* Form Fields */
    .field {
      margin-bottom: 20px;
    }

    label {
      font-size: 12px;
      font-weight: 600;
      letter-spacing: 1px;
      color: var(--text-muted);
      text-transform: uppercase;
      display: block;
      margin-bottom: 8px;
    }

    label .optional {
      color: var(--text-dark);
      font-weight: 500;
      text-transform: lowercase;
    }

    .input-wrapper {
      position: relative;
    }

    input[type="text"] {
      width: 100%;
      background: rgba(0,0,0,0.2);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 14px 16px;
      color: var(--text);
      font-size: 16px;
      font-family: 'Fira Code', monospace;
      outline: none;
      transition: all 0.2s;
    }

    input[type="text"]:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px var(--accent-light);
    }

    /* Letter Chips */
    .chips-container {
      margin-top: 10px;
    }

    .chips-label {
      font-size: 11px;
      color: var(--text-dark);
      margin-bottom: 4px;
    }

    .chips {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .chip {
      background: rgba(0,0,0,0.2);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 3px 8px;
      font-size: 12px;
      font-family: 'Fira Code', monospace;
      color: var(--text-muted);
      cursor: pointer;
      user-select: none;
      transition: all 0.15s;
    }

    .chip:hover {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-light);
    }

    /* Preset Buttons */
    .preset-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
      margin-bottom: 24px;
    }

    .preset-btn {
      background: rgba(0, 0, 0, 0.15);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 10px;
      color: var(--text-muted);
      font-size: 12px;
      font-family: 'Fira Code', monospace;
      text-align: left;
      cursor: pointer;
      transition: all 0.2s;
      display: flex;
      flex-direction: column;
      gap: 2px;
    }

    .preset-btn:hover {
      background: var(--surface-hover);
      border-color: var(--accent);
      color: var(--text);
    }

    .preset-btn span {
      font-size: 10px;
      color: var(--text-dark);
    }

    /* Toggle Switches */
    .mode-toggle {
      display: flex;
      background: rgba(0,0,0,0.25);
      padding: 4px;
      border-radius: 10px;
      margin-bottom: 24px;
      border: 1px solid var(--border);
    }

    .mode-btn {
      flex: 1;
      padding: 8px 12px;
      border: none;
      background: transparent;
      color: var(--text-muted);
      font-size: 13px;
      font-weight: 600;
      border-radius: 8px;
      cursor: pointer;
      transition: all 0.2s;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
    }

    .mode-btn.active {
      background: var(--surface-hover);
      color: var(--accent);
      box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }

    /* Action Buttons */
    .btn-primary {
      width: 100%;
      padding: 14px;
      border-radius: 10px;
      background: var(--accent);
      color: #000;
      font-weight: 800;
      font-size: 15px;
      border: none;
      cursor: pointer;
      letter-spacing: 0.5px;
      text-transform: uppercase;
      transition: all 0.2s;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }

    .btn-primary:hover:not(:disabled) {
      background: #bbf7d0;
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(163, 230, 53, 0.2);
    }

    .btn-primary:active:not(:disabled) {
      transform: translateY(0);
    }

    .btn-primary:disabled {
      background: var(--accent-dim);
      opacity: 0.6;
      cursor: not-allowed;
    }

    /* Error Message */
    .error-box {
      margin-top: 16px;
      padding: 12px 16px;
      border-radius: 10px;
      background: var(--error-bg);
      border: 1px solid var(--error);
      color: var(--error);
      font-size: 14px;
      display: none;
      animation: fadeIn 0.2s ease-out;
    }

    /* Results Header and Stats */
    .results-meta {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
      flex-wrap: wrap;
      gap: 8px;
    }

    .results-count {
      font-size: 13px;
      font-weight: 700;
      color: var(--text-muted);
    }

    .stats-pill {
      font-size: 11px;
      background: var(--surface-hover);
      border: 1px solid var(--border);
      border-radius: 9999px;
      padding: 4px 12px;
      font-family: 'Fira Code', monospace;
      color: var(--text-muted);
    }

    .stats-pill span {
      color: var(--accent);
    }

    /* Vertical Math Grid Rendering */
    .vertical-math-card {
      background: #111;
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 24px;
      margin-bottom: 16px;
      position: relative;
      overflow: hidden;
      animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
    }

    .vertical-math-grid {
      display: grid;
      justify-content: center;
      margin: 16px auto;
      font-family: 'Fira Code', monospace;
      font-size: 24px;
      font-weight: 700;
      row-gap: 6px;
      width: fit-content;
    }

    .math-row {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      letter-spacing: 4px;
      position: relative;
    }

    .math-row.carry-row {
      font-size: 14px;
      color: var(--warning);
      letter-spacing: 14px;
      margin-bottom: 2px;
      height: 20px;
    }

    .math-row.sum-row {
      border-top: 2px solid var(--text-muted);
      margin-top: 4px;
      padding-top: 8px;
    }

    .math-row .operator {
      position: absolute;
      left: -28px;
      color: var(--text-muted);
      font-weight: 500;
    }

    .math-cell {
      width: 32px;
      height: 44px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      position: relative;
      cursor: pointer;
    }

    .math-cell.carry-cell {
      width: 32px;
      height: 20px;
    }

    .math-cell .letter {
      color: var(--accent);
      line-height: 1;
    }

    .math-cell .digit {
      font-size: 13px;
      color: var(--text-muted);
      margin-top: 2px;
      font-weight: 500;
    }

    .math-cell:hover .letter {
      color: #fff;
      transform: scale(1.1);
    }

    .math-cell.highlighted {
      background: var(--accent-light);
      border-radius: 4px;
    }

    /* Sandbox Panel Styles */
    .sandbox-container {
      display: flex;
      flex-direction: column;
      gap: 20px;
    }

    .digit-pool {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      padding: 12px;
      background: rgba(0,0,0,0.15);
      border-radius: 12px;
      border: 1px solid var(--border);
    }

    .pool-digit {
      width: 38px;
      height: 38px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      font-family: 'Fira Code', monospace;
      font-weight: 700;
      font-size: 16px;
      cursor: grab;
      user-select: none;
      transition: all 0.15s;
    }

    .pool-digit:hover:not(.used) {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-light);
    }

    .pool-digit.used {
      opacity: 0.3;
      cursor: not-allowed;
      background: rgba(0,0,0,0.2);
    }

    .manual-assignment-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
      gap: 12px;
    }

    .assign-card {
      background: rgba(0,0,0,0.15);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }

    .assign-card .letter {
      font-family: 'Fira Code', monospace;
      font-size: 18px;
      font-weight: 700;
      color: var(--accent);
    }

    .assign-card select {
      background: var(--surface);
      color: var(--text);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 4px 8px;
      font-family: 'Fira Code', monospace;
      outline: none;
      width: 100%;
      text-align: center;
      cursor: pointer;
    }

    .assign-card select:focus {
      border-color: var(--accent);
    }

    /* Verification Badge */
    .verification-badge {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: rgba(0,0,0,0.2);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 10px 16px;
      margin-top: 14px;
      font-family: 'Fira Code', monospace;
      font-size: 13px;
    }

    .badge-status {
      display: flex;
      align-items: center;
      gap: 6px;
      font-weight: 600;
    }

    .badge-status.valid {
      color: var(--success);
    }

    .badge-status.invalid {
      color: var(--error);
    }

    .badge-status.partial {
      color: var(--warning);
    }

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

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

    /* Spinner */
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
    .spinner {
      display: inline-block;
      width: 16px;
      height: 16px;
      border: 2px solid #000;
      border-top-color: transparent;
      border-radius: 50%;
      animation: spin 0.6s linear infinite;
    }

    .show-all-btn {
      width: 100%;
      padding: 12px;
      border-radius: 10px;
      background: transparent;
      border: 1px solid var(--border);
      color: var(--text-muted);
      cursor: pointer;
      font-size: 14px;
      font-weight: 600;
      transition: all 0.2s;
      margin-top: 8px;
    }

    .show-all-btn:hover {
      border-color: var(--text-muted);
      color: var(--text);
      background: var(--surface-hover);
    }

    .no-solution {
      text-align: center;
      padding: 40px;
      color: var(--text-muted);
      font-size: 14px;
    }

    /* Header presets */
    .tab-header {
      font-size: 14px;
      color: var(--text-muted);
      font-weight: 700;
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .tab-header span {
      background: var(--accent-light);
      color: var(--accent);
      font-size: 11px;
      padding: 2px 6px;
      border-radius: 4px;
    }
