/* ================================
   LAYOUT.CSS
   — Structure, layout, header
   ================================ */

/* ============ PAGE LAYOUT ============ */

.page {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  transition-property: transform;
  transition-timing-function: ease;
  will-change: transform, clip-path;
  contain: paint;
  transform-origin: center center;
  border-radius: 8px;
  margin: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.zoomed-out {
  transform: scale(20);
  pointer-events: none;
  border-radius: 12px;
}

.zoomed-in {
  transform: scale(1);
  pointer-events: auto;
  border-radius: 8px;
}

.clipped {
  clip-path: url(#holeClip);
  border-radius: 8px;
  will-change: clip-path;
}

.hidden {
  display: none !important;
}

/* ============ HEADER ============ */

#header {
  display: flex;
  flex-direction: column;
  background: #000; /* static black behind tabs */
  padding: 0;
  height: var(--header-height, 150px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  position: relative; /* elevate header above .page layers */
  z-index: 5;
}

/* TAB STRIP */
#tabs {
  display: flex;
  height: 56px;
  justify-content: center;
  align-items: stretch; /* ensures tabs fill height */
  background: #000;
  padding: 0 var(--space-sm);
}

/* Each tab fills height of #tabs */
.tab {
  flex: 1;
  text-align: center;
  padding: 0 var(--space-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-weight: var(--font-weight-bold);
  transition: all 0.3s ease;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  border-bottom: none;
  height: 100%;
  margin-top: 1px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  letter-spacing: 0.02em;
  font-size: 0.9rem;
}

/* Active tab background uses dark color */
.tab.active-blue {
  background: var(--color-blue-dark);
  color: #fff;
  transform: translateY(0);
  box-shadow: none;
  margin-bottom: -1px;
}

.tab.active-red {
  background: var(--color-red-dark);
  color: #fff;
  transform: translateY(0);
  box-shadow: none;
  margin-bottom: -1px;
}

.tab.active-dark {
  background: var(--color-green-dark);
  color: #fff;
  transform: translateY(0);
  box-shadow: none;
  margin-bottom: -1px;
}

/* Unselected tabs: darker than active tabs */
.tab[data-tab="lib"]:not(.active-blue) {
  background: #0c1d45;
  color: var(--color-text-subtle);
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.tab[data-tab="con"]:not(.active-red) {
  background: #4a0c0c;
  color: var(--color-text-subtle);
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.tab[data-tab="mix"]:not(.active-dark) {
  background: #082d16;
  color: var(--color-text-subtle);
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.tab:hover {
  filter: brightness(1.2);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
}

.tab.active-blue:hover,
.tab.active-red:hover,
.tab.active-dark:hover {
  transform: translateY(0);
}

.tab:focus {
  outline: 2px solid var(--color-blue-xbright);
  outline-offset: -2px;
}

/* ============ HEADER SUBSECTION ============ */

.header-subsection {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-md);
  padding: var(--space-xs) var(--space-md);
  height: calc(var(--header-height, 150px) - 56px);
  background: var(--header-subsection-bg, var(--color-blue-dark));
  color: var(--color-text-main);
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#header[data-theme="con"] .header-subsection {
  background: var(--header-subsection-bg, var(--color-red-dark));
}

#header[data-theme="mix"] .header-subsection {
  background: var(--header-subsection-bg, var(--color-green-dark));
}

#logo {
  height: 100%;
  aspect-ratio: 5 / 1;
  object-fit: contain;
  border-radius: 6px;
  max-width: 100%;
  box-shadow: none; /* removed drop shadow */
  transition: all 0.3s ease;
  background: transparent; /* removed background color */
  padding: 0;
}

#logo:hover {
  transform: scale(1.02);
}

#subtitleArea {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 100%;
  color: var(--color-text-subtle);
  font-size: 1.2rem;
  font-weight: 800; /* match list .name (font-weight: 800) */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.01em; /* match list .name tracking */
  font-family: inherit;
  will-change: opacity, transform; /* reduce paint/composite flicker during morph */
}

/* Ensure subtitle text measures to content width (for mobile centering target) */
#subtitleArea .subtitleText {
  display: inline-block;
  will-change: opacity, transform;
}

/* ============ POLITICIAN PAGE ============ */

#politicianPage,
#editPage,
#overlayPage {
  padding: var(--space-md);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

#polName {
  font-size: 2rem;
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-sm);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.02em;
}

#polContent {
  display: flex;
  gap: var(--space-md);
}

#polPic {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

#polPic:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

#polBio {
  flex: 1;
  font-size: 1.1rem;
  line-height: 1.6em;
  letter-spacing: 0.01em;
}

.editable {
  color: #ffd54f;
  cursor: pointer;
  text-decoration: underline dashed;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-weight: var(--font-weight-medium);
}

