/* =============================================================================
   Alessandro Amadio — Masterplan Interattivo
   Contract with the JS: main.js toggles .is-open, .is-hidden and .is-current;
   map.js owns the map canvas, toggles .is-panning on .viewport and .is-visible on
   the floating label. The map has no CSS geometry any more — the plate, the grid
   and every lot are three.js objects.
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Space Mono', ui-monospace, 'SF Mono', monospace;

  /* Studio dark */
  --bg: #0b0f12;
  --bg-deep: #070a0d;
  --grid: #141a21;
  --panel: rgba(18, 24, 31, 0.88);
  --panel-solid: #12181f;

  --accent: #ff4500;
  --accent-soft: rgba(255, 69, 0, 0.16);

  --text: #f0f4f8;
  --text-muted: #8c9ba5;
  --text-dim: #5f6d78;

  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.05);

  /* Sheet (light surface) */
  --sheet-bg: #ffffff;
  --sheet-text: #10161c;
  --sheet-muted: #6b7883;
  --sheet-line: #e8ecef;

  --radius: 16px;
  --radius-lg: 24px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-panel: 0 20px 40px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 25px 60px rgba(0, 0, 0, 0.45);
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 500;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 0 0 10px 10px;
  text-decoration: none;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 0; }

.text-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.text-link:hover { border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- header --- */
.site-header {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: 30;
  width: 320px;
  padding: 18px 20px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.site-header h1 {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.site-header .role {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.menu-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px; height: 36px;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s;
}
.menu-toggle:hover { background: rgba(255, 255, 255, 0.08); }
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: width 0.3s var(--ease);
}
.menu-toggle span:first-child { width: 20px; }
.menu-toggle span:last-child  { width: 13px; }
.menu-toggle:hover span:last-child { width: 20px; }

/* ------------------------------------------------------------------- map --- */
.viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: grab;
  background: radial-gradient(circle at 50% 45%, #18222d 0%, #080b0f 72%);
  /* Only the map swallows gestures; the rest of the page stays pinch-zoomable. */
  touch-action: none;
}
.viewport.is-panning { cursor: grabbing; }
.viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.45) 100%);
}

/* The whole map: one canvas, sized by map.js through a ResizeObserver. */
.map-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Keyboard and screen-reader route to the lots. Off-screen rather than
   display:none, because hidden elements cannot take focus. */
