/* ══════════════════════════════════════════════════════════
   BASE
══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #04060e;
  --text:     #e8eef8;
  --dimtext:  rgba(220,232,252,.72);
  --panel:    rgba(4,6,14,0.95);
  --border:   rgba(220,232,252,.16);

  /* per-view accent — swapped by app.js via data-view attribute */
  --accent:   #f5a623;
  --anti:     #ff6b35;
  --synth:    #18c97c;

  --nav-h:    58px;
  --desc-h:   36px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Crimson Text', Georgia, serif;
  color: var(--text);
}

/* ══════════════════════════════════════════════════════════
   INTRO SCREEN
══════════════════════════════════════════════════════════ */
#intro {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity .7s ease;
}
#intro.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Subtle scan-line texture */
#intro::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255,255,255,.012) 2px,
    rgba(255,255,255,.012) 4px
  );
  pointer-events: none;
}

/* Animated star field (CSS only) */
#intro-stars {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#intro-stars::before,
#intro-stars::after {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%; left: -50%;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(180,200,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 15%, rgba(180,200,255,.2) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 80% 60%, rgba(180,200,255,.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 40% 80%, rgba(180,200,255,.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 40%, rgba(180,200,255,.18) 0%, transparent 100%),
    radial-gradient(2px 2px at 10% 70%, rgba(200,180,255,.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 55%, rgba(180,200,255,.22) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 10%, rgba(200,220,255,.2) 0%, transparent 100%);
  animation: starDrift 120s linear infinite;
}
#intro-stars::after {
  animation-duration: 90s;
  animation-direction: reverse;
  opacity: .6;
}
@keyframes starDrift {
  to { transform: rotate(360deg); }
}

#intro-inner {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 860px;
  padding: 0 24px;
  max-height: 100vh;
  overflow: hidden;
}

#intro-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: clamp(.62rem, 1.2vw, .78rem);
  letter-spacing: .35em;
  text-transform: uppercase;
  color: var(--dimtext);
  margin-bottom: 12px;
  animation: fadeInDown .8s ease both;
  animation-delay: .2s;
}

#intro-title {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 16px;
  animation: fadeInUp .9s ease both;
  animation-delay: .5s;
}
.t-line {
  display: block;
  font-size: clamp(1.8rem, 5.5vw, 4rem);
  letter-spacing: .08em;
  background: linear-gradient(135deg, #f5d47a 0%, #f5a623 40%, #fff 70%, #b8d4ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.t-line--2 {
  font-size: clamp(1.2rem, 4vw, 3rem);
  letter-spacing: .28em;
  background: linear-gradient(135deg, #c8d8ff 0%, #88b4ff 50%, #3b9eff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation-delay: .7s;
}

#intro-sub {
  font-size: clamp(.9rem, 1.6vw, 1.1rem);
  font-style: italic;
  line-height: 1.75;
  color: rgba(220,232,252,.80);
  max-width: 560px;
  margin: 0 auto 28px;
  animation: fadeInUp .8s ease both;
  animation-delay: 1s;
}

/* ── Intro cards ── */
#intro-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 30px;
  animation: fadeInUp .8s ease both;
  animation-delay: 1.3s;
}

.icard {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
  border-top: 2px solid transparent;
  border-radius: 3px;
  padding: 22px 20px 18px;
  width: clamp(170px, 23vw, 230px);
  text-align: left;
  cursor: pointer;
  transition: background .25s, border-color .25s, transform .2s, box-shadow .25s;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-family: inherit;
  color: var(--text);
}
.icard:hover {
  background: rgba(255,255,255,.07);
  transform: translateY(-3px);
}
.icard--classical { --c: #f5a623; }
.icard--modern    { --c: #3b9eff; }
.icard--bridge    { --c: #c66aff; }
.icard--rochdale  { --c: #c8392a; }
.icard--culture   { --c: #d4922a; }
.icard--gender    { --c: #c44dff; }
.icard--nation    { --c: #2196f3; }
.icard:hover { border-top-color: var(--c); box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 30px rgba(var(--c-rgb, 255,255,255),.06); }
.icard--classical:hover { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(245,166,35,.1); }
.icard--modern:hover    { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(59,158,255,.1); }
.icard--bridge:hover    { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(198,106,255,.1); }
.icard--rochdale:hover  { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(200,57,42,.15); }
.icard--culture:hover   { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(212,146,42,.18); }
.icard--gender:hover    { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(196,77,255,.18); }
.icard--nation:hover    { box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(33,150,243,.18); }

.icard-num {
  font-family: 'Cinzel', serif;
  font-size: .7rem;
  letter-spacing: .25em;
  color: var(--c);
  opacity: .7;
}
.icard-name {
  font-family: 'Cinzel', serif;
  font-size: clamp(.78rem, 1.4vw, .92rem);
  font-weight: 600;
  letter-spacing: .05em;
  line-height: 1.3;
}
.icard-desc {
  font-size: .82rem;
  font-style: italic;
  line-height: 1.55;
  color: rgba(220,232,252,.70);
}
.icard-nodes {
  font-family: 'Cinzel', serif;
  font-size: .6rem;
  letter-spacing: .12em;
  color: var(--c);
  opacity: .72;
  margin-top: 4px;
}

#intro-hint {
  font-size: .72rem;
  font-style: italic;
  color: rgba(200,214,240,.22);
  letter-spacing: .05em;
  animation: fadeInUp .6s ease both;
  animation-delay: 1.7s;
}

/* ══════════════════════════════════════════════════════════
   KEYFRAMES
══════════════════════════════════════════════════════════ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ══════════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════════ */
#app {
  position: fixed;
  inset: 0;
  opacity: 1;
  transition: opacity .5s ease;
}
#app.hidden {
  opacity: 0;
  pointer-events: none;
}
#app.visible {
  opacity: 1;
  pointer-events: all;
}

/* ── Navigation ── */
#nav {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(4,6,14,.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

#nav-brand {
  display: flex;
  flex-direction: column;
}
#nav-home-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
#nav-title {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  font-size: clamp(.72rem, 1.3vw, .88rem);
  letter-spacing: .1em;
  color: var(--text);
  transition: color .2s;
}
#nav-home-btn:hover #nav-title { color: var(--accent); }
#nav-subtitle {
  font-size: .62rem;
  font-style: italic;
  color: rgba(220,232,252,.65);
  letter-spacing: .05em;
}

