/* ==========================================================================
   In die Stille des Herzens — Mystical Late-19th-Century Steampunk Styles
   Typography:
     - Gothic Script everywhere: 'UnifrakturMaguntia' & 'Grenze Gotisch'
     - Stamped Century Gothic ONLY on the 3D casket paper strip
   ========================================================================== */

:root {
  --font-gothic-display: 'UnifrakturMaguntia', 'Grenze Gotisch', Georgia, serif;
  --font-gothic-script: 'Grenze Gotisch', 'UnifrakturMaguntia', Georgia, serif;
  --font-slip-stamp: 'Century Gothic', 'Jost', 'Didact Gothic', Futura, sans-serif;

  --gold-bright: #f4d47c;
  --gold-warm: #d4a64a;
  --gold-antique: #9c7228;
  --ink-sepia: #261406;
  --ink-soft: #4e3015;
  --bg-deep: #120a05;

  --bg-blur: 2.8px;
  --bg-scale: 1.04;
  --bg-shift-x: 0px;
  --bg-shift-y: 0px;

  /* Live-projected 3D parchment bounds from Three.js */
  --sheet-left: 50%;
  --sheet-top: 50%;
  --sheet-width: 420px;
  --sheet-height: 540px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--gold-bright);
  font-family: var(--font-gothic-script);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ==========================================================================
   1. Cinematic Blurred 3D Steampunk Study Background (Always Visible)
   ========================================================================== */
.study-backdrop {
  position: fixed;
  inset: -40px;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 40%, #2d1b0e 0%, #140b05 70%, #090502 100%);
}

.study-backdrop__image {
  position: absolute;
  inset: 0;
  background-image: url('assets/study-backdrop.webp');
  background-size: cover;
  background-position: center 42%;
  background-repeat: no-repeat;
  filter: blur(var(--bg-blur)) brightness(0.76) saturate(1.12) contrast(1.04);
  transform: translate3d(var(--bg-shift-x), var(--bg-shift-y), 0) scale(var(--bg-scale));
  transition: filter 1.6s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, filter;
}

.room-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  filter: blur(var(--bg-blur)) brightness(1.08) saturate(1.14) contrast(1.04);
  transform: scale(1.03);
  transition: filter 1.6s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: filter;
}

.room-atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body.state-writing .study-backdrop__image,
body.state-form .study-backdrop__image,
body.state-writing .room-canvas,
body.state-form .room-canvas {
  --bg-blur: 8.5px;
}

body.state-folding .study-backdrop__image,
body.state-casket .study-backdrop__image,
body.state-done .study-backdrop__image,
body.state-folding .room-canvas,
body.state-casket .room-canvas,
body.state-done .room-canvas {
  --bg-blur: 6.5px;
}

.study-backdrop__vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 72% at 50% 44%, rgba(20, 10, 3, 0) 40%, rgba(10, 5, 2, 0.5) 100%),
    linear-gradient(180deg, rgba(14, 8, 4, 0.22) 0%, rgba(14, 8, 4, 0.0) 28%, rgba(14, 8, 4, 0.18) 100%);
}

.study-backdrop__warm-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 72% 36%, rgba(255, 198, 102, 0.14) 0%, rgba(255, 160, 64, 0) 52%);
  animation: candleBreath 5.5s ease-in-out infinite alternate;
}

@keyframes candleBreath {
  0%   { opacity: 0.7; transform: scale(1); }
  50%  { opacity: 1;   transform: scale(1.04); }
  100% { opacity: 0.8; transform: scale(0.98); }
}

/* ==========================================================================
   2. Real-Time 3D WebGL Canvas
   ========================================================================== */
.scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

body.cursor-pointer .scene-canvas {
  cursor: pointer;
}

/* ==========================================================================
   3. Interactive Quill Prompt Pill (IDLE state)
   ========================================================================== */
