/*
 * NSG.VC Letter Page Styles
 * Three-mode color system: Greedy Green, Ronin Red, Beached Blue
 */

/* === Font Loading === */
@font-face {
  font-family: 'Courier Prime';
  src: url("/fonts/Courier_Prime,IBM_Plex_Mono,IBM_Plex_Sans,Noto_Sans_JP,Noto_Serif/Courier_Prime/CourierPrime-Regular.ttf") format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* === Color Mode Variables === */
:root {
  --greedy-green: rgb(43, 155, 82);
  --ronin-red: rgb(188, 0, 45);
  --beached-blue: rgb(0, 111, 205);
}

/* === Dynamic Background by Mode === */
html {
  background: var(--greedy-green);
  width: 100%;
  overflow-x: hidden;
}

html.mode-green {
  background: var(--greedy-green);
}

html.mode-red {
  background: var(--ronin-red);
}

html.mode-blue {
  background: var(--beached-blue);
}

/* === Top Gradient Fade === */
html::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 8rem;
  pointer-events: none;
  z-index: 10;
  background: linear-gradient(to bottom, var(--greedy-green), transparent);
}

html.mode-green::before {
  background: linear-gradient(to bottom, var(--greedy-green), transparent);
}

html.mode-red::before {
  background: linear-gradient(to bottom, var(--ronin-red), transparent);
}

html.mode-blue::before {
  background: linear-gradient(to bottom, var(--beached-blue), transparent);
}

/* === Body - Proportional Container === */
body {
  /* Proportional width using ch units - maintains constant character count */
  max-width: 65ch;
  width: min(65ch, 100vw);
  min-width: min(20rem, 100vw);
  margin: 0 auto;
  box-sizing: border-box;
  overflow-x: hidden;

  /* Fluid spacing: scales from mobile (375px) to desktop (1440px+) */
  padding: clamp(4rem, 3rem + 5vw, 8rem)
           clamp(2rem, 1.5rem + 1vw, 2rem)
           1rem
           clamp(2rem, 1.5rem + 1vw, 2rem);

  /* Fluid typography: scaled down 10% */
  font-size: clamp(1.125rem, 0.675rem + 1.08vw, 1.575rem);
  line-height: 1.8;

  /* Typography */
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-weight: 400;

  /* White text on colored background */
  background: inherit;
  color: rgb(255, 255, 255);

  /* Fade in on page load */
  opacity: 0;
  transition: opacity 0.6s ease-out;
}

body.loaded {
  opacity: 1;
}


/* === Typography === */
p, strong, footer, h1 {
  color: rgb(255, 255, 255);
}

/* Header */
h1 {
  font-size: 1.15em;
  font-weight: 700;
  margin: 0 0 clamp(1.5rem, 1.2rem + 1vw, 2.5rem) 0;
  line-height: 1.6;
}

/* Fluid paragraph spacing */
p {
  margin: 0 0 clamp(1.5rem, 1.2rem + 1vw, 2.5rem) 0;
}