#nav-tabs {
  display: flex;
  gap: 4px;
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 14px 4px;
  font-family: 'Cinzel', serif;
  font-size: clamp(.6rem, 1.1vw, .74rem);
  letter-spacing: .1em;
  color: rgba(220,232,252,.62);
  cursor: pointer;
  transition: color .2s, border-color .2s;
  white-space: nowrap;
}
.tab:hover { color: rgba(204,214,232,.8); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-num {
  font-size: .58rem;
  opacity: .6;
  margin-right: 5px;
}

/* ── Canvas ── */
canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
}

/* ── Transition curtain ── */
#curtain {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease;
}
#curtain.show { opacity: 1; pointer-events: all; }

/* ── View description strip ── */
#view-desc {
  position: absolute;
  top: var(--nav-h);
  left: 0; right: 0;
  height: var(--desc-h);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4,6,14,.55);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  overflow: hidden;
}
#view-desc-text {
  font-size: clamp(.62rem, 1.1vw, .74rem);
  font-style: italic;
  color: rgba(220,232,252,.75);
  text-align: center;
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 900px;
}

/* ── Info panel ── */
#info {
  position: absolute;
  right: 16px;
  top: calc(var(--nav-h) + var(--desc-h) + 16px);
  width: clamp(200px, 21vw, 268px);
  max-height: calc(100vh - var(--nav-h) - var(--desc-h) - 80px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  z-index: 20;
  backdrop-filter: blur(16px);
  transition: opacity .35s ease, border-left-color .3s ease, width .3s ease, padding .3s ease;
  opacity: 0;
  pointer-events: none;
}
#info.show { opacity: 1; pointer-events: all; }

/* ── Toggle button ── */
#info-toggle {
  position: absolute;
  top: 8px;
  left: -28px;
  width: 24px;
  height: 48px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 4px 0 0 4px;
  color: var(--dimtext);
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s;
  padding: 0;
  line-height: 1;
}
#info-toggle:hover { color: var(--text); background: rgba(255,255,255,.06); }

/* collapsed state — just show the toggle tab */
#info.collapsed {
  width: 0;
  padding: 0;
  border-width: 0;
  overflow: visible;
}
#info.collapsed #info-toggle {
  left: -28px;
}
#info.collapsed #info-toggle::before { content: '¾F'; }
#info-toggle::before { content: '¾E'; }
/* hide the arrow char in the button element itself, use ::before */
#info-toggle { font-size: 0; }
#info-toggle::before { font-size: .8rem; }

/* ── Info body ── */
#info-body {
  padding: 16px 14px;
  overflow-y: auto;
  max-height: calc(100vh - var(--nav-h) - var(--desc-h) - 80px);
  scrollbar-width: none;
}
#info-body::-webkit-scrollbar { display: none; }
#info.collapsed #info-body { display: none; }

#i-type {
  font-family: 'Cinzel', serif;
  font-size: .6rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
#i-cluster {
  font-family: 'Cinzel', serif;
  font-size: .58rem;
  letter-spacing: .1em;
  color: rgba(220,232,252,.65);
  margin-bottom: 9px;
}
#i-name {
  font-family: 'Cinzel', serif;
  font-size: .94rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 10px;
}
#i-desc {
  font-size: .88rem;
  line-height: 1.72;
  font-style: italic;
  color: rgba(220,235,255,.88);
}
#i-rel {
  margin-top: 11px;
  font-size: .76rem;
  opacity: .72;
  font-family: 'Cinzel', serif;
  letter-spacing: .04em;
  line-height: 1.5;
}

