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

:root {
  --bg: #000000;
  --surface: #000000;
  --border: #ffffff;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.5);
  --jack-hole: #000000;
  --font-sans: 'DM Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
  --radius: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#portfolio {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 2;
  pointer-events: none;
}

/* ── Social bar ── */

#social-bar {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border: 2px solid var(--border);
  box-shadow: 3px 3px 0 var(--border);
}

#social-bar a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 34px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.1s;
}

#social-bar a + a {
  border-left: 1px solid var(--border);
}

#social-bar a:hover {
  color: var(--text);
}

#social-bar a[href="about.html"] {
  color: black;
  background: red;
}

#social-bar a[href="about.html"]:hover {
  color: black;
  background: white;
}

#social-bar svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* ── Portfolio ── */

.portfolio {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 3px;
  background: var(--bg);
}

.portfolio--active {
  background: var(--bg);
}

.project-card {
  position: relative;
  overflow: hidden;
  opacity: 0;
  animation: project-in 0.3s steps(4) forwards;
  border: 2px solid var(--border);
}

.project-card--clickable {
  cursor: pointer;
}


.project-card--solo {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
}

.project-card__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(100%) contrast(1.1);
  transform: scale(1);
  transition: transform 0.1s ease;
  opacity: 0.3;
}

.project-card--clickable:hover .project-card__image {
  transform: scale(1.02);
  filter: grayscale(0%) contrast(1.1);
  opacity: 1;
}

.project-card__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(16px, 3vw, 32px);
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(0, 0, 0, 0.4) 50%,
    transparent 100%
  );
  pointer-events: none;
}

