/* =============================================================================
   Content Flow — guided intro drawn directly onto the real #periodic-table.
   Axis numbers, guide lines and mode buttons are grid children of the table,
   so they stay aligned with the element cells at any scale.
   ============================================================================= */

:root {
  --cf-period: #f0a04b;
  --cf-group: #e754c4;
  --cf-selected: #35d94a;
}

/* ---- Statement lives in the global nav bar ---- */
.cf-caption-bar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  z-index: 5;
  pointer-events: none;
}

.cf-caption-text {
  margin: 0;
  text-align: center;
  font-size: 1.35rem;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary, #1e293b);
  max-width: 1180px;
}

/* The statement replaces the nav's own controls for the flow's duration. */
body.content-flow-active .nav-center-group,
body.content-flow-active .nav-right-section,
body.content-flow-active .nav-brand-section {
  display: none;
}

/* A constant height that fits two lines. Fixed rather than auto so the table
   below never rescales between screens — that would shift the anchored panel. */
body.content-flow-active #global-nav {
  height: 84px;
  padding-top: 10px;
  padding-bottom: 10px;
}

body.content-flow-active .cf-caption-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Extra clearance so the taller nav never sits over the group numbers, and a
   constant top-anchored layout so the table sits identically on every screen
   (any vertical drift would move the anchored panel with it). */
body.content-flow-active #main-container {
  padding-top: 132px;
  justify-content: flex-start;
}

body.content-flow-active .cf-caption-bar {
  position: static;
  flex: 1;
}

/* Room in the margins for the axis numbers and the PERIODS/GROUPS label.
   The generous top gap keeps the group numbers (which sit above row 1) clear
   of the nav bar carrying the statement. */
body.content-flow-active #periodic-table {
  padding: 92px 0 60px 46px;
}

/* Dim the table so the annotation lines and any highlighted cells read
   clearly, matching the darkened look of the source slides. */
body.content-flow-active #periodic-table .element {
  opacity: 0.4;
  filter: saturate(0.75);
  transition: opacity 0.25s ease, filter 0.25s ease;
}

/* Highlighted cells stay fully lit and override the dim. */
body.content-flow-active #periodic-table.highlighting .element.highlighted {
  opacity: 1;
  filter: brightness(1.06);
}

/* ---- Annotation layer ----
   Absolutely positioned inside the table and driven by JS measurements taken
   from real cells, so it stays aligned regardless of the table's CSS scale
   transform (subgrid cannot be used: the parent's row track list does not
   match, and the table is transform-scaled). */
.cf-axis-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 120;
}

/* Axis numbers (1-7 down the left, 1-18 across the top) */
.cf-axis-mark {
  position: absolute;
  pointer-events: auto;
  border: none;
  background: transparent;
  font-weight: 800;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, filter 0.15s ease;
  z-index: 2;
}

/* Numbers sit in the margin outside the grid, not on top of the cells. */
.cf-axis-period {
  color: var(--cf-period);
  transform: translate(-150%, -50%);
}

.cf-axis-group {
  color: var(--cf-group);
  transform: translate(-50%, -150%);
}

.cf-axis-mark:hover {
  filter: brightness(1.15);
}

.cf-axis-period.selected {
  transform: translate(-150%, -50%) scale(1.4);
}

.cf-axis-group.selected {
  transform: translate(-50%, -150%) scale(1.4);
}

/* Guide lines across each row / down each column */
.cf-axis-line {
  position: absolute;
  z-index: 1;
  opacity: 0.5;
  transition: opacity 0.2s ease, box-shadow 0.2s ease;
}

.cf-axis-line-period {
  height: 2px;
  transform: translateY(-50%);
  background: var(--cf-period);
  color: var(--cf-period);
}

.cf-axis-line-group {
  width: 2px;
  transform: translateX(-50%);
  background: var(--cf-group);
  color: var(--cf-group);
}

.cf-axis-line.selected {
  opacity: 1;
  box-shadow: 0 0 10px currentColor;
}

.cf-axis-line-period.selected {
  height: 3px;
}

.cf-axis-line-group.selected {
  width: 3px;
}

/* ---- Element screens: both legends drawn dotted; the tapped element's own
   row and column turn green (matches the Chromium slide). ---- */
.cf-axis-layer[data-axis="both"] .cf-axis-line {
  background: none;
  opacity: 0.85;
}

.cf-axis-layer[data-axis="both"] .cf-axis-line-period {
  height: 0;
  border-top: 3px dotted var(--cf-group);
}

.cf-axis-layer[data-axis="both"] .cf-axis-line-group {
  width: 0;
  border-left: 3px dotted var(--cf-group);
}

.cf-axis-layer[data-axis="both"] .cf-axis-mark {
  color: var(--cf-group);
}

.cf-axis-layer[data-axis="both"] .cf-axis-line-period.selected {
  border-top-color: var(--cf-selected);
  box-shadow: none;
}

.cf-axis-layer[data-axis="both"] .cf-axis-line-group.selected {
  border-left-color: var(--cf-selected);
  box-shadow: none;
}

