  :root {
    --bg: #0a0c12;
    --bg2: #12151f;
    --bg3: #1a1e2e;
    --bg4: #222840;
    --text: #e8eaf6;
    --text2: #9098c0;
    --text3: #5a6290;
    --accent: #00d4ff;
    --accent2: #7c4dff;
    --border: rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.14);

    --alkali:       #ff5252;
    --alkaline:     #ff9100;
    --lanthanide:   #ff6d00;
    --actinide:     #ffd600;
    --transition:   #00b0ff;
    --post:         #69f0ae;
    --metalloid:    #40c4ff;
    --nonmetal:     #e040fb;
    --halogen:      #ff4081;
    --noble:        #7c4dff;

    --alkali-glow:      rgba(255,82,82,0.18);
    --alkaline-glow:    rgba(255,145,0,0.18);
    --lanthanide-glow:  rgba(255,109,0,0.18);
    --actinide-glow:    rgba(255,214,0,0.18);
    --transition-glow:  rgba(0,176,255,0.18);
    --post-glow:        rgba(105,240,174,0.18);
    --metalloid-glow:   rgba(64,196,255,0.18);
    --nonmetal-glow:    rgba(224,64,251,0.18);
    --halogen-glow:     rgba(255,64,129,0.18);
    --noble-glow:       rgba(124,77,255,0.18);
  }

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

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

  /* --- STARFIELD --- */
  #stars {
    position: fixed; inset: 0; pointer-events: none; z-index: 0;
    overflow: hidden;
  }
  #stars span {
    position: absolute;
    width: 2px; height: 2px;
    background: white;
    border-radius: 50%;
    opacity: 0;
    animation: twinkle var(--d) var(--delay) infinite;
  }
  @keyframes twinkle {
    0%,100% { opacity: 0; }
    50% { opacity: var(--op); }
  }

  /* --- LAYOUT --- */
  .wrapper { position: relative; z-index: 1; }

  header {
    text-align: center;
    padding: 2.5rem 2rem 1.5rem;
  }
  header h1 {
    font-family: 'Space Mono', monospace;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    letter-spacing: 0.12em;
    color: var(--text);
    text-transform: uppercase;
  }
  header h1 span { color: var(--accent); }
  header p {
    color: var(--text2);
    font-size: 0.9rem;
    margin-top: 0.4rem;
    letter-spacing: 0.04em;
  }

  /* --- SEARCH & FILTERS --- */
  .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    padding: 0.5rem 1.5rem 1.5rem;
  }
  .search-box {
    position: relative;
  }
  .search-box input {
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: 8px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    padding: 0.5rem 0.9rem 0.5rem 2.2rem;
    width: 220px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .search-box input::placeholder { color: var(--text3); }
  .search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0,212,255,0.15);
  }
  .search-icon {
    position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%);
    color: var(--text3); font-size: 0.85rem; pointer-events: none;
  }

  .filter-select {
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: 8px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.82rem;
    padding: 0.5rem 0.75rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%235a6290' d='M7 10l5 5 5-5H7z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 1.8rem;
  }
  .filter-select:focus { border-color: var(--accent); }
  .filter-select option { background: var(--bg3); }

  .mode-btn {
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: 8px;
    color: var(--text2);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
  }
  .mode-btn:hover, .mode-btn.active {
    background: var(--bg4);
    color: var(--accent);
    border-color: var(--accent);
  }

  /* --- LEGEND --- */
  .legend {
    display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
    justify-content: center;
    padding: 0 1.5rem 1.2rem;
    font-size: 0.73rem;
  }
  .legend-item {
    display: flex; align-items: center; gap: 0.35rem;
    color: var(--text2);
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 5px;
    border: 1px solid transparent;
    transition: all 0.2s;
  }
  .legend-item:hover { background: var(--bg3); border-color: var(--border2); }
  .legend-item.active { background: var(--bg4); border-color: var(--border2); color: var(--text); }
  .legend-dot {
    width: 10px; height: 10px; border-radius: 50%;
    flex-shrink: 0;
  }

  /* --- PERIODIC TABLE GRID --- */
  .table-container {
    overflow-x: auto;
    padding: 0 1rem 1rem;
  }
  .pt-grid {
    display: grid;
    /* 1 column for labels + 18 columns for the groups */
    grid-template-columns: 34px repeat(18, minmax(52px, 1fr));
    grid-template-rows: repeat(10, auto);
    gap: 3px;
    min-width: 980px;
    max-width: 1300px;
    margin: 0 auto;
  }

  /* --- ELEMENT CARD --- */
  .el {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 3px 3px;
    cursor: pointer;
    transition: all 0.18s ease;
    background: var(--bg2);
    min-height: 58px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center;
    overflow: hidden;
    user-select: none;
  }
  .el::before {
    content: '';
    position: absolute; inset: 0;
    opacity: 0;
    transition: opacity 0.18s;
    border-radius: 5px;
  }
  .el:hover { transform: scale(1.14) translateZ(0); z-index: 10; border-color: rgba(255,255,255,0.25); }
  .el.dimmed { opacity: 0.1; }
  .el.highlighted { opacity: 1; transform: scale(1.06); }
  .el.selected { border-color: var(--accent) !important; box-shadow: 0 0 0 2px var(--accent), 0 0 20px rgba(0,212,255,0.35); }

  .el-num { font-family: 'Space Mono', monospace; font-size: 0.58rem; color: rgba(255,255,255,0.75); line-height: 1; }
  .el-sym { font-family: 'Space Mono', monospace; font-weight: 700; font-size: 1.1rem; color: var(--text); line-height: 1.1; }
  .el-name { font-size: 0.46rem; color: rgba(255,255,255,0.82); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; font-weight: 500; }
  .el-mass { font-size: 0.44rem; color: rgba(255,255,255,0.65); line-height: 1; }

  /* per category coloring */
  .cat-alkali      { background: rgba(255,82,82,0.12);   border-color: rgba(255,82,82,0.3);   }
  .cat-alkali .el-sym { color: #ff7c7c; }
  .cat-alkali::before { background: var(--alkali-glow); }

  .cat-alkaline    { background: rgba(255,145,0,0.12);  border-color: rgba(255,145,0,0.3);   }
  .cat-alkaline .el-sym { color: #ffb340; }
  .cat-alkaline::before { background: var(--alkaline-glow); }

  .cat-lanthanide  { background: rgba(255,109,0,0.1);  border-color: rgba(255,109,0,0.25);  }
  .cat-lanthanide .el-sym { color: #ffa040; }
  .cat-lanthanide::before { background: var(--lanthanide-glow); }

  .cat-actinide    { background: rgba(255,214,0,0.08); border-color: rgba(255,214,0,0.22);  }
  .cat-actinide .el-sym { color: #ffd740; }
  .cat-actinide::before { background: var(--actinide-glow); }

  .cat-transition  { background: rgba(0,176,255,0.1);  border-color: rgba(0,176,255,0.25);  }
  .cat-transition .el-sym { color: #40caff; }
  .cat-transition::before { background: var(--transition-glow); }

  .cat-post        { background: rgba(105,240,174,0.1); border-color: rgba(105,240,174,0.25);}
  .cat-post .el-sym { color: #69f0ae; }
  .cat-post::before { background: var(--post-glow); }

  .cat-metalloid   { background: rgba(64,196,255,0.1); border-color: rgba(64,196,255,0.25); }
  .cat-metalloid .el-sym { color: #64cfff; }
  .cat-metalloid::before { background: var(--metalloid-glow); }

  .cat-nonmetal    { background: rgba(224,64,251,0.1); border-color: rgba(224,64,251,0.25); }
  .cat-nonmetal .el-sym { color: #e040fb; }
  .cat-nonmetal::before { background: var(--nonmetal-glow); }

  .cat-halogen     { background: rgba(255,64,129,0.1); border-color: rgba(255,64,129,0.25); }
  .cat-halogen .el-sym { color: #ff4081; }
  .cat-halogen::before { background: var(--halogen-glow); }

  .cat-noble       { background: rgba(124,77,255,0.12); border-color: rgba(124,77,255,0.3); }
  .cat-noble .el-sym { color: #b388ff; }
  .cat-noble::before { background: var(--noble-glow); }

  .el:hover::before { opacity: 1; }

  /* separator rows */
  .gap-row { grid-column: 1 / -1; height: 8px; }
  .label-row { 
    display: flex; align-items: center; justify-content: center;
    font-family: 'Space Mono', monospace; font-size: 0.55rem;
    color: var(--text3); border-radius: 4px;
    background: transparent; border: none; cursor: default;
    min-height: 20px;
  }
  .series-label {
    font-size: 0.6rem; color: var(--text3);
    writing-mode: initial;
    display: flex; align-items: center; justify-content: flex-end;
    padding-right: 8px; font-family: 'Space Mono', monospace;
    text-align: right; line-height: 1.2;
  }

  /* --- COLOR MODES overlay --- */
  .mode-electronegativity .el { background: var(--bg2); }
  .mode-electronegativity .el-sym { color: var(--text) !important; }
  .mode-mass .el { background: var(--bg2); }
  .mode-mass .el-sym { color: var(--text) !important; }

  /* --- COLOR SCALE BAR --- */
  #color-scale {
    display: none;
    max-width: 600px;
    margin: 0 auto 1rem;
    padding: 0.8rem 1.4rem;
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 12px;
  }
  #color-scale.visible { display: block; }
  .scale-title {
    font-family: 'Space Mono', monospace;
    font-size: 0.72rem;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.5rem;
    text-align: center;
  }
  .scale-desc {
    font-size: 0.75rem;
    color: var(--text2);
    text-align: center;
    margin-bottom: 0.7rem;
    line-height: 1.5;
  }
  .scale-bar-wrap {
    position: relative;
    margin: 0 0.5rem;
  }
  .scale-bar {
    height: 14px;
    border-radius: 7px;
    margin-bottom: 4px;
  }
  .scale-labels {
    display: flex;
    justify-content: space-between;
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    color: var(--text2);
  }
  .scale-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 0.62rem;
    color: var(--text3);
    margin-top: 3px;
    padding: 0 1px;
  }
  .scale-extremes {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text2);
    margin-top: 2px;
  }
  .scale-extremes span:first-child { color: #6ab4ff; }
  .scale-extremes span:last-child  { color: #ff5252; }

  /* --- MODAL OVERLAY --- */
  #modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center;
    padding: 1rem;
  }
  #modal-overlay.open { display: flex; }

  #modal {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 16px;
    max-width: 560px;
    width: 100%;
    position: relative;
    animation: modal-in 0.25s cubic-bezier(.34,1.4,.64,1);
    overflow: hidden;
    max-height: 90vh;
    overflow-y: auto;
  }
  @keyframes modal-in {
    from { opacity: 0; transform: scale(0.88) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }

  .modal-header {
    position: relative;
    padding: 1.8rem 1.8rem 1.2rem;
    border-bottom: 1px solid var(--border);
  }
  .modal-cat-bar {
    height: 4px; border-radius: 2px;
    position: absolute; top: 0; left: 0; right: 0;
  }
  .modal-symbol {
    font-family: 'Space Mono', monospace;
    font-size: 3.5rem; font-weight: 700;
    line-height: 1;
  }
  .modal-name {
    font-size: 1.35rem; font-weight: 500; margin-top: 0.2rem;
  }
  .modal-num {
    position: absolute; top: 1.8rem; right: 3.5rem;
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem; color: var(--text2);
  }
  .modal-cat-badge {
    display: inline-block;
    font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    padding: 3px 10px; border-radius: 20px;
    margin-top: 0.6rem;
  }

  .modal-body { padding: 1.4rem 1.8rem 1.8rem; }
  .modal-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1.5rem; margin-bottom: 1.4rem;
  }
  .modal-prop { }
  .modal-prop-label {
    font-size: 0.7rem; color: var(--text3); text-transform: uppercase;
    letter-spacing: 0.07em; margin-bottom: 0.15rem;
  }
  .modal-prop-value {
    font-family: 'Space Mono', monospace; font-size: 0.92rem; color: var(--text);
  }
  .modal-desc {
    font-size: 0.88rem; color: var(--text2); line-height: 1.65;
    border-top: 1px solid var(--border); padding-top: 1rem;
  }
  .modal-close {
    position: absolute; top: 1rem; right: 1rem;
    background: var(--bg3); border: 1px solid var(--border2);
    color: var(--text2); border-radius: 8px;
    width: 32px; height: 32px;
    cursor: pointer; font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; z-index: 10;
  }
  .modal-close:hover { background: var(--bg4); color: var(--text); }

  /* Electron shell diagram */
  .shell-diagram {
    display: flex; justify-content: center; align-items: center;
    margin: 1rem 0;
  }
  .shell-svg { overflow: visible; }

  /* Progress bars for properties */
  .prop-bar-wrap { margin-top: 1rem; }
  .prop-bar-label { font-size: 0.7rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 0.5rem; display: flex; justify-content: space-between; }
  .prop-bar { height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; margin-bottom: 0.55rem; }
  .prop-bar-fill { height: 100%; border-radius: 2px; transition: width 0.6s cubic-bezier(.34,1,.64,1); }

  /* --- QUIZ --- */
  #quiz-panel {
    display: none; max-width: 600px; margin: 0 auto;
    padding: 1.5rem;
    background: var(--bg2); border: 1px solid var(--border2); border-radius: 16px;
    margin-bottom: 2rem;
  }
  #quiz-panel.open { display: block; }
  .quiz-question { font-size: 1rem; color: var(--text); margin-bottom: 1.2rem; }
  .quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .quiz-opt {
    background: var(--bg3); border: 1px solid var(--border2);
    border-radius: 10px; padding: 0.7rem 1rem;
    cursor: pointer; font-size: 0.88rem; color: var(--text2);
    transition: all 0.18s; text-align: center;
  }
  .quiz-opt:hover { background: var(--bg4); color: var(--text); border-color: var(--accent); }
  .quiz-opt.correct { background: rgba(105,240,174,0.15); border-color: #69f0ae; color: #69f0ae; }
  .quiz-opt.wrong   { background: rgba(255,82,82,0.15);   border-color: #ff5252;   color: #ff5252;   }
  .quiz-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
  .quiz-score { font-family: 'Space Mono', monospace; font-size: 0.85rem; color: var(--text2); }
  .quiz-next {
    background: var(--accent); color: #000; border: none;
    border-radius: 8px; padding: 0.5rem 1.2rem; cursor: pointer;
    font-family: 'DM Sans', sans-serif; font-weight: 700; font-size: 0.85rem;
    transition: opacity 0.2s; display: none;
  }
  .quiz-next:hover { opacity: 0.85; }

  /* --- TOOLTIP --- */
  .tooltip {
    position: fixed; z-index: 999; pointer-events: none;
    background: var(--bg3); border: 1px solid var(--border2);
    border-radius: 8px; padding: 0.5rem 0.8rem;
    font-size: 0.75rem; color: var(--text2); white-space: nowrap;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    opacity: 0; transition: opacity 0.12s;
    max-width: 200px; white-space: normal;
  }
  .tooltip.visible { opacity: 1; }

  /* Period/Group labels */
  .period-label {
    display: flex; align-items: center; justify-content: center;
    font-family: 'Space Mono', monospace; font-size: 0.6rem;
    color: var(--text3); min-height: 58px;
  }
  .group-header {
    text-align: center; font-family: 'Space Mono', monospace; font-size: 0.6rem;
    color: var(--text3); padding-bottom: 4px; letter-spacing: 0.05em;
  }

  /* Info box in grid */
  .info-box {
    grid-column: 4 / 14;
    grid-row: 1 / 4;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 0.5rem;
  }
  .info-title {
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    letter-spacing: 0.08em; text-align: center;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(0,212,255,0.4);
    margin-bottom: 0.3rem;
  }
  .info-sub { font-size: 0.7rem; color: var(--text3); text-align: center; }

  @media (max-width: 700px) {
    .pt-grid { grid-template-columns: 28px repeat(18, 44px); min-width: 820px; }
    .el { min-height: 48px; }
    .el-sym { font-size: 0.9rem; }
    .el-name { font-size: 0.38rem; }
  }

  .footer-note { text-align: center; color: var(--text3); font-size: 0.73rem; padding: 2rem 1rem 1.5rem; }





.header-main {
  display: flex;
  align-items: flex-end;      /* Vertically aligns logo and title */
  justify-content: center;  /* Centers the whole block horizontally */
  gap: 0.75rem;              /* Space between logo and title */
  margin-bottom: 0.5rem;
}

.logo-container {
  flex-shrink: 0;           /* Prevents the logo from shrinking if the title is long */
  margin-bottom: -1.4rem; /* Adjust this value until the logo aligns perfectly with your description line */
  

.logo {
  width: 60px;              /* Adjusted for header height */
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Ensures the whole logo is visible */
  filter: invert(1) opacity(0.85); /* Turns black to white, slightly softened */
}

/* Optional: adjust title to look good next to the logo */
header h1 {
  margin: 0; /* Remove default margins so it aligns perfectly with the logo */
}
