
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg:        #f0f0f0;
      --surface:   #e7e7e7;
      --border:    #232b25;
      --muted:     #3a4a3d;
      --accent:    #28a366;
      --accent2:   #ffdd57;
      --accent3:   #ff6b6b;
      --text:      #16b163;
      --text-dim:  #556959;
      --sidebar-w: 260px;
      --font-mono: 'IBM Plex Mono', monospace;
      --font-serif: 'Libre Baskerville', serif;
      --font-display: 'Space Mono', monospace;
    }

    html { scroll-behavior: smooth; }

    body {
      background: var(--bg);
      color: var(--text);
      font-family: var(--font-mono);
      font-size: 14px;
      line-height: 1.6;
      min-height: 100vh;
      display: flex;
      overflow-x: hidden;
    }

    /* ── SIDEBAR ──────────────────────────────────────────── */
    #sidebar {
      width: var(--sidebar-w);
      min-height: 100vh;
      background: var(--surface);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      position: fixed;
      top: 0; left: 0;
      z-index: 100;
      transition: transform .3s cubic-bezier(.4,0,.2,1);
    }

    .sidebar-logo {
      padding: 28px 24px 20px;
      border-bottom: 1px solid var(--border);
    }

    .sidebar-logo .wordmark {
      font-family: var(--font-display);
      font-size: 19px;
      font-weight: 700;
      color: var(--accent);
      letter-spacing: -0.5px;
    }

    .sidebar-logo .tagline {
      font-size: 10px;
      color: var(--text-dim);
      letter-spacing: 2px;
      text-transform: uppercase;
      margin-top: 4px;
    }

    .sidebar-nav {
      flex: 1;
      padding: 16px 0;
      overflow-y: auto;
    }

    .nav-section-label {
      font-size: 14px;
      letter-spacing: 3px;
      text-transform: uppercase;
      color: var(--muted);
      padding: 12px 24px 6px;
    }

    .nav-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 24px;
      cursor: pointer;
      color: var(--text-dim);
      font-size: 14px;
      transition: all .15s;
      border-left: 2px solid transparent;
      text-decoration: none;
    }

    .nav-item:hover {
      color: var(--text);
      background: rgba(79,255,176,0.04);
      border-left-color: var(--muted);
    }

    .nav-item.active {
      color: var(--accent);
      background: rgba(79,255,176,0.07);
      border-left-color: var(--accent);
    }

    .nav-item .nav-icon {
      font-size: 16px;
      width: 20px;
      text-align: center;
      flex-shrink: 0;
    }

    .sidebar-footer {
      padding: 16px 24px;
      border-top: 1px solid var(--border);
      font-size: 10px;
      color: var(--muted);
      letter-spacing: 1px;
    }

    /* ── HAMBURGER ────────────────────────────────────────── */
    #hamburger {
      display: none;
      position: fixed;
      top: 16px; left: 16px;
      z-index: 200;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 4px;
      width: 40px; height: 40px;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      flex-direction: column;
      gap: 5px;
      padding: 10px;
    }

    #hamburger span {
      display: block;
      width: 100%;
      height: 1.5px;
      background: var(--accent);
      transition: all .3s;
    }

    #overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.7);
      z-index: 99;
    }

    /* ── MAIN CONTENT ─────────────────────────────────────── */
    #main {
      margin-left: var(--sidebar-w);
      flex: 1;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
    }

    .topbar {
      padding: 21px 40px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 16px;
    }

    .tool-title {
      font-family: var(--font-display);
      font-size: 35px;
      font-weight: 700;
      color: var(--text);
      letter-spacing: -1px;
    }

    .tool-badge {
      font-size: 13px;
      letter-spacing: 1px;
      margin-left: auto;
      text-transform: uppercase;
      color: var(--accent);
      background: rgba(79,255,176,0.1);
      border: 1px solid rgba(79,255,176,0.25);
      padding: 3px 10px;
      border-radius: 20px;
    }

    .tool-content {
      padding: 40px;
      flex: 1;
    }
    

    /* ── TOOL PANELS ──────────────────────────────────────── */
    .tool-panel { display: none; }
    .tool-panel.active { display: block; }

    /* ── CARDS ────────────────────────────────────────────── */
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 4px;
      padding: 28px 32px;
      margin-bottom: 20px;
    }

    .card-content-wrapper {
      max-width: 1000px;       /* Content matches table width */
      margin: 0 auto;          /* Centers the content */
      padding: 0 40px;         /* Horizontal padding for mobile */
    }

    .card-label {
      font-size: 20px;
      text-align: center;
      letter-spacing: 2px;
      text-transform: uppercase;
      color: var(--text-dim);
      margin-bottom: 40px;
      margin-top: 5px;
    }

    /* ── INPUTS ───────────────────────────────────────────── */
    .input-row {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 16px;
      margin-bottom: 20px;
    }

    .field { display: flex; flex-direction: column; gap: 6px; }

    .field label {
      font-size: 10px;
      letter-spacing: 2px;
      text-transform: uppercase;
      color: var(--text-dim);
    }

    .field input, .field select {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 3px;
      color: var(--text);
      font-family: var(--font-mono);
      font-size: 14px;
      padding: 10px 14px;
      outline: none;
      transition: border-color .15s;
      appearance: none;
    }

    .field input:focus, .field select:focus {
      border-color: var(--accent);
    }

    .field input::placeholder { color: var(--muted); }

    .btn {
      background: var(--accent);
      color: #080f0a;
      font-family: var(--font-display);
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 1px;
      text-transform: uppercase;
      padding: 12px 28px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      transition: all .15s;
    }

    .btn:hover { background: #7bffca; transform: translateY(-1px); }
    .btn:active { transform: translateY(0); }

    .btn-ghost {
      background: transparent;
      color: var(--accent);
      border: 1px solid var(--accent);
    }

    .btn-ghost:hover { background: rgba(79,255,176,0.08); transform: none; }

    .result-box {
      background: var(--bg);
      border: 1px solid var(--border);
      border-left: 3px solid var(--accent);
      border-radius: 3px;
      padding: 16px 20px;
      margin-top: 20px;
      display: none;
    }

    .result-box.show { display: block; }

    .result-label {
      font-size: 9px;
      letter-spacing: 3px;
      text-transform: uppercase;
      color: var(--text-dim);
      margin-bottom: 8px;
    }

    .result-value {
      font-family: var(--font-display);
      font-size: 26px;
      color: var(--accent);
      font-weight: 700;
    }

    .result-unit {
      font-size: 13px;
      color: var(--text-dim);
      margin-left: 8px;
    }

    .result-formula {
      font-size: 11px;
      color: var(--muted);
      margin-top: 8px;
      font-style: italic;
    }

    .error-box {
      background: rgba(255,107,107,0.07);
      border: 1px solid rgba(255,107,107,0.3);
      border-radius: 3px;
      padding: 12px 16px;
      margin-top: 12px;
      color: var(--accent3);
      font-size: 12px;
      display: none;
    }

    .error-box.show { display: block; }

    /* ── PERIODIC TABLE ───────────────────────────────────── */
    .pt-wrapper {
      overflow-x: auto;
      padding-bottom: 10px;
    }

    .pt-grid {
      display: grid;
      /* 18 equal columns based on container width */
      grid-template-columns: repeat(18, 1fr); 
      gap: 4px; 
      width: 100%;       /* Set to 100% to fill container, or e.g. 90% */
      max-width: 1000px;  /* Optional: prevents it from getting comically wide on huge monitors */
      margin: 0 auto;     /* This centers the table if width is less than 100% */
      height: auto;
    }

    .pt-cell {
      /* This ensures cells stay square/consistent regardless of width */
      aspect-ratio: 1 / 1; 
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 5px;
      align-items: center;
      cursor: pointer;
      border-radius: 4px;
      transition: transform 0.1s;
    }

    .pt-cell:hover {
      transform: scale(1.05);
      z-index: 10;
    }

    .pt-cell .pt-num {
      font-size: 10px;
      line-height: 1;
    }

    .pt-cell .pt-sym {
      font-family: var(--font-display);
      font-size: 13px;
      font-weight: 700;
      line-height: 1.1;
    }

    .pt-cell .pt-name {
      font-size: 10px;
      opacity: 0.6;
      line-height: 1;
    }

    /* Element categories */
    .cat-alkali        { background: #ffe9d5; color: #d68039; }
    .cat-alkali-earth  { background: #ffeac3; color: #ce9d3a; }
    .cat-transition    { background: #c4dfff; color: #4c98e4; }
    .cat-post-trans    { background: #c6ffef; color: #40c091; }
    .cat-metalloid     { background: #ffffd1; color: #a7a731; }
    .cat-nonmetal      { background: #d4ffd4; color: #319e55; }
    .cat-halogen       { background: #ffd6cc; color: #c97d3f; }
    .cat-noble         { background: #ebd4ff; color: #ab40b4; }
    .cat-lanthanide    { background: #d1d1ff; color: #7878a1; }
    .cat-actinide      { background: #ceffa6; color: #8bb36a; }

    #element-info {
      display: flex;
      align-items: center;      /* Vertically centers Symbol with Text */
      justify-content: center;   /* Centers the whole group in the card */
      gap: 40px;                /* Space between Big Symbol and the data list */
      padding: 30px;
      opacity: 0;
      transition: opacity 0.3s;
      border-top: 1px solid var(--border); /* Adds a nice separator */
      margin-top: 20px;
    }

    #element-info.show {
      opacity: 1;
      display: flex; /* Ensures it stays flex when shown */
    }

    /* Big Symbol stays on the left of the flex container */
    #el-sym {
      font-family: var(--font-display);
      line-height: 0.8;
      min-width: 100px;
      text-align: center;
    }

    /* The box containing Name + Properties */
    .el-details {
      display: flex;
      flex-direction: column;
      align-items: flex-start; /* Keeps text left-aligned RELATIVE to the center */
    }

    #el-props {
      display: grid;
      grid-template-columns: 1fr 1fr; /* Optional: puts properties in two columns if wide enough */
      gap: 10px 44px;
    }

    .el-prop {
      display: flex;
      flex-direction: column; /* Stack Label over Value */
      align-items: flex-start;
    }

    .el-prop-k {
      color: var(--text-dim) !important; /* Forces it to stay muted */
      font-size: 11px;
      letter-spacing: 2px;
      text-transform: uppercase;
      margin-bottom: 2px;
    }

    /* Ensure the value is what pops */
    .el-prop-v {
      font-size: 18px;
      font-weight: 600;
      /* Color is handled by JS showElement function */
    }

    .legend {
      display: flex; flex-wrap: wrap; gap: 2px 19px; margin-top: 20px; justify-content: center; max-width: 800px; margin-left: auto; margin-right: auto;
    }

    .legend-item {
      display: flex; align-items: center; gap: 5px;
      font-size: 15px; color: var(--text-dim);
    }

    .legend-dot {
      width: 10px; height: 10px; border-radius: 2px;
    }

    /* ── FORMULA BOX ─────────────────────────────────────── */
    .formula-display-card {
      background: white;
      border: 1px solid #232b25;
      border-radius: 4px;
      padding: 40px;
      margin: 0 auto 30px auto;
      max-width: 1000px;
      text-align: center;
    }

    .formula-math {
      font-size: 42px; /* Large LaTeX style */
      font-family: var(--font-serif);
      color: var(--border);
      margin-bottom: 15px;
    }

    .formula-key {
      font-size: 12px;
      font-family: var(--font-serif);
      color: var(--text-dim);
      letter-spacing: 1px;
    }

    /* ── RESPONSIVE ───────────────────────────────────────── */
    @media (max-width: 768px) {
      #sidebar {
        transform: translateX(-100%);
      }

      #sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 40px rgba(0,0,0,0.8);
      }

      #hamburger { display: flex; }
      #overlay.show { display: block; }

      #main { margin-left: 0; }

      .topbar { padding: 16px 20px 16px 68px; }
      .tool-content { padding: 20px; }

      .pt-grid {
        grid-template-columns: repeat(18, 34px);
        grid-template-rows: repeat(10, 34px);
      }

      .pt-cell { width: 34px; height: 34px; }
      .pt-cell .pt-sym { font-size: 10px; }
      .pt-cell .pt-name { display: none; }
    }

    .suggestion-box {
      position: absolute;
      top: 100%;
      left: 0;
      right: 0;
      background: var(--surface);
      border: 1px solid var(--border);
      z-index: 1000;
      display: none;
      max-height: 200px;
      overflow-y: auto;
    }

    .suggestion-item {
      padding: 8px 12px;
      cursor: pointer;
      border-bottom: 1px solid var(--border);
    }

    .suggestion-item:hover {
      background: var(--bg);
      color: var(--accent);
    }

    /* Gray out button if invalid */
    .btn:disabled {
      opacity: 0.3;
      cursor: not-allowed;
      filter: grayscale(1);
    }