/*
 * THE MARBLE PARADOX / interface
 * Mobile-first UI for a full-screen first-person architectural exploration.
 * The visual system borrows material warmth and proportion from the 3D world
 * without turning the interface into a literal historical reconstruction.
 */

:root {
  color-scheme: light;
  --sky: #9bc3ca;
  --sea: #376f7d;
  --sea-deep: #285465;
  --marble: #eee7d8;
  --marble-light: #faf5e8;
  --marble-shadow: #c7bdab;
  --terracotta: #a76040;
  --ochre: #b4863f;
  --olive: #66724d;
  --bronze: #806637;
  --ink: #263537;
  --ink-soft: #536062;
  --line: rgba(38, 53, 55, 0.35);
  --glass: rgba(246, 239, 222, 0.8);
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  --gravity-angle: 0deg;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  background: var(--sky) url("../img/pentelic-marble.jpg") center / cover;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button,
kbd {
  font: inherit;
}

.experience {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100dvh;
  min-height: 480px;
  overflow: hidden;
  background: var(--sky);
}

.experience::before,
.experience::after {
  position: absolute;
  z-index: 8;
  inset: 0;
  pointer-events: none;
  content: "";
}

.experience::before {
  opacity: 0.32;
  background:
    radial-gradient(circle at 78% 13%, rgba(255, 241, 187, 0.72), transparent 20%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 45%, rgba(25, 66, 76, 0.16));
  mix-blend-mode: screen;
}

.experience::after {
  z-index: 9;
  box-shadow:
    inset 0 0 0 1px rgba(238, 231, 216, 0.28),
    inset 0 0 100px rgba(30, 61, 68, 0.22);
  transition: box-shadow 600ms ease;
}

.experience.is-turning::after {
  box-shadow:
    inset 0 0 0 3px rgba(244, 223, 168, 0.62),
    inset 0 0 170px rgba(35, 75, 83, 0.52);
}

.scene {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.scene:active {
  cursor: grabbing;
}

.scene:focus-visible {
  outline: 2px solid var(--ochre);
  outline-offset: -5px;
}

.scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 900ms ease;
}

.experience[data-ready="true"] .scene canvas {
  opacity: 1;
}

.experience[data-locked="true"] .scene,
.experience[data-locked="true"] .scene canvas {
  cursor: none;
}

.topbar {
  position: absolute;
  z-index: 30;
  top: var(--safe-top);
  right: var(--safe-right);
  left: var(--safe-left);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 7px 12px;
  pointer-events: none;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 40px;
  padding: 0 12px;
  color: var(--marble-light);
  background: rgba(38, 83, 94, 0.88);
  border: 1px solid rgba(250, 245, 232, 0.72);
  box-shadow: 0 6px 22px rgba(31, 68, 77, 0.18);
  font-size: 0.61rem;
  font-weight: 700;
  letter-spacing: 0.105em;
  text-decoration: none;
  text-transform: uppercase;
  pointer-events: auto;
  backdrop-filter: blur(10px);
}

.wordmark:hover,
.wordmark:focus-visible {
  color: var(--ink);
  background: var(--marble-light);
  outline: none;
}

.wordmark-mark {
  margin-right: 8px;
  color: #e9c578;
  font-size: 0.85rem;
}

.slash {
  margin: 0 0.58em;
  opacity: 0.5;
}

.court-readout {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: max-content;
  min-width: 178px;
  padding: 8px 10px 7px;
  color: var(--ink);
  background:
    linear-gradient(rgba(250, 245, 232, 0.88), rgba(232, 222, 201, 0.84)),
    url("../img/pentelic-marble.jpg") center / 220px;
  border: 1px solid rgba(65, 80, 80, 0.38);
  box-shadow: 0 5px 22px rgba(38, 68, 72, 0.13);
  backdrop-filter: blur(10px);
}

.court-kicker {
  grid-column: 1 / -1;
  color: var(--terracotta);
  font-size: 0.48rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.court-readout strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.83rem;
  font-weight: 500;
}

.court-readout > span:last-child {
  align-self: end;
  color: var(--sea-deep);
  font-size: 0.54rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.reset-button {
  grid-column: 2;
  grid-row: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 70px;
  min-height: 40px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(250, 245, 232, 0.82);
  border: 1px solid rgba(38, 53, 55, 0.55);
  cursor: pointer;
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  pointer-events: auto;
  backdrop-filter: blur(10px);
}

.reset-button span {
  color: var(--terracotta);
  font-size: 0.95rem;
}

.reset-button:hover,
.reset-button:focus-visible,
.reset-button:active {
  color: var(--marble-light);
  background: var(--sea-deep);
  outline: none;
}

.loading-card {
  position: absolute;
  z-index: 40;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 50px;
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 0 17px;
  color: var(--ink);
  background:
    linear-gradient(rgba(250, 245, 232, 0.88), rgba(238, 231, 216, 0.88)),
    url("../img/pentelic-marble.jpg") center / cover;
  border: 1px solid var(--bronze);
  box-shadow: 0 9px 28px rgba(28, 70, 79, 0.22);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  transition: opacity 400ms ease, visibility 400ms ease;
}

.loading-rosette {
  color: var(--terracotta);
  font-size: 1rem;
  animation: rosette-turn 2s linear infinite;
}

.experience[data-ready="true"] .loading-card {
  opacity: 0;
  visibility: hidden;
}

@keyframes rosette-turn {
  to { transform: rotate(1turn); }
}

.webgl-message,
.noscript-message {
  position: fixed;
  z-index: 80;
  top: 50%;
  left: 50%;
  display: grid;
  gap: 7px;
  width: min(340px, calc(100% - 40px));
  padding: 24px;
  color: var(--ink);
  background: var(--marble-light);
  border: 1px solid var(--terracotta);
  text-align: center;
  transform: translate(-50%, -50%);
}

.webgl-message span,
.noscript-message {
  font-size: 0.72rem;
  line-height: 1.5;
}

.entry-panel {
  position: absolute;
  z-index: 25;
  inset: 0;
  display: grid;
  padding: 98px var(--safe-right) 114px var(--safe-left);
  place-items: center;
  background:
    radial-gradient(circle at 76% 18%, rgba(255, 241, 181, 0.24), transparent 26%),
    linear-gradient(90deg, rgba(28, 66, 75, 0.2), transparent 52%),
    linear-gradient(0deg, rgba(24, 59, 68, 0.25), transparent 50%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 600ms ease, visibility 600ms ease;
}

.experience[data-ready="true"][data-started="false"] .entry-panel {
  opacity: 1;
  visibility: visible;
}

.experience[data-started="true"] .entry-panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.entry-plate {
  position: relative;
  width: min(520px, 100%);
  padding: 25px 20px 20px;
  color: var(--ink);
  background:
    linear-gradient(rgba(250, 245, 232, 0.92), rgba(230, 220, 199, 0.92)),
    url("../img/pentelic-marble.jpg") center / cover;
  border: 1px solid rgba(92, 76, 45, 0.58);
  box-shadow:
    11px 11px 0 rgba(49, 91, 99, 0.26),
    inset 0 0 0 5px rgba(255, 255, 255, 0.27);
  backdrop-filter: blur(12px);
}

.entry-plate::before {
  position: absolute;
  top: 8px;
  right: 8px;
  bottom: 8px;
  left: 8px;
  border: 1px solid rgba(128, 102, 55, 0.3);
  pointer-events: none;
  content: "";
}

.entry-index {
  position: relative;
  display: block;
  margin-bottom: 13px;
  color: var(--terracotta);
  font-size: 0.53rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.entry-plate h1 {
  position: relative;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.25rem, 11vw, 4.9rem);
  font-weight: 400;
  line-height: 0.85;
  letter-spacing: -0.055em;
  text-transform: uppercase;
}

.entry-plate p {
  position: relative;
  max-width: 440px;
  margin: 18px 0 20px;
  color: var(--ink-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.82rem;
  line-height: 1.5;
}

.enter-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 53px;
  padding: 0 16px;
  color: var(--marble-light);
  background: var(--sea-deep);
  border: 1px solid var(--sea-deep);
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.enter-button span:last-child {
  color: #efcb78;
  font-size: 1.1rem;
}

.enter-button:hover,
.enter-button:focus-visible {
  color: var(--ink);
  background: transparent;
  border-color: var(--bronze);
  outline: none;
}

.entry-controls {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 13px;
  margin-top: 15px;
  color: var(--ink-soft);
  font-size: 0.51rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.entry-controls kbd {
  color: var(--sea-deep);
  font-weight: 800;
}

.fps-ui {
  opacity: 0;
  visibility: hidden;
  transition: opacity 320ms ease, visibility 320ms ease;
}

.experience[data-started="true"] .fps-ui {
  opacity: 1;
  visibility: visible;
}

.gaze {
  position: absolute;
  z-index: 20;
  top: 50%;
  left: 50%;
  display: grid;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(250, 245, 232, 0.62);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(39, 75, 81, 0.3);
  place-items: center;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--gravity-angle));
  transition: transform 1s cubic-bezier(0.62, 0, 0.22, 1);
}

.gaze::before,
.gaze::after {
  position: absolute;
  background: rgba(250, 245, 232, 0.7);
  content: "";
}

.gaze::before { width: 32px; height: 1px; }
.gaze::after { width: 1px; height: 32px; }

.gaze span {
  width: 4px;
  height: 4px;
  background: #efc873;
  border: 1px solid var(--sea-deep);
  border-radius: 50%;
}

.threshold-card {
  position: absolute;
  z-index: 22;
  top: 50%;
  left: 50%;
  display: grid;
  min-width: min(300px, calc(100% - 48px));
  padding: 13px 16px 12px;
  color: var(--ink);
  background:
    linear-gradient(rgba(250, 245, 232, 0.94), rgba(229, 217, 193, 0.94)),
    url("../img/pentelic-marble.jpg") center / cover;
  border: 1px solid var(--bronze);
  box-shadow: 8px 8px 0 rgba(39, 80, 88, 0.24);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.95);
}

.threshold-card span,
.threshold-card small {
  color: var(--terracotta);
  font-size: 0.49rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.threshold-card strong {
  margin: 2px 0 3px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  font-weight: 500;
}

.threshold-card small {
  color: var(--sea-deep);
  font-size: 0.44rem;
}

.threshold-card.is-visible {
  animation: court-arrival 1.25s ease both;
}

.threshold-card:not(.is-visible) {
  opacity: 0 !important;
}

@keyframes court-arrival {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.94); }
  16%, 67% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.97); }
}