.floating-hint {
  position: fixed;
  bottom: clamp(18px, 4vh, 38px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid rgba(244, 212, 124, 0.42);
  background: radial-gradient(ellipse at 50% 0%, rgba(56, 34, 14, 0.82), rgba(20, 11, 5, 0.88));
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.65),
    0 0 20px rgba(244, 200, 102, 0.16),
    inset 0 1px 0 rgba(255, 240, 195, 0.24);
  color: var(--gold-bright);
  font-family: var(--font-gothic-script);
  font-size: clamp(1rem, 2.2vw, 1.24rem);
  letter-spacing: 0.04em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: opacity 0.8s ease, transform 0.6s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  animation: gentleFloat 3.4s ease-in-out infinite;
}

.floating-hint:hover,
.floating-hint:focus-visible {
  border-color: rgba(255, 232, 158, 0.88);
  box-shadow:
    0 10px 32px rgba(0, 0, 0, 0.72),
    0 0 28px rgba(255, 214, 118, 0.42),
    inset 0 1px 0 rgba(255, 244, 206, 0.45);
  outline: none;
}

body:not(.state-idle) #quill-hint {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
}

.floating-hint__sparkle {
  color: #ffe8a3;
  animation: sparklePulse 2s ease-in-out infinite;
}

@keyframes gentleFloat {
  0%, 100% { transform: translate(-50%, 0); }
  50%      { transform: translate(-50%, -6px); }
}

@keyframes sparklePulse {
  0%, 100% { opacity: 0.6; transform: scale(0.95); }
  50%      { opacity: 1;   transform: scale(1.22); }
}

/* ==========================================================================
   4. Direct-on-3D-Parchment Transparent Ink Layer (NO separate floating card!)
   Pinned directly onto the live-projected 3D parchment quad on top of the book.
   ========================================================================== */
.registration-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease;
  perspective: 1100px;
}

body.state-form .registration-overlay {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 1.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.parchment-ink-layer {
  position: fixed;
  left: var(--sheet-left);
  top: var(--sheet-top);
  width: var(--sheet-width);
  max-height: var(--sheet-height);
  transform: translate(-50%, -50%) rotateX(9deg);
  transform-origin: center center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(10px, 2vh, 22px) clamp(12px, 2.5%, 22px);
  /* 100% transparent so the REAL 3D illuminated parchment shines right through! */
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--ink-sepia);
  user-select: text;
  overflow-y: auto;
  scrollbar-width: none;
}

.parchment-ink-layer::-webkit-scrollbar {
  display: none;
}

.parchment-ink__ornament {
  text-align: center;
  color: rgba(112, 72, 22, 0.78);
  font-size: clamp(0.82rem, 1.4vw, 0.98rem);
  letter-spacing: 0.28em;
  margin-bottom: 2px;
}

.parchment-ink__heading {
  font-family: var(--font-gothic-display);
  font-weight: 400;
  font-size: clamp(1.18rem, 2.3vw, 1.66rem);
  text-align: center;
  color: rgba(34, 18, 6, 0.92);
  margin-bottom: clamp(10px, 2vh, 18px);
  line-height: 1.18;
  text-shadow: 0 1px 0 rgba(255, 245, 214, 0.45);
}

.reg-form {
  display: flex;
  flex-direction: column;
  gap: clamp(9px, 1.8vh, 15px);
}

.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.reg-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reg-field__label {
  font-family: var(--font-gothic-display);
  font-size: clamp(0.98rem, 1.75vw, 1.2rem);
  color: rgba(40, 22, 8, 0.9);
  letter-spacing: 0.02em;
}

/* Transparent hand-ruled ink lines directly on the 3D parchment! */
.reg-field__input {
  width: 100%;
  font-family: var(--font-gothic-script);
  font-size: clamp(1rem, 1.8vw, 1.18rem);
  line-height: 1.34;
  color: #1e1004;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid rgba(92, 56, 18, 0.48);
  border-radius: 0;
  padding: 4px 2px 5px;
  caret-color: #5e300a;
  transition: border-color 0.25s ease, background-color 0.25s ease;
}

.reg-field__input::placeholder {
  color: rgba(82, 52, 22, 0.46);
  font-style: italic;
}

.reg-field__input:focus {
  outline: none;
  background: rgba(255, 248, 226, 0.16);
  border-bottom-color: rgba(124, 72, 14, 0.88);
}

