:root {
  color-scheme: dark;
}

* { box-sizing: border-box; }

body.periodic {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #131a2b 0%, #090b12 60%, #05060a 100%);
  color: #e6e9f2;
  font-family: 'Courier New', ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 100vh;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  /* extra bottom padding so the last grid row and footer can scroll clear
     of the fixed detail drawer instead of sitting underneath it */
  padding: 40px 20px 260px;
  text-align: center;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

header.top img.logo {
  width: 52px;
  height: 52px;
  border-radius: 10px;
}

header.top .wordmark {
  font-family: 'Open Sans', sans-serif;
  font-size: 28px;
  letter-spacing: 4px;
  font-weight: 700;
  color: #f2f4fb;
}

header.top .tagline {
  font-family: 'Open Sans', sans-serif;
  font-size: 13px;
  color: #8b93a8;
  letter-spacing: 1px;
}

p.lede {
  font-family: 'Open Sans', sans-serif;
  color: #a9b1c6;
  font-size: 14px;
  max-width: 640px;
  line-height: 1.6;
  margin: 18px auto 26px;
}

/* -- legend --------------------------------------------------------- */

.legend-row {
  font-family: 'Open Sans', sans-serif;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  /* No row-gap here -- a flex-basis:100% break (see .legend-break) becomes
     its own zero-height line, and row-gap applies on both sides of it,
     effectively doubling the gap for an in-row wrap versus the plain
     margin-bottom below used between two different legend rows. The wrap
     gap is set explicitly on .legend-break itself instead, so both kinds
     of break read as the same spacing. */
  gap: 0 22px;
  font-size: 12px;
  color: #b7bfd4;
}

#lang-legend {
  margin-bottom: 30px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Off by default (desktop's row is wide enough for every item on one
   line) -- only forces a wrap under the mobile breakpoint below, where
   periodic.js has already picked how many items belong on each line. */
.legend-break {
  display: none;
}

.legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  box-shadow: 0 0 8px currentColor;
}

.legend-row .legend-item {
  cursor: pointer;
  padding: 3px 6px;
  margin: -3px -6px;
  border-radius: 5px;
  transition: background 0.12s ease;
}

.legend-row .legend-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.legend-row .legend-item.locked {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px currentColor;
}

/* -- grid ------------------------------------------------------------ */

.family-block {
  margin-bottom: 26px;
}

.family-block h3 {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0 0 10px;
  opacity: 0.85;
}

.family-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.element {
  --card-color: #8ecae6;
  --fam-color: #8ecae6;
  position: relative;
  width: 92px;
  height: 92px;
  background: linear-gradient(160deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid color-mix(in srgb, var(--card-color) 45%, #2a3040);
  border-radius: 8px;
  color: #e6e9f2;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease,
    width 0.15s ease, height 0.15s ease;
}

.element:hover,
.element:focus-visible {
  width: calc(92px * 1.2);
  height: calc(92px * 1.2);
  transform: translateY(-3px);
  border-color: var(--card-color);
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--card-color) 70%, transparent);
  outline: none;
}

.element.active {
  border-color: var(--card-color);
  background: linear-gradient(160deg, color-mix(in srgb, var(--card-color) 18%, transparent), rgba(255,255,255,0.01));
  box-shadow: 0 0 0 1px var(--card-color), 0 8px 22px -6px color-mix(in srgb, var(--card-color) 80%, transparent);
}

.element .num {
  position: absolute;
  top: 5px;
  left: 7px;
  font-size: 9px;
  color: #767e94;
}

.element .symbol {
  font-size: 24px;
  font-weight: 700;
  color: var(--fam-color);
  line-height: 1.1;
}

.element .ename {
  font-size: 9px;
  color: #b7bfd4;
  text-align: center;
  line-height: 1.2;
  margin-top: 4px;
  word-break: break-word;
}