.map-index {
  position: absolute;
  left: -9999px;
  top: 0;
  list-style: none;
}
.map-index button {
  font: inherit;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
/* Bring the focused entry on-screen, so sighted keyboard users can see where
   they are instead of chasing an invisible focus ring. */
.map-index:focus-within {
  left: 50%;
  top: auto;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 26;
  display: flex;
  gap: 8px;
}

/* Floating lot name. HTML, not a texture, so it stays crisp at any zoom;
   map.js projects the lot's anchor point and writes left/top. */
.map-label {
  position: fixed;
  z-index: 24;
  padding: 6px 11px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
  background: rgba(10, 14, 18, 0.9);
  border: 1px solid var(--line);
  border-radius: 6px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.map-label.is-visible { opacity: 1; }

/* --------------------------------------------------------- map overlay UI --- */
.map-ui { position: fixed; z-index: 25; }

.map-hint {
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 100px;
  pointer-events: none;
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.map-hint.is-hidden { opacity: 0; transform: translateX(-50%) translateY(8px); }

.zoom-controls {
  right: 24px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.zoom-controls button {
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  background: var(--panel-solid);
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.zoom-controls button:hover { background: #1b232c; color: var(--accent); }
.zoom-controls .zoom-reset { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.05em; }

/* ------------------------------------------------------------- side sheet --- */
.sheet {
  position: fixed;
  top: 20px; right: 20px; bottom: 20px;
  z-index: 100;
  width: min(450px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  background: var(--sheet-bg);
  color: var(--sheet-text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  /* Animating transform (not `right`) so it also slides on the mobile layout,
     where the original animated a property it never changed. */
  transform: translateX(calc(100% + 32px));
  visibility: hidden;
  transition: transform 0.5s var(--ease), visibility 0s linear 0.5s;
}
.sheet.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.5s var(--ease), visibility 0s;
}

.sheet-close {
  position: absolute;
  top: 16px; right: 16px;
  z-index: 10;
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--sheet-text);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.sheet-close:hover { background: #eef1f3; transform: scale(1.06); }

/* 3D viewer panel */
.viewer {
  position: relative;
  flex: 0 0 auto;
  height: 250px;
  background: radial-gradient(circle at 50% 40%, #ffffff 0%, #e9edf1 100%);
  border-bottom: 1px solid var(--sheet-line);
  touch-action: none; /* OrbitControls handles the gestures here */
}
.viewer-canvas { display: block; width: 100%; height: 100%; }

.viewer-label {
  position: absolute;
  bottom: 12px; left: 16px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sheet-muted);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 100px;
  pointer-events: none;
}

.viewer-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--sheet-muted);
  background: rgba(244, 246, 248, 0.92);
}
.viewer-status[hidden] { display: none; }
.viewer-status[data-state='error'] { color: #b3401a; }

.sheet-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.project-category {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
.project-title h2 {
  margin-top: 6px;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.metadata-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 18px 0;
  border-top: 1px solid var(--sheet-line);
  border-bottom: 1px solid var(--sheet-line);
}
.meta-item { display: flex; flex-direction: column; gap: 4px; }
.meta-item dt {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sheet-muted);
}
.meta-item dd { font-size: 0.875rem; font-weight: 600; }

.project-abstract h3 {
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sheet-muted);
}
.project-abstract p { font-size: 0.9rem; line-height: 1.65; color: #3d4750; }

/* ------------------------------------------------------------------ menu --- */
.full-menu {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(32px, 5vw, 60px) clamp(24px, 6vw, 80px);
  background: rgba(8, 11, 15, 0.97);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--ease), visibility 0s linear 0.4s;
}
.full-menu.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s var(--ease), visibility 0s;
}

.menu-close {
  position: absolute;
  top: 28px; right: 28px;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  line-height: 1;
  color: #fff;
  background: none;
  border: none;
  cursor: pointer;
  transition: transform 0.2s, color 0.2s;
}
.menu-close:hover { transform: scale(1.12); color: var(--accent); }

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: clamp(30px, 5vw, 60px);
  width: 100%;
  max-width: 1300px;
  margin-top: 40px;
}

.menu-nav { display: flex; flex-direction: column; gap: 18px; align-items: flex-start; }
.menu-nav button {
  font-family: var(--font-sans);
  font-size: clamp(1.15rem, 2.4vw, 1.8rem);
  font-weight: 300;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-align: left;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.3s, transform 0.3s var(--ease);
}
.menu-nav button:hover,
.menu-nav button.is-current { color: #fff; transform: translateX(10px); }

.menu-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 60vh;
  padding-left: 40px;
  border-left: 1px solid var(--line);
  color: #d0d6dc;
  overflow-y: auto;
}
.menu-content h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.menu-content p { font-size: 0.95rem; font-weight: 300; line-height: 1.65; }
.menu-content strong { color: #fff; font-weight: 500; }

.archive-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.archive-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.archive-item:last-child { border-bottom: none; }
.archive-item strong { color: #fff; font-weight: 500; }
.archive-place {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.archive-meta { font-size: 0.82rem; color: var(--text-muted); }

.menu-footer {
  padding-top: 36px;
  margin-top: 32px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* --------------------------------------------------------------- noscript --- */
.noscript-note {
  position: fixed;
  inset: auto 24px 24px 24px;
  z-index: 400;
  padding: 16px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------ responsive --- */
@media (max-width: 900px) {
  .menu-grid { grid-template-columns: 1fr; }
  .menu-content {
    padding-left: 0;
    padding-top: 20px;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 768px) {
  .site-header { top: 16px; left: 16px; right: 16px; width: auto; }

  .sheet {
    top: auto;
    left: 16px; right: 16px; bottom: 16px;
    width: auto;
    height: 76vh;
    transform: translateY(calc(100% + 24px));
  }
  .sheet.is-open { transform: translateY(0); }

  .viewer { height: 210px; }
  .zoom-controls { right: 16px; bottom: 96px; }
  .map-hint { bottom: 24px; font-size: 0.62rem; }
  .metadata-grid { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .sheet { transition: transform 0.01ms, visibility 0s; }
}