.reg-field__textarea {
  resize: none;
  min-height: 54px;
  max-height: 112px;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(1.34em - 1px),
    rgba(92, 56, 18, 0.22) calc(1.34em - 1px),
    rgba(92, 56, 18, 0.22) 1.34em
  );
  background-position: 0 5px;
}

.reg-form__error {
  min-height: 1.1em;
  font-family: var(--font-gothic-script);
  font-size: 0.94rem;
  color: #8b1c12;
  text-align: center;
}

.reg-form__actions {
  display: flex;
  justify-content: center;
  margin-top: 2px;
}

/* Wax-seal / antique-ink stamped submit button blended naturally into the parchment */
.ink-seal-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 24px;
  border-radius: 999px;
  border: 1.5px solid rgba(98, 58, 16, 0.78);
  background: radial-gradient(ellipse at 50% 30%, rgba(126, 40, 26, 0.92), rgba(78, 20, 14, 0.95));
  color: #fbe6b4;
  font-family: var(--font-gothic-display);
  font-size: clamp(1rem, 1.75vw, 1.2rem);
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow:
    0 4px 12px rgba(42, 18, 6, 0.36),
    inset 0 1px 0 rgba(255, 226, 170, 0.38),
    inset 0 -2px 5px rgba(26, 6, 3, 0.45);
  transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
}

.ink-seal-button:hover,
.ink-seal-button:focus-visible {
  transform: translateY(-1px) scale(1.02);
  box-shadow:
    0 7px 18px rgba(42, 18, 6, 0.45),
    0 0 18px rgba(212, 152, 60, 0.32),
    inset 0 1px 0 rgba(255, 238, 195, 0.55);
  filter: brightness(1.08);
  outline: none;
}

.ink-seal-button:active {
  transform: translateY(0);
}

.ink-seal-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* ==========================================================================
   5. Corner Controls & Loading Veil
   ========================================================================== */
.corner-controls {
  position: fixed;
  top: clamp(14px, 2.5vh, 24px);
  right: clamp(14px, 2.5vw, 24px);
  z-index: 40;
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(244, 212, 124, 0.36);
  background: rgba(22, 12, 5, 0.68);
  color: var(--gold-bright);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.25s ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  border-color: rgba(255, 232, 158, 0.85);
  background: rgba(46, 26, 10, 0.86);
  transform: scale(1.05);
  outline: none;
}

.icon-btn__svg {
  width: 20px;
  height: 20px;
}

.icon-btn[aria-pressed="true"] .icon-btn__svg--off {
  display: none;
}

.icon-btn[aria-pressed="false"] .icon-btn__svg--on {
  display: none;
}

.loading-veil {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(circle at 50% 45%, #231409 0%, #0d0703 100%);
  transition: opacity 0.9s ease, visibility 0.9s ease;
}

.loading-veil.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-veil__gear {
  font-size: 3rem;
  color: var(--gold-warm);
  animation: spinSlow 4s linear infinite;
  text-shadow: 0 0 20px rgba(244, 200, 102, 0.4);
}

.loading-veil__text {
  font-family: var(--font-gothic-script);
  font-size: 1.25rem;
  color: var(--gold-bright);
  letter-spacing: 0.05em;
}

@keyframes spinSlow {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   6. Mobile & Reduced-Motion Refinements
   ========================================================================== */
@media (max-width: 600px) {
  .parchment-ink-layer {
    transform: translate(-50%, -50%) rotateX(5deg);
    padding: 8px 10px;
  }

  .parchment-ink__heading {
    font-size: 1.08rem;
    margin-bottom: 8px;
  }

  .reg-field__label {
    font-size: 0.94rem;
  }

  .reg-field__input {
    font-size: 0.92rem;
    padding: 3px 2px 4px;
  }

  .reg-form {
    gap: 7px;
  }

  .ink-seal-button {
    padding: 7px 18px;
    font-size: 0.92rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .floating-hint,
  .study-backdrop__warm-glow,
  .loading-veil__gear {
    animation: none;
  }
}