.step-readout {
  position: absolute;
  z-index: 19;
  top: 50%;
  right: var(--safe-right);
  display: grid;
  gap: 2px;
  padding: 7px 9px;
  color: var(--ink);
  background: rgba(250, 245, 232, 0.68);
  border-left: 2px solid var(--terracotta);
  backdrop-filter: blur(7px);
  pointer-events: none;
}

.step-readout span {
  color: var(--ink-soft);
  font-size: 0.44rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.step-readout strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.77rem;
  font-weight: 500;
}

.desktop-hud,
.capture-hint {
  display: none;
}

.court-progress {
  position: absolute;
  z-index: 21;
  top: calc(var(--safe-top) + 88px);
  right: var(--safe-right);
  display: flex;
  gap: 5px;
  padding: 6px 7px;
  background: rgba(250, 245, 232, 0.55);
  border: 1px solid rgba(38, 70, 75, 0.25);
  backdrop-filter: blur(7px);
  pointer-events: none;
}

.court-progress span {
  display: block;
  width: 18px;
  height: 4px;
  background: rgba(38, 83, 94, 0.24);
  transition: background 300ms ease, transform 300ms ease;
}

.court-progress span.is-active {
  background: var(--terracotta);
  transform: scaleY(1.55);
}

.mobile-controls {
  position: absolute;
  z-index: 32;
  inset: 0;
  pointer-events: none;
}