.cf-axis-layer[data-axis="both"] .cf-axis-mark.selected {
  color: var(--cf-selected);
}

/* "PERIODS" / "GROUPS" label, below the main block on the left */
.cf-axis-caption {
  position: absolute;
  left: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
}

.cf-axis-layer[data-axis="period"] .cf-axis-caption {
  color: var(--cf-period);
}

.cf-axis-layer[data-axis="group"] .cf-axis-caption {
  color: var(--cf-group);
}

/* ---- Period / Group heading, centred in the table's empty top gap ---- */
.cf-mode-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  z-index: 210;
  pointer-events: auto;
}

.cf-mode-btn {
  border: none;
  border-radius: 12px;
  padding: 12px 34px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  color: #3f2d16;
  background: linear-gradient(#f3f4f6, #d8dade);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.cf-mode-btn:hover {
  transform: translateY(-1px);
}

.cf-mode-btn.active {
  background: linear-gradient(#f5a63d, #d9822b);
  color: #3f2d16;
  box-shadow: 0 3px 10px rgba(217, 130, 43, 0.5);
}

/* ---- Panel: block / element-type chips, info bubble, nav.
   JS anchors it into the table's empty gap beneath the Period/Group heading;
   these values are the fallback when the gap is too narrow. ---- */
.content-flow-overlay {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 400;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  pointer-events: none;
}

/* Anchored: a fixed box in the table's gap. Content scrolls inside it so the
   box itself never grows over the surrounding element cells. */
.content-flow-overlay[data-anchored="true"] {
  max-height: none;
  overflow: hidden;
}

.content-flow-overlay[data-anchored="true"] .cf-panel {
  max-height: 100%;
  overflow: hidden;
}

/* The content area takes all remaining height and centres itself, so the
   info bubble reads as one surface with the nav row rather than being
   clipped behind it. */
.content-flow-overlay[data-anchored="true"] .cf-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  justify-content: center;
}

.cf-panel {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  padding: 12px 14px 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cf-panel-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.cf-pill {
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.03);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.cf-pill:hover {
  color: var(--text-primary, #1e293b);
  background: rgba(0, 0, 0, 0.06);
}

.cf-pill.active {
  background: #1e293b;
  border-color: #1e293b;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

/* An empty bubble would render as a bare blue strip. */
.cf-info-bubble:empty {
  display: none;
}

/* Fills the panel's content area and shares its surface with the nav row —
   no inner card, no clipping. */
.cf-info-bubble {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  padding: 14px 18px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Only claim the leftover height when the bubble is the sole content; with
   chips present it sizes to its text so neither gets squashed. */
.content-flow-overlay[data-anchored="true"] .cf-panel-scroll:not(:has(.cf-controls:not([hidden]))) .cf-info-bubble {
  flex: 1;
  min-height: 0;
}

.cf-info-head {
  font-size: 0.86rem;
  color: var(--text-secondary, #64748b);
  font-weight: 600;
}

.cf-info-sym {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary, #1e293b);
}

.cf-info-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary, #1e293b);
  margin-top: 3px;
}

.cf-info-body {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-primary, #1e293b);
  margin-top: 8px;
}

.cf-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding-top: 10px;
}

/* No chips and no info bubble: the nav row is the whole panel, so drop the
   divider that would otherwise float above nothing. */
.cf-panel:has(.cf-controls[hidden]):has(.cf-info-bubble[hidden]) .cf-nav {
  border-top: none;
  padding-top: 0;
}

.cf-panel:has(.cf-controls[hidden]):has(.cf-info-bubble[hidden]) .cf-panel-scroll {
  display: none;
}

.cf-progress {
  margin-right: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  font-variant-numeric: tabular-nums;
}

.cf-btn {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.cf-btn-ghost {
  background: transparent;
  color: var(--text-secondary, #64748b);
}

.cf-btn-ghost:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary, #1e293b);
}

.cf-btn-primary {
  background: #1e293b;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.cf-btn-primary:hover {
  background: #0f172a;
}

/* The specific element tapped on the element → period/group screens: it pops
   out of the dimmed table, as in the source slide. */
#periodic-table.highlighting .element.element-tap-focus,
body.content-flow-active #periodic-table .element.element-tap-focus {
  opacity: 1;
  filter: none;
  outline: 3px solid #1e293b;
  outline-offset: 2px;
  transform: scale(1.18);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  z-index: 130;
}

/* Keep the learner in the intro: nav visible but inert until it finishes. */
body.content-flow-active .global-nav {
  pointer-events: none;
  opacity: 0.55;
}

/* The intro supplies its own controls; the table's legend/EIT toolbar would
   sit under them and compete. */
body.content-flow-active #table-legend,
body.content-flow-active .eit-controller {
  visibility: hidden;
}

@media (max-width: 860px) {
  .cf-caption-bar {
    top: 60px;
    width: calc(100vw - 20px);
  }

  .cf-caption-text {
    font-size: 0.86rem;
    padding: 9px 14px;
  }

  .content-flow-overlay {
    right: 10px;
    left: 10px;
    bottom: 10px;
    width: auto;
    max-height: 42vh;
  }
}