/* Prevent text selection on interactive paragraphs (mobile long press) */
p[data-controller~="sforzando"] {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

p:last-child {
  margin-bottom: 0;
}

/* Bold emphasis */
strong {
  font-weight: 700;
}

/* Italic emphasis */
em {
  font-style: italic;
  font-weight: 400;
}

/* Japanese design element - city names */
.city {
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* === Spacing - Ma (間) principle === */
section {
  margin-bottom: clamp(1.5rem, 1.2rem + 1vw, 2.5rem);
}

/* === Footer === */
footer {
  margin-top: clamp(3rem, 2.5rem + 2vw, 5rem);
  margin-bottom: clamp(3rem, 2.5rem + 2vw, 5rem);
}

.signature {
  display: block;
  height: 50px;
  width: auto;
  margin-bottom: 1rem;
}

footer .email {
  opacity: 0.6;
  font-size: 0.9em;
}

.email-link {
  opacity: 0.6;
  color: rgb(255, 255, 255);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.email-link:hover {
  opacity: 1;
  text-decoration: underline;
}

footer em {
  opacity: 0.6;
  font-style: normal;
}

.kanji-link {
  color: inherit;
  text-decoration: none;
  cursor: default;
  transition: opacity 0.2s ease;
}

.kanji-link:hover {
  cursor: pointer;
  opacity: 1;
}

/* === Voice Elements === */
.voice {
  cursor: inherit;
  position: relative;
  display: inline;
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.05),
    0 0 4px rgba(255, 255, 255, 0.03);
  transition: text-shadow 0.3s ease-out;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  /* Fix Safari text-shadow rendering - force hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.voice.vibrato {
  color: rgb(255, 255, 255);
  text-shadow:
    0 0 5px rgba(255, 255, 255, 0.8),
    0 0 10px rgba(255, 255, 255, 0.6),
    0 0 15px rgba(255, 255, 255, 0.5),
    0 0 20px rgba(255, 255, 255, 0.4);
  animation: subtle-pulse 2s ease-in-out infinite;
  transition: text-shadow 0.3s ease-out;
}

@keyframes subtle-pulse {
  0%, 100% {
    text-shadow:
      0 0 5px rgba(255, 255, 255, 0.8),
      0 0 10px rgba(255, 255, 255, 0.6),
      0 0 15px rgba(255, 255, 255, 0.5),
      0 0 20px rgba(255, 255, 255, 0.4);
  }
  50% {
    text-shadow:
      0 0 8px rgba(255, 255, 255, 1),
      0 0 15px rgba(255, 255, 255, 0.8),
      0 0 22px rgba(255, 255, 255, 0.6),
      0 0 28px rgba(255, 255, 255, 0.5);
  }
}

/* Mobile Safari glow boost - compensate for weaker text-shadow rendering */
@media (max-width: 768px) {
  .voice.vibrato {
    /* Moderate constant glow - subtle pulse */
    text-shadow:
      0 0 4px rgba(255, 255, 255, 1),
      0 0 8px rgba(255, 255, 255, 0.9),
      0 0 12px rgba(255, 255, 255, 0.8),
      0 0 18px rgba(255, 255, 255, 0.7),
      0 0 25px rgba(255, 255, 255, 0.5);
    /* Force Safari to render with GPU */
    will-change: text-shadow;
  }

  @keyframes subtle-pulse {
    0%, 100% {
      text-shadow:
        0 0 4px rgba(255, 255, 255, 1),
        0 0 8px rgba(255, 255, 255, 0.9),
        0 0 12px rgba(255, 255, 255, 0.8),
        0 0 18px rgba(255, 255, 255, 0.7),
        0 0 25px rgba(255, 255, 255, 0.5);
    }
    50% {
      text-shadow:
        0 0 6px rgba(255, 255, 255, 1),
        0 0 12px rgba(255, 255, 255, 0.95),
        0 0 18px rgba(255, 255, 255, 0.85),
        0 0 24px rgba(255, 255, 255, 0.75),
        0 0 30px rgba(255, 255, 255, 0.6);
    }
  }
}

/* === Logo === */
.logo {
  display: block;
  width: auto;
  transition: opacity 0.3s ease;
}

.prologue-main {
  margin-bottom: clamp(2rem, 2rem + 2vw, 4rem);
  margin-left: 0;
  margin-right: auto;
  opacity: 1;
}

.prologue-main.hidden {
  opacity: 0;
}

.logo-pinned {
  position: fixed;
  top: 2rem;
  left: clamp(2rem, 1.5rem + 1vw, 2rem);
  height: 40px;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
}

.logo-pinned.visible {
  opacity: 1;
  pointer-events: auto;
}

.logo-pinned-victory {
  display: none;
}

.logo-pinned-victory.visible.vibrato {
  display: block;
  animation: glow-pulse 2s ease-in-out infinite;
}

/* Red mode: glitch instead of glow */
.mode-red .logo-pinned-victory.visible.vibrato,
.mode-red .prologue-nsg.vibrato {
  animation: logo-glitch 2s ease-in-out infinite;
}

/* Blue mode: static instead of glow */
.mode-blue .logo-pinned-victory.visible.vibrato,
.mode-blue .prologue-nsg.vibrato {
  animation: logo-static-filter 0.2s steps(4) infinite !important;
}

/* === Prologue === */
.prologue-container {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  height: clamp(60px, 12vw, 100px);
  overflow: visible;
  padding-left: 40px;
  margin-left: -40px;
}

@media (max-width: 768px) {
  .prologue-container {
    margin-top: 2rem;
    margin-bottom: 3rem;
  }
}

.prologue-nsg,
.prologue-bump,
.prologue-ts {
  height: 100%;
  width: auto;
  display: block;
  position: relative;
}

.prologue-nsg {
  cursor: default;
  transition: filter 0.3s ease;
}

.prologue-nsg.ready {
  cursor: pointer;
}

.prologue-nsg.ready:hover {
  filter: brightness(1.1);
}

.prologue-nsg.vibrato {
  animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6))
            drop-shadow(0 0 12px rgba(255, 255, 255, 0.4));
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8))
            drop-shadow(0 0 18px rgba(255, 255, 255, 0.6));
  }
}