/* tiers -- same footprint for every cell; tier reads through glow/weight/dimming only */
.element.tier-highlight {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--card-color) 55%, transparent),
    0 0 14px -4px color-mix(in srgb, var(--card-color) 70%, transparent);
}
.element.tier-highlight .ename { font-weight: 600; color: #d7dcec; }

.element.tier-standard { opacity: 0.92; }

.element.tier-minor { opacity: 0.55; }
.element.tier-minor .symbol { font-size: 20px; }

/* -- legend hover/click filtering ------------------------------------- */

.element.filter-highlight {
  opacity: 1;
  transform: translateY(-2px);
  border-color: var(--card-color);
  box-shadow: 0 0 0 1px var(--card-color),
    0 0 16px -2px color-mix(in srgb, var(--card-color) 80%, transparent);
}

.element.filter-muted {
  opacity: 0.5;
}

/* -- detail drawer ------------------------------------------------------ */
/* pinned to the bottom of the window; slides up on selection, slides back
   down on close instead of scrolling away like the page's own footer. */

#detail {
  --card-color: #8ecae6;
  --fam-color: #8ecae6;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 55vh;
  overflow-y: auto;
  border-top: 1px solid color-mix(in srgb, var(--card-color) 40%, #2a3040);
  border-radius: 16px 16px 0 0;
  background: linear-gradient(180deg, rgba(19, 26, 43, 0.98), rgba(5, 6, 10, 0.99));
  box-shadow: 0 -14px 34px -12px rgba(0, 0, 0, 0.65);
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

#detail.open {
  transform: translateY(0);
}

.detail-inner {
  max-width: 700px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  min-height: 140px;
  text-align: left;
}

.detail-symbol {
  font-size: 54px;
  font-weight: 700;
  color: var(--fam-color);
  line-height: 1;
  min-width: 90px;
  text-align: center;
}

.detail-body {
  max-width: 800px;
  min-width: 0;
}

.detail-body h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #f2f4fb;
  font-family: 'Open Sans', sans-serif;
}

.detail-body .lang {
  font-size: 11px;
  color: #767e94;
  font-weight: 400;
  margin-left: 8px;
}

.detail-blurb {
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
  color: #cfd4e6;
  margin: 0 0 10px;
}

.detail-text {
  font-family: 'Open Sans', sans-serif;
  font-size: 13px;
  color: #9aa2b8;
  line-height: 1.6;
  margin: 0 0 12px;
  max-width: 620px;
}

.detail-link {
  font-size: 12px;
  color: var(--card-color);
  text-decoration: none;
  overflow-wrap: anywhere;
}
.detail-link:hover { text-decoration: underline; }

/* -- about / bio -------------------------------------------------------- */

section.about {
  margin-top: 54px;
  padding-top: 30px;
  border-top: 1px solid #1e2333;
}

section.about h3 {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #767e94;
  margin: 0 0 14px;
}

section.about p {
  font-family: 'Open Sans', sans-serif;
  font-size: 14.5px;
  line-height: 1.7;
  color: #b7bfd4;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

section.about .career {
  font-size: 12.5px;
  color: #767e94;
  margin-top: 8px;
}

/* -- footer -------------------------------------------------------- */

footer.bottom {
  margin-top: 50px;
  font-family: 'Open Sans', sans-serif;
  font-size: 11px;
  color: #767e94;
}

footer.bottom a {
  color: #9aa2b8;
  text-decoration: none;
}
footer.bottom a:hover { color: #e6e9f2; }

@media (max-width: 600px) {
  .wrap { padding: 26px 14px 220px; }
  header.top .wordmark { font-size: 22px; }
  .detail-inner { flex-direction: column; }
  .detail-symbol { font-size: 40px; text-align: left; }

  /* Grid instead of flex-wrap -- flex-wrap breaks rows by however many
     92px tiles fit the viewport width (4 & 2 on most phones for six
     tiles), which reads unevenly. --mobile-cols is set per family-row in
     periodic.js (balancedCols()), picking whatever column count splits
     that family's own tile count most evenly (3 for six, 2 for four) --
     falls back to 3 if the inline custom property is ever missing.
     Fixed-width (not 1fr) columns plus justify-content: center keeps
     tiles the same natural size as desktop and centers the row, instead
     of stretching tiles to fill the full row width -- 1fr made a
     2-column row's tiles balloon well past a 3-column row's. */
  .family-row {
    display: grid;
    grid-template-columns: repeat(var(--mobile-cols, 3), 92px);
    justify-content: center;
  }

  .element,
  .element:hover,
  .element:focus-visible {
    width: 92px;
    height: 92px;
    transform: none;
  }

  /* Forces exactly the column count periodic.js computed per legend row
     (balancedCols) -- the row itself stays flex-wrap, so each item keeps
     its own natural text width instead of being stretched into a grid
     cell. margin-top matches .legend-row's own margin-bottom exactly, so
     wrapping within a row and the gap between two different legend rows
     read as the same spacing instead of the wrap looking bigger. */
  .legend-break {
    display: block;
    flex-basis: 100%;
    height: 0;
    margin-top: 14px;
  }
}
