/* The Vitruvian Man — exhibition styling.
   Period-appropriate restraint: parchment tones, hairline gold rules,
   EB Garamond for modern text, IM Fell for Leonardo's voice. */

@font-face {
  font-family: 'EB Garamond';
  src: url('../assets/fonts/eb-garamond.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../assets/fonts/eb-garamond-italic.woff2') format('woff2');
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('../assets/fonts/im-fell-english-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: block;
}

:root {
  --ink: #2e2014;
  --parchment: #d5bf94;
  --cream: #efe3c8;
  --gold: #b08d57;
  --gold-dim: rgba(176, 141, 87, .55);
  --glass: rgba(24, 16, 9, .78);
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120b06;
  color: var(--cream);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
}
#stage canvas { display: block; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
body.notes-on #stage canvas { cursor: pointer; }

/* ---------------------------------------------------------------- veil */
#veil {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background:
    radial-gradient(120% 90% at 50% 40%, #2a1d10 0%, #171008 58%, #0d0804 100%);
  transition: opacity .85s ease, visibility .85s;
}
#veil.gone { opacity: 0; visibility: hidden; pointer-events: none; }
#veilText {
  margin: 0;
  font-style: italic;
  letter-spacing: .04em;
  color: rgba(239, 227, 200, .82);
}
.veil-ring {
  width: 96px;
  height: 96px;
  animation: ring-spin 14s linear infinite;
}
.veil-ring circle, .veil-ring path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.6;
  transform-origin: center;
}
.ring-square { stroke-dasharray: 40 12; opacity: .75; }
.ring-circle { stroke-width: 2; opacity: .95; }
.ring-figure { stroke-width: 1.3; opacity: .6; }
@keyframes ring-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .veil-ring { animation: none; }
}

/* ------------------------------------------------------------- fallback */
#fallback {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  max-width: 30rem;
  margin: auto;
}
#fallback[hidden] { display: none; }
#fallback h1 { font-size: 1.5rem; margin: 0; color: var(--cream); }
#fallback p { color: rgba(239, 227, 200, .8); line-height: 1.55; }

/* --------------------------------------------------------------- plaque */
#plaque {
  position: fixed;
  top: 26px;
  left: 30px;
  z-index: 20;
  pointer-events: none;
  user-select: none;
}
.plaque-kicker {
  margin: 0 0 6px;
  font-size: .72rem;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--gold);
}
#plaque h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  font-weight: 500;
  font-style: italic;
  letter-spacing: .01em;
  color: var(--cream);
  text-shadow: 0 1px 14px rgba(0, 0, 0, .55);
}
.plaque-sub {
  margin: 4px 0 0;
  font-size: .92rem;
  color: rgba(239, 227, 200, .68);
}

/* ------------------------------------------------------------- hint bar */
#hintbar {
  position: fixed;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%) translateY(8px);
  z-index: 20;
  margin: 0;
  padding: 9px 18px;
  font-size: .88rem;
  font-style: italic;
  letter-spacing: .03em;
  color: rgba(239, 227, 200, .92);
  background: var(--glass);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .8s ease, transform .8s ease, visibility .8s;
  pointer-events: none;
  white-space: nowrap;
}
#hintbar.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------- toast */
#toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  z-index: 40;
  margin: 0;
  padding: 8px 16px;
  font-size: .86rem;
  letter-spacing: .04em;
  background: var(--glass);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  opacity: 0;
  visibility: hidden;
  transition: all .35s ease;
  pointer-events: none;
}
#toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- control cluster */
#controlsbar {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px 10px;
  background: var(--glass);
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .45);
  max-width: min(94vw, 860px);
}
.ctl-group {
  display: flex;
  align-items: center;
  gap: 2px;
}
.seg button, .actions button {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(239, 227, 200, .82);
  font-family: var(--serif);
  font-size: .84rem;
  letter-spacing: .05em;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .25s ease, color .25s ease, border-color .25s;
  white-space: nowrap;
}
.seg button:hover, .actions button:hover {
  color: var(--cream);
  background: rgba(176, 141, 87, .14);
}
.seg button[aria-pressed="true"], #notesBtn[aria-pressed="true"] {
  color: #f4e9cd;
  background: rgba(176, 141, 87, .22);
  border-color: var(--gold-dim);
}
.actions { gap: 6px; }
#helpBtn {
  width: 34px;
  justify-content: center;
  font-size: .95rem;
}

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.explode { gap: 10px; padding: 0 8px; }
.explode-label {
  font-size: .74rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
}
#explodeRange {
  appearance: none;
  -webkit-appearance: none;
  width: 130px;
  height: 22px;
  background: transparent;
  cursor: ew-resize;
}
#explodeRange::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 2px;
}
#explodeRange::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--parchment);
  border: 1.5px solid var(--gold);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .5);
}
#explodeRange::-moz-range-track {
  height: 2px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
}
#explodeRange::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--parchment);
  border: 1.5px solid var(--gold);
}