.prologue-bump {
  transform-origin: center;
}

.prologue-ts {
  transform-origin: left center;
}

/* === Cadenza === */
.cadenza {
  display: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: rgb(255, 255, 255);
  text-align: center;
  margin-top: 3rem;
  padding-bottom: 0.5rem;
}

.cadenza em {
  font-style: normal;
  opacity: 1;
}

.cadenza.pronounced {
  display: block;
  opacity: 1;
  pointer-events: auto;
  animation: glow-pulse 2s ease-in-out infinite;
}

.cadenza:hover {
  filter: brightness(1.2);
}

/* === Privacy Footer === */
.privacy-footer {
  text-align: left;
  margin-top: clamp(4rem, 3rem + 3vw, 6rem);
  padding-bottom: clamp(3rem, 2rem + 2vw, 4rem);
}

.privacy-footer a {
  color: rgb(255, 255, 255);
  opacity: 0.4;
  font-size: 0.75em;
  text-decoration: none;
  font-style: normal;
  transition: opacity 0.2s ease;
}

.privacy-footer a:hover {
  opacity: 0.7;
}

/* === Dev Mode Switcher === */
.dev-mode-switcher {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.8);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  display: flex;
  gap: 0.75rem;
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 0.75rem;
  z-index: 1000;
}

.dev-mode-switcher .debug-label {
  opacity: 0.5;
}

.dev-mode-switcher #current-mode {
  opacity: 0.7;
  margin-left: 0.5rem;
}

.dev-mode-switcher a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.dev-mode-switcher a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 1);
}

.dev-mode-switcher a.active {
  color: rgba(255, 255, 255, 1);
  background: rgba(255, 255, 255, 0.2);
  font-weight: bold;
}

/* === Red Mode: Glitch Effects === */

/* Prevent text selection on red mode sections */
html.mode-red section p {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Glitch trigger styling */
.effect-trigger {
  position: relative;
  transition: all 0.1s ease;
}

/* Hover state - same intensity as first click */
.effect-trigger.glitch-hover {
  animation: glitch-1 0.3s ease-out;
  text-shadow:
    3px 0 0 var(--greedy-green),
    -3px 0 0 var(--beached-blue);
}

/* Progressive glitch states */
.effect-trigger.glitch-1 {
  animation: glitch-1 0.3s ease-out;
  text-shadow:
    3px 0 0 var(--greedy-green),
    -3px 0 0 var(--beached-blue);
}

.effect-trigger.glitch-2 {
  animation: glitch-2 0.3s ease-out;
  text-shadow:
    5px 0 0 var(--greedy-green),
    -5px 0 0 var(--beached-blue);
}

.effect-trigger.glitch-3 {
  animation: glitch-3 0.5s ease-out;
  text-shadow:
    8px 0 0 var(--greedy-green),
    -8px 0 0 var(--beached-blue);
}

@keyframes glitch-1 {
  0%, 100% { transform: translate(0); }
  25% { transform: translate(2px, 0); }
  50% { transform: translate(-2px, 0); }
  75% { transform: translate(2px, 0); }
}

@keyframes glitch-2 {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(3px, 1px); }
  40% { transform: translate(-3px, -1px); }
  60% { transform: translate(3px, 1px); }
  80% { transform: translate(-3px, -1px); }
}

@keyframes glitch-3 {
  0%, 100% { transform: translate(0); }
  10% { transform: translate(5px, 2px); }
  20% { transform: translate(-5px, -2px); }
  30% { transform: translate(4px, -1px); }
  40% { transform: translate(-4px, 1px); }
  50% { transform: translate(5px, -2px); }
  60% { transform: translate(-5px, 2px); }
  70% { transform: translate(4px, 1px); }
  80% { transform: translate(-4px, -1px); }
  90% { transform: translate(3px, 2px); }
}