/* ── Legend ── */
#legend {
  position: absolute;
  bottom: 16px; left: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
}
.leg {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Cinzel', serif;
  font-size: .68rem;
  letter-spacing: .07em;
  opacity: .80;
}
.ldot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Hint ── */
#hint {
  position: absolute;
  bottom: 16px; right: 16px;
  font-size: .7rem;
  font-style: italic;
  opacity: .40;
  z-index: 20;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════
   PER-VIEW ACCENT COLOURS (set via data-view on #app)
══════════════════════════════════════════════════════════ */
#app[data-view="classical"] {
  --accent: #f5a623;
}
#app[data-view="modern"] {
  --accent: #3b9eff;
}
#app[data-view="bridge"] {
  --accent: #c66aff;
}
#app[data-view="rochdale"] {
  --accent: #c8392a;
}
#app[data-view="culture"] {
  --accent: #d4922a;
}
#app[data-view="gender"] {
  --accent: #c44dff;
}
#app[data-view="nation"] {
  --accent: #2196f3;
}

/* ══════════════════════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(200,214,232,.2); border-radius: 2px; }

/* ══════════════════════════════════════════════════════════
   MOBILE  ( ≤ 640px )
══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* ── Intro ── */
  #intro-inner {
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
  }

  #intro-eyebrow {
    font-size: .62rem;
    letter-spacing: .2em;
    margin-bottom: 10px;
  }

  .t-line   { font-size: clamp(2rem, 12vw, 3rem); }
  .t-line--2 { font-size: clamp(1.3rem, 8vw, 2rem); letter-spacing: .18em; }

  #intro-title { margin-bottom: 14px; }

  #intro-sub {
    font-size: .88rem;
    margin-bottom: 20px;
  }

  /* Cards stack vertically, full width */
  #intro-cards {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 18px;
  }

  .icard {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }

  .icard-num  { font-size: .8rem; flex-shrink: 0; width: 20px; }
  .icard-name { font-size: .85rem; }
  .icard-desc { display: none; }   /* too cramped on phone */
  .icard-nodes { margin-top: 0; font-size: .6rem; white-space: nowrap; }

  #intro-hint { font-size: .65rem; }

  /* ── Nav ── */
  :root {
    --nav-h:   48px;
    --desc-h:  0px;   /* hide desc strip on mobile — too small to read */
  }

  #nav {
    padding: 0 12px;
    gap: 8px;
  }

  #nav-subtitle { display: none; }

  #nav-title { font-size: .72rem; letter-spacing: .06em; }

  /* Tabs: show only the roman numeral, hide text label */
  #nav-tabs {
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #nav-tabs::-webkit-scrollbar { display: none; }

  .tab {
    padding: 6px 10px 4px;
    font-size: .62rem;
    letter-spacing: .06em;
    flex-shrink: 0;
  }

  /* Hide the text after the roman numeral on very small screens */
  .tab-label { display: none; }
  .tab-num   { font-size: .72rem; opacity: 1; margin-right: 0; }

  /* ── View desc strip — hidden on mobile ── */
  #view-desc { display: none; }

  /* ── Info panel — bottom sheet on mobile ── */
  #info {
    /* Override desktop right-side positioning */
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100% !important;
    max-height: 52vh;
    border-left: none;
    border-top: 3px solid var(--accent);
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
    transition: transform .35s ease, opacity .35s ease, border-top-color .3s ease;
    opacity: 1 !important;
    pointer-events: none;
  }

  #info.show {
    transform: translateY(0);
    pointer-events: all;
  }

  /* Toggle becomes a drag handle / close button at top of sheet */
  #info-toggle {
    position: relative;
    top: auto; left: auto;
    width: 100%;
    height: 28px;
    border-radius: 12px 12px 0 0;
    border: none;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.04);
  }

  /* Draw a pill drag handle instead of arrow */
  #info-toggle::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(220,232,252,.3);
    border-radius: 2px;
    margin: 0 auto;
    font-size: 0;
  }

  #info.collapsed {
    transform: translateY(100%);
    width: 100% !important;
    border-width: 0;
  }

  #info-body {
    padding: 12px 16px 20px;
    max-height: calc(52vh - 28px);
  }

  /* ── Legend — horizontal strip above bottom sheet ── */
  #legend {
    bottom: auto;
    top: calc(var(--nav-h) + 10px);
    left: 12px;
    flex-direction: row;
    gap: 12px;
    background: rgba(4,6,14,.7);
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
  }

  .leg { font-size: .6rem; gap: 5px; }
  .leg span { display: none; }   /* just show the coloured dots */
  .ldot { width: 8px; height: 8px; }

  /* ── Hint — hide on mobile, touch is self-evident ── */
  #hint { display: none; }

}

/* ══════════════════════════════════════════════════════════
   TABLET  ( 641px – 900px )
══════════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 900px) {

  .t-line    { font-size: clamp(2rem, 7vw, 3.5rem); }
  .t-line--2 { font-size: clamp(1.4rem, 5vw, 2.5rem); }

  #intro-cards {
    flex-wrap: wrap;
    justify-content: center;
  }

  .icard {
    width: clamp(180px, 40vw, 260px);
  }

  .tab { font-size: .62rem; padding: 6px 10px 4px; }

  #info {
    width: clamp(220px, 34vw, 280px);
  }

}