.editable:hover {
  filter: brightness(1.3);
  background: rgba(255, 213, 79, 0.1);
  transform: scale(1.05);
}

/* ============ WORD EDIT PAGE ============ */

#editHead {
  font-size: 1.8rem;
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-xs);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.02em;
}

/* #origText removed (no longer rendered) */

#options {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.optionRow {
  display: flex;
  align-items: center;
  padding: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 6px;
  margin-bottom: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.optionRow:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.optionRow:active {
  transform: translateY(0);
}

.optWord {
  font-size: 1.1rem;
  line-height: 1.4em;
  letter-spacing: 0.01em;
}

@media (max-width: 768px) {
  #header {
    height: auto;
  }

  .tab {
    font-size: 0.8rem;
    font-weight: var(--font-weight-regular);
    padding: 0 var(--space-sm);
  }

  .header-subsection {
    flex-direction: row;
    height: auto;
    padding: var(--space-sm);
    align-items: center;
  }

  #logo {
    height: 40px;
    flex-shrink: 0;
  }

  #subtitleArea {
    justify-content: center;
    font-size: 1rem;
  }

  #polContent {
    flex-direction: column;
    align-items: center;
  }

  #polPic {
    width: 100px;
    height: 100px;
  }
}

@media (max-width: 480px) {
  .tab {
    flex-basis: 100%;
    font-size: 0.75rem;
    padding: 0 var(--space-xs);
  }

  #polName {
    font-size: 1.5rem;
  }

  #polBio {
    font-size: 1rem;
  }

  /* Header refinements on very small screens */
  #header.no-tabs #logoutBtn {
    font-size: 12px;
    padding: 4px 8px;
  }
  #header.no-tabs #loginContainer > div {
    transform: scale(0.9);
    transform-origin: right center;
  }
}

/* iPhone SE specific optimizations */
@media (max-width: 375px) and (max-height: 667px) {
  .tab {
    font-size: 0.7rem;
    padding: 0 var(--space-xs);
  }
  
  #logo {
    height: 35px;
  }
  
  #subtitleArea {
    font-size: 0.9rem;
  }
}

/* ============ HEADER: NO-TABS MODE (preserve layout for animations) ============ */
#header.no-tabs {
  height: auto; /* allow content-driven height */
}
#header.no-tabs #tabs {
  display: none;
}
#header.no-tabs .header-subsection {
  height: auto;            /* fill based on content when tabs hidden */
  overflow: visible;       /* avoid clipping non-logo elements on wide screens */
  flex-wrap: nowrap;       /* desktop default: single row */
}

/* Desktop sizing to prevent the logo from dominating the row */
#header.no-tabs #logoWrap {
  flex: 0 0 auto;
  max-width: min(420px, 35%);             /* percent based on header container, not the image */
  display: flex;
  align-items: center;
}
#header.no-tabs #logo {
  height: 42px;                           /* updated desktop size */
  max-width: 100%;                         /* fill wrapper width as needed */
  width: auto;
  aspect-ratio: auto;                     /* remove enforced 5:1 width expansion */
}

/* Let subtitle occupy remaining space and ellipsize if needed */
#header.no-tabs #subtitleArea {
  flex: 1 1 auto;
  min-width: 0;                           /* enables text-overflow to work in flexbox */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Keep user controls sized to content and on the same row on desktop */
#header.no-tabs #userArea {
  flex: 0 0 auto;
}

/* Mobile layout for no-tabs header */
@media (max-width: 768px) {
  #header.no-tabs .header-subsection {
    padding: var(--space-xs) var(--space-sm);
    gap: var(--space-sm);
    flex-wrap: wrap; /* allow reflow on small screens */
  }
  #header.no-tabs #logo {
    height: 40px;
  }
  #header.no-tabs #userArea {
    order: 2;
    margin-left: auto;
  }
  #header.no-tabs #subtitleArea {
    order: 3;
    flex: 1 0 100%;
    font-size: 0.95rem;
    height: auto;
    align-items: center;
  }
}

/* Extra-compact tweaks for very small screens */
@media (max-width: 375px) and (max-height: 667px) {
  #header.no-tabs .header-subsection {
    gap: var(--space-xs);
  }
  #header.no-tabs #logo {
    height: 36px;
  }
}

/* ================================
   COMPOSITING + PAINT CONTAINMENT
   — Reduce end-of-transition flicker on wide viewports
   ================================ */

#transitionLayer,
#transitionLayerTop {
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
  contain: paint;
  }

.header-subsection {
  backface-visibility: hidden;
  }

#subtitleArea,
#subtitleArea .subtitleText {
  backface-visibility: hidden;
  transform: translateZ(0);
}