@keyframes logo-glitch {
  0%, 100% {
    filter: drop-shadow(2px 4px 0 rgba(43, 155, 82, 0.9))
            drop-shadow(-2px -4px 0 rgba(0, 111, 205, 0.9));
  }
  50% {
    filter: drop-shadow(3px 5px 0 rgba(43, 155, 82, 1))
            drop-shadow(-3px -5px 0 rgba(0, 111, 205, 1));
    transform: translate(1px, 0);
  }
}

@keyframes logo-static-filter {
  0% {
    filter: contrast(1.5) brightness(1) grayscale(0.1);
    opacity: 0.97;
  }
  10% {
    filter: contrast(1.3) brightness(0.95) grayscale(0.15);
    opacity: 0.93;
  }
  20% {
    filter: contrast(1.6) brightness(1.05) grayscale(0.08);
    opacity: 0.98;
  }
  30% {
    filter: contrast(1.4) brightness(0.9) grayscale(0.12);
    opacity: 0.91;
  }
  40% {
    filter: contrast(1.55) brightness(1.02) grayscale(0.06);
    opacity: 0.96;
  }
  50% {
    filter: contrast(1.35) brightness(0.92) grayscale(0.14);
    opacity: 0.94;
  }
  60% {
    filter: contrast(1.5) brightness(1) grayscale(0.1);
    opacity: 0.97;
  }
  70% {
    filter: contrast(1.45) brightness(0.88) grayscale(0.16);
    opacity: 0.9;
  }
  80% {
    filter: contrast(1.6) brightness(1.03) grayscale(0.07);
    opacity: 0.99;
  }
  90% {
    filter: contrast(1.4) brightness(0.93) grayscale(0.13);
    opacity: 0.92;
  }
}

/* === Red Mode: Terminal/Response Area === */

.response-area {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

.response-area.visible {
  opacity: 1;
  transform: translateY(0);
}

.response-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 1.1rem;
}

.prompt-symbol {
  color: rgba(255, 255, 255, 0.9);
  font-weight: bold;
  user-select: none;
  text-shadow:
    1px 2px 0 var(--greedy-green),
    -1px -2px 0 var(--beached-blue);
  animation: prompt-glitch 3s ease-in-out infinite;
}

@keyframes prompt-glitch {
  0%, 90%, 100% {
    text-shadow:
      1px 2px 0 var(--greedy-green),
      -1px -2px 0 var(--beached-blue);
  }
  92%, 94%, 96% {
    text-shadow:
      2px 4px 0 var(--greedy-green),
      -2px -4px 0 var(--beached-blue);
    transform: translate(1px, 0);
  }
  93%, 95% {
    text-shadow:
      2px 4px 0 var(--greedy-green),
      -2px -4px 0 var(--beached-blue);
    transform: translate(-1px, 0);
  }
}

.response-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: rgba(255, 255, 255, 0.95);
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: clamp(1.125rem, 0.675rem + 1.08vw, 1.575rem);
  line-height: 1.8;
  padding: 0;
  caret-color: rgba(255, 255, 255, 0.9);
  text-shadow:
    3px 0 0 var(--greedy-green),
    -3px 0 0 var(--beached-blue);
}

.response-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.response-input:disabled {
  opacity: 0.7;
}

/* Shake animation for wrong input */
.response-area.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* === Red Mode: Cipher Letters (Marked Glyphs) === */

.marked {
  position: relative;
  display: inline-block;
  transition: text-shadow 0.1s ease;
}

/* Before terminal unlocked - completely normal */
.marked:not(.enabled) {
  /* No visual distinction */
}

/* After terminal unlocked - strong RGB glitch on hover/flicker (like vibrato on green) */
.marked.enabled.glitched {
  text-shadow:
    2px 4px 0 var(--greedy-green),
    -2px -4px 0 var(--beached-blue);
}

/* Clicked/held state - sustained glitch (like sostenuto on green) */
.marked.enabled.sustained {
  text-shadow:
    2px 4px 0 var(--greedy-green),
    -2px -4px 0 var(--beached-blue);
}

/* Mobile: Touch feedback - slightly stronger */
@media (hover: none) {
  .marked.enabled.glitched,
  .marked.enabled.sustained {
    text-shadow:
      3px 5px 0 var(--greedy-green),
      -3px -5px 0 var(--beached-blue);
  }
}