.project-card__index {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.project-card__title {
  font-family: var(--font-sans);
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 8px;
}

.project-card__desc {
  font-size: clamp(10px, 1.3vw, 12px);
  line-height: 1.5;
  color: var(--muted);
  max-width: 480px;
}

@media (max-width: 640px) {
  .cable-panel__label,
  .jack-panel__label,
  .jack-hole__index {
    display: none;
  }

  .intro-card, .project-card, .project-detail, .project-detail__hero, .project-detail__hero-overlay {
    border: none !important;
  }

  .intro-card__content,
  .project-card__overlay,
  .project-detail__hero-overlay,
  .project-detail__body {
    padding-left: 52px !important;
    padding-right: 52px !important;
  }
  


  /* Cable panel: contenitore invisibile, 1px al bordo esatto */
  .cable-panel,
  body.portfolio-active .cable-panel {
    left: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    border-color: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  /* Slot invisibile, 1px di larghezza — solo segnaposto per _measure() */
  .cable-slot {
    width: 1px;
    height: 14px;
    padding: 0;
    overflow: visible;
  }

  .cable-slot + .cable-slot {
    border-top: none;
  }

  /* Anchor invisibile — solo punto di misura per il cavo */
  .cable-anchor {
    width: 1px !important;
    height: 1px !important;
    background: transparent !important;
  }

  /* Jack panel: invisibile, attaccato al bordo destro */
  .jack-panel,
  body.portfolio-active .jack-panel {
    right: 0 !important;
    left: auto !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    border-color: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  .jack-row {
    gap: 0;
  }

  /* Jack hole: solo il quadratino visibile, spinto al bordo destro */
  .jack-hole {
    width: 10px;
    height: 14px;
    justify-content: flex-end;
  }

  .jack-hole__outer {
    width: 8px;
    height: 8px;
    border-width: 1px;
  }

  .jack-hole__inner {
    display: none;
  }

  .plug-tip {
    width: 10px;
    height: 10px;
  }

  .plug-tip .plug-shaft {
    width: 6px;
    height: 3px;
  }
}

@keyframes project-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

body.portfolio-active .cable-panel,
body.portfolio-active .jack-panel {
  background: var(--bg);
  border-color: var(--border);
}

body.portfolio-active .patch-hint {
  color: var(--muted);
}

.patch-stage {
  width: 100%;
  height: 100%;
  position: relative;
}

.patch-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.patch-svg .cable-path {
  fill: none;
  stroke-linecap: square;
  stroke-linejoin: miter;
  pointer-events: stroke;
  cursor: grab;
}

.patch-svg .cable-path.dragging {
  cursor: grabbing;
}

.patch-ui {
  position: relative;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.patch-ui > * {
  pointer-events: auto;
}

/* ── OUT — left ── */

.cable-panel {
  position: absolute;
  left: clamp(8px, 1.5vw, 20px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 12px 10px;
  box-shadow: 4px 4px 0 var(--border);
}

.cable-panel__label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  text-align: center;
}

.cable-panel__slots {
  display: flex;
  flex-direction: column;
}

.cable-slot {
  position: relative;
  width: 52px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 2px;
}

.cable-slot + .cable-slot {
  border-top: 1px solid var(--border);
}

.cable-anchor {
  width: 8px;
  height: 8px;
  background: var(--text);
  flex-shrink: 0;
}

/* ── IN — right ── */

.jack-panel {
  position: absolute;
  right: clamp(8px, 1.5vw, 20px);
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 12px 10px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: -4px 4px 0 var(--border);
}

.jack-panel__label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.jack-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.jack-hole {
  position: relative;
  width: 40px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.jack-hole__outer {
  width: 22px;
  height: 22px;
  background: var(--jack-hole);
  border: 2px solid var(--border);
  transition: outline 0.1s;
}

.jack-hole__outer.highlight {
  outline: 2px solid var(--border);
  outline-offset: 2px;
}

.jack-hole__inner {
  position: absolute;
  left: 7px;
  width: 8px;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.jack-hole__index {
  position: absolute;
  right: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ── Plug tip ── */

.plug-tip {
  position: absolute;
  width: 14px;
  height: 14px;
  z-index: 6;
  cursor: grab;
  transform: translate(-50%, -50%);
  touch-action: none;
  pointer-events: auto;
}

.plug-tip::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #ffffff;
  border: 1px solid var(--bg);
}

.plug-tip::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  background: var(--bg);
  transform: translate(-50%, -50%);
}

.plug-tip.dragging {
  cursor: grabbing;
  z-index: 20;
}

.plug-tip.dragging::before {
  background: #ffffff;
  outline: 1px solid var(--bg);
}

.plug-tip.inserted::before {
  background: #ffffff;
}

.plug-tip .plug-shaft {
  position: absolute;
  top: 50%;
  right: 100%;
  width: 10px;
  height: 4px;
  background: #ffffff;
  transform: translateY(-50%);
  margin-right: -1px;
}

/* ── Hint ── */

.patch-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.8;
  text-align: center;
  color: var(--muted);
  z-index: 0;
  pointer-events: none;
  animation: hint-blink 2s ease-in-out infinite;
}

@keyframes hint-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Intro ── */

.intro-card {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 2px solid var(--border);
  opacity: 0;
  animation: project-in 0.3s steps(4) forwards;
}

.intro-card__content {
  text-align: center;
  padding: clamp(24px, 5vw, 48px);
  max-width: 720px;
}

.intro-card__line {
  font-family: var(--font-sans);
  font-size: clamp(18px, 3.2vw, 28px);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: -0.02em;
  color: var(--text);
}

.intro-card__line + .intro-card__line {
  margin-top: 0.35em;
}

.intro-card__subtitle {
  font-family: var(--font-mono);
  font-size: clamp(10px, 1.1vw, 12px);
  line-height: 1.6;
  color: var(--muted);
  margin-top: clamp(28px, 4vw, 44px);
  letter-spacing: 0.06em;
}

/* ── Project detail ── */

.portfolio--detail {
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

body.project-detail-active {
  user-select: auto;
  -webkit-user-select: auto;
}

.project-detail__hero {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  border-bottom: 2px solid var(--border);
}

.project-detail__hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.project-detail__hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(20px, 4vw, 48px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, transparent 60%);
  pointer-events: none;
  border: 2px solid var(--border);
  border-top: none;
}

.project-detail__index {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.project-detail__title {
  font-family: var(--font-sans);
  font-size: clamp(22px, 4vw, 36px);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 12px;
}

.project-detail__tagline {
  font-size: clamp(11px, 1.5vw, 13px);
  line-height: 1.6;
  color: var(--muted);
  max-width: 520px;
}

.project-detail__scroll-hint {
  position: absolute;
  bottom: clamp(20px, 4vw, 40px);
  right: clamp(20px, 4vw, 48px);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  animation: scroll-pulse 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes scroll-pulse {
  0%, 100% { opacity: 1; transform: translateY(0); }
  50% { opacity: 0.4; transform: translateY(4px); }
}

.project-detail__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  padding: clamp(40px, 8vw, 96px) clamp(24px, 6vw, 80px);
  min-height: 50vh;
  border-top: 2px solid var(--border);
  user-select: text;
  -webkit-user-select: text;
}

.project-detail__date {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 24px;
}

.project-detail__text {
  font-size: clamp(12px, 1.6vw, 14px);
  line-height: 1.8;
  color: var(--muted);
  max-width: 640px;
  width: 100%;
  margin: 0 auto clamp(24px, 4vw, 40px);
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

.project-detail__text a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.project-detail__tech {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto clamp(32px, 6vw, 64px);
  padding: 0;
}

.project-detail__tech li {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.project-detail__extras {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  width: 100%;
  max-width: 960px;
}

.project-detail__extra-img {
  flex: 1 1 260px;
  max-width: 480px;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
  border: 2px solid var(--border);
}