/* -------------------------------------------------------- notes panel */
#notesPanel {
  position: fixed;
  top: 90px;
  right: 26px;
  z-index: 35;
  width: min(400px, calc(100vw - 40px));
  max-height: min(66vh, 560px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, rgba(31, 21, 12, .93), rgba(20, 13, 7, .95));
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  opacity: 0;
  visibility: hidden;
  transform: translateX(14px);
  transition: opacity .45s ease, transform .45s ease, visibility .45s, box-shadow .45s;
}
#notesPanel.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}
#notesPanel.flash { box-shadow: 0 0 0 2px var(--gold), 0 18px 50px rgba(0, 0, 0, .55); }
.notes-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.notes-head h2 {
  margin: 0;
  font-size: 1.06rem;
  font-style: italic;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--cream);
}
#notesClose {
  appearance: none;
  background: none;
  border: none;
  color: rgba(239, 227, 200, .6);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
}
#notesClose:hover { color: var(--cream); }
#notesTabs {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(176, 141, 87, .25);
}
#notesTabs button {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: rgba(239, 227, 200, .62);
  font-family: var(--serif);
  font-size: .8rem;
  letter-spacing: .04em;
  padding: 8px 8px 9px;
  cursor: pointer;
}
#notesTabs button[aria-selected="true"] {
  color: var(--cream);
  border-bottom-color: var(--gold);
}
#notesBody {
  padding: 14px 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#notesBody h3 {
  margin: 2px 0 10px;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold);
}
.note-italian {
  margin: 0 0 12px;
  font-family: 'IM Fell English', Georgia, serif;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.5;
  color: rgba(239, 227, 200, .78);
}
.note-english {
  margin: 0;
  font-size: 1rem;
  line-height: 1.62;
  color: var(--cream);
}
.note-foot {
  margin-top: 14px;
  font-size: .76rem;
  font-style: italic;
  line-height: 1.45;
  color: rgba(239, 227, 200, .5);
  border-top: 1px solid rgba(176, 141, 87, .22);
  padding-top: 10px;
}

/* ------------------------------------------------------------ help */
#helpOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 5, 2, .6);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility .35s;
}
#helpOverlay.open { opacity: 1; visibility: visible; }
.help-card {
  position: relative;
  width: min(560px, 94vw);
  max-height: 84vh;
  overflow-y: auto;
  padding: 28px 30px 22px;
  background: linear-gradient(165deg, #2a1c10, #1a1109);
  border: 1px solid var(--gold-dim);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  transform: translateY(10px) scale(.985);
  transition: transform .35s ease;
}
#helpOverlay.open .help-card { transform: none; }
.help-card h2 {
  margin: 0 0 12px;
  font-style: italic;
  font-weight: 500;
  font-size: 1.35rem;
}
.help-card > p {
  margin: 0 0 16px;
  font-size: .98rem;
  line-height: 1.6;
  color: rgba(239, 227, 200, .88);
}
.help-keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 16px;
  margin: 0 0 16px;
  font-size: .92rem;
}
.help-keys dt {
  color: var(--gold);
  letter-spacing: .04em;
}
.help-keys dd { margin: 0; color: rgba(239, 227, 200, .85); }
kbd {
  font-family: inherit;
  font-size: .84em;
  padding: 1px 6px;
  border: 1px solid var(--gold-dim);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(176, 141, 87, .12);
}
.help-card footer {
  font-size: .8rem;
  font-style: italic;
  color: rgba(239, 227, 200, .52);
  border-top: 1px solid rgba(176, 141, 87, .22);
  padding-top: 10px;
}
#helpClose {
  position: absolute;
  top: 14px;
  right: 16px;
  appearance: none;
  background: none;
  border: none;
  color: rgba(239, 227, 200, .6);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 6px;
}
#helpClose:hover { color: var(--cream); }

/* --------------------------------------------------------- responsive */
@media (max-width: 900px) {
  #controlsbar { flex-wrap: wrap; justify-content: center; row-gap: 4px; }
  #hintbar { white-space: normal; text-align: center; width: max-content; max-width: 86vw; }
}

@media (max-width: 640px) {
  #plaque { top: 16px; left: 18px; right: 90px; }
  .plaque-kicker { font-size: .62rem; letter-spacing: .24em; }
  .plaque-sub { font-size: .8rem; }

  #controlsbar {
    left: 10px;
    right: 10px;
    transform: none;
    justify-content: center;
    gap: 6px;
    padding: 6px;
    border-radius: 12px;
  }
  .seg button, .actions button { font-size: .8rem; padding: 9px 9px; }
  #explodeRange { width: 104px; }

  #notesPanel {
    top: auto;
    right: 10px;
    left: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 48vh;
    transform: translateY(14px);
  }
  #notesPanel.open { transform: none; }

  #hintbar { bottom: 132px; font-size: .8rem; padding: 8px 14px; }
}

@media (max-width: 380px) {
  .seg button, .actions button { font-size: .74rem; padding: 8px 7px; }
  .explode-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