.move-pad {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 20px);
  left: var(--safe-left);
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(3, 42px);
  gap: 2px;
  width: 130px;
  height: 130px;
  pointer-events: auto;
  transform: rotate(-1deg);
}

.pad-button {
  display: grid;
  color: var(--marble-light);
  background: rgba(39, 80, 90, 0.76);
  border: 1px solid rgba(247, 236, 207, 0.78);
  border-radius: 50%;
  box-shadow: 0 3px 9px rgba(29, 65, 73, 0.16);
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 1rem;
  line-height: 1;
  place-items: center;
  touch-action: none;
  user-select: none;
}

.pad-button.is-active,
.pad-button:active {
  color: var(--sea-deep);
  background: #efd28a;
  transform: scale(0.93);
}

.pad-forward { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-right { grid-column: 3; grid-row: 2; }
.pad-back { grid-column: 2; grid-row: 3; }

.pad-center {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  margin: 10px;
  color: #efcf84;
  background: rgba(39, 80, 90, 0.8);
  border: 1px solid rgba(250, 245, 232, 0.68);
  border-radius: 50%;
  font-size: 0.65rem;
  place-items: center;
  transform: rotate(var(--gravity-angle));
  transition: transform 1s cubic-bezier(0.62, 0, 0.22, 1);
}

.look-pad {
  position: absolute;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 20px);
  display: grid;
  width: 124px;
  height: 124px;
  color: var(--marble-light);
  background: rgba(39, 80, 90, 0.38);
  border: 1px solid rgba(247, 236, 207, 0.68);
  border-radius: 50%;
  box-shadow: inset 0 0 24px rgba(250, 237, 195, 0.12);
  cursor: move;
  place-content: center;
  text-align: center;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.look-pad strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.look-pad small {
  margin-top: 2px;
  color: #efd18a;
  font-size: 0.44rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.look-orbit {
  position: absolute;
  inset: 15px;
  border: 1px dashed rgba(250, 245, 232, 0.45);
  border-radius: 50%;
}

.look-orbit::before,
.look-orbit::after {
  position: absolute;
  top: 50%;
  left: 50%;
  background: rgba(250, 245, 232, 0.45);
  content: "";
  transform: translate(-50%, -50%);
}

.look-orbit::before { width: 26px; height: 1px; }
.look-orbit::after { width: 1px; height: 26px; }

.stride-indicator {
  position: absolute;
  z-index: 20;
  bottom: calc(var(--safe-bottom) + 162px);
  left: calc(var(--safe-left) + 7px);
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--marble-light);
  font-size: 0.47rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-shadow: 0 1px 2px rgba(25, 57, 64, 0.7);
  text-transform: uppercase;
  pointer-events: none;
}

.stride-indicator span {
  width: 24px;
  height: 3px;
  background: #efd07e;
  transform: scaleX(0.25);
  transform-origin: left;
  transition: transform 180ms ease;
}

.stride-indicator.is-active span {
  transform: scaleX(1);
}

.folio {
  position: absolute;
  z-index: 18;
  right: var(--safe-right);
  bottom: max(6px, env(safe-area-inset-bottom));
  left: var(--safe-left);
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: rgba(250, 245, 232, 0.78);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.48rem;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 2px rgba(31, 64, 70, 0.7);
  text-transform: uppercase;
  pointer-events: none;
}

@media (pointer: fine) and (min-width: 700px) {
  .topbar {
    top: max(18px, env(safe-area-inset-top));
    right: max(22px, env(safe-area-inset-right));
    left: max(22px, env(safe-area-inset-left));
    grid-template-columns: 1fr auto 1fr;
  }

  .court-readout {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
  }

  .reset-button {
    grid-column: 3;
    justify-self: end;
  }

  .entry-panel {
    justify-items: start;
    padding: 90px max(6vw, 60px) 70px;
  }

  .entry-plate {
    padding: 33px 30px 27px;
  }

  .entry-controls {
    grid-template-columns: repeat(4, auto);
  }

  .mobile-controls,
  .stride-indicator {
    display: none;
  }

  .desktop-hud {
    position: absolute;
    z-index: 20;
    bottom: max(25px, env(safe-area-inset-bottom));
    left: max(22px, env(safe-area-inset-left));
    display: flex;
    gap: 16px;
    padding: 9px 11px;
    color: rgba(250, 245, 232, 0.82);
    background: rgba(39, 80, 90, 0.58);
    border: 1px solid rgba(247, 236, 207, 0.35);
    font-size: 0.49rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    backdrop-filter: blur(7px);
    pointer-events: none;
  }

  .desktop-hud b {
    color: #f0cf80;
  }

  .capture-hint {
    position: absolute;
    z-index: 20;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(25px, env(safe-area-inset-bottom));
    display: block;
    padding: 9px 11px;
    color: var(--marble-light);
    background: rgba(39, 80, 90, 0.58);
    border: 1px solid rgba(247, 236, 207, 0.35);
    font-size: 0.49rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    backdrop-filter: blur(7px);
    pointer-events: none;
  }

  .experience[data-locked="true"] .capture-hint {
    opacity: 0;
  }

  .court-progress {
    top: max(26px, env(safe-area-inset-top));
    right: auto;
    left: 50%;
    transform: translate(-50%, 52px);
  }

  .step-readout {
    right: max(22px, env(safe-area-inset-right));
  }

  .folio {
    display: none;
  }
}

@media (max-height: 640px) {
  .entry-panel {
    padding-top: 69px;
    padding-bottom: 72px;
  }

  .entry-plate {
    padding: 18px;
  }

  .entry-plate h1 {
    font-size: 1.9rem;
  }

  .entry-plate p {
    margin: 10px 0 13px;
  }

  .entry-controls {
    display: none;
  }

  .move-pad {
    grid-template-columns: repeat(3, 37px);
    grid-template-rows: repeat(3, 37px);
    width: 115px;
    height: 115px;
  }

  .look-pad {
    width: 106px;
    height: 106px;
  }

  .stride-indicator {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
