/* Mat.ai — quiet host conversation */

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: #0a0907;
  color: #ece4d2;
  font-family: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: default;
}

:root {
  --ink: #ece4d2;
  --ink-dim: rgba(236, 228, 210, 0.66);
  --ink-faint: rgba(236, 228, 210, 0.30);
  --warm: #d4a373;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

#stage { position: fixed; inset: 0; }
#scene-image, #scene-image-next {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: opacity 1.6s ease;
  opacity: 0;
  z-index: 0;
}
#scene-image.visible, #scene-image-next.visible { opacity: 1; }

#three-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 1;
}

/* Soft vignette + atmospheric darkening on top of the scene image,
   to blend the 3D character into the painted backdrop */
#vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, transparent 30%, rgba(0,0,0,0.55) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.25) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.55) 100%);
}
#grain {
  position: absolute; inset: -4px; pointer-events: none; z-index: 3;
  opacity: .06; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .9 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* Top-right icon bar — only one or two icons */
#topbar {
  position: absolute; top: 0; right: 0;
  z-index: 20;
  display: flex; gap: 4px; align-items: center;
  padding: 18px 22px;
}
.icon-btn {
  appearance: none; border: 0; background: transparent;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-dim);
  cursor: pointer;
  border-radius: 0;
  transition: color .2s, background .2s;
}
.icon-btn:hover { color: var(--ink); background: rgba(236,228,210,0.04); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.2; }

/* Caption — barely there, the slide hint */
#caption {
  position: absolute;
  left: 32px; bottom: 32px;
  z-index: 8;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#caption.visible { opacity: 1; }
#caption::before {
  content: "·"; margin-right: 8px; color: var(--warm); opacity: .6;
}

/* Dialogue block — bottom center, two-column quiet layout */
#dialogue {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 9;
  padding: 0 0 56px 0;
  display: flex; justify-content: center;
  pointer-events: none;
}
#dialogue-inner {
  width: min(1080px, 92vw);
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 60px;
  pointer-events: auto;
}

.host-line {
  font-family: "Cormorant Garamond", serif;
  font-weight: 400;
  font-size: clamp(20px, 2.1vw, 26px);
  line-height: 1.55;
  color: var(--ink);
  text-wrap: pretty;
  letter-spacing: 0.005em;
  position: relative;
  padding-left: 0;
  cursor: pointer;
}
.host-line .text { display: inline; }
.host-line .caret {
  display: inline-block;
  width: 8px; height: 1em;
  background: var(--warm);
  vertical-align: -3px;
  margin-left: 4px;
  opacity: .7;
  animation: caret-blink 1.05s steps(2, end) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

.choices {
  display: flex; flex-direction: column;
  gap: 2px;
  align-self: end;
  padding-top: 8px;
}
.choices .heading {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.32em;
  text-transform: lowercase;
  color: var(--ink-faint);
  margin-bottom: 14px;
  font-weight: 400;
}
.choice {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: clamp(15px, 1.45vw, 18px);
  line-height: 1.4;
  color: var(--ink-dim);
  padding: 8px 0;
  cursor: pointer;
  border: 0;
  background: transparent;
  text-align: left;
  position: relative;
  padding-left: 0;
  transition: color .2s, padding-left .25s, opacity .2s;
  opacity: 0;
  transform: translateY(4px);
  animation: choice-in .5s ease forwards;
  width: 100%;
  border-bottom: .5px solid rgba(236, 228, 210, 0.06);
}
.choice:last-child { border-bottom: none; }
.choice:nth-child(1) { animation-delay: 0.05s; }
.choice:nth-child(2) { animation-delay: 0.15s; }
.choice:nth-child(3) { animation-delay: 0.25s; }
.choice:nth-child(4) { animation-delay: 0.35s; }
.choice:nth-child(5) { animation-delay: 0.45s; }
@keyframes choice-in {
  to { opacity: 1; transform: translateY(0); }
}
.choice::before {
  content: "";
  position: absolute;
  left: -22px; top: 50%;
  width: 0; height: .5px;
  background: var(--warm);
  transition: width .25s ease;
}
.choice:hover, .choice:focus-visible {
  color: var(--ink);
  padding-left: 22px;
  outline: none;
}
.choice:hover::before, .choice:focus-visible::before { width: 14px; }
.choices.locked .choice { opacity: 0.18; pointer-events: none; }

/* Settings panel — slides from top-right */
#settings {
  position: absolute;
  top: 64px; right: 22px;
  z-index: 21;
  width: 280px;
  background: rgba(15, 12, 10, 0.92);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  backdrop-filter: blur(20px) saturate(120%);
  border: .5px solid rgba(236, 228, 210, 0.12);
  padding: 20px 22px 22px;
  transform: translateY(-8px);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#settings.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
#settings h3 {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
}
.setting-row {
  display: flex; flex-direction: column;
  gap: 6px; padding: 10px 0;
  border-bottom: .5px solid rgba(236, 228, 210, 0.06);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex; justify-content: space-between;
}
.setting-row .label .val {
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  text-transform: none;
}
.setting-row select, .setting-row input[type=range] {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 16px;
  outline: none;
  padding: 0;
}
.setting-row select {
  appearance: none;
  -webkit-appearance: none;
  border-bottom: .5px solid rgba(236, 228, 210, 0.18);
  padding: 4px 0;
  cursor: pointer;
}
.setting-row select option {
  background: #15120a; color: var(--ink); font-family: "Cormorant Garamond", serif;
}
.setting-row input[type=range] {
  appearance: none; -webkit-appearance: none;
  height: 18px;
}
.setting-row input[type=range]::-webkit-slider-runnable-track {
  height: .5px; background: rgba(236, 228, 210, 0.22);
}
.setting-row input[type=range]::-moz-range-track {
  height: .5px; background: rgba(236, 228, 210, 0.22);
}
.setting-row input[type=range]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 8px; height: 14px; border-radius: 0;
  background: var(--warm); margin-top: -7px; cursor: pointer;
}
.setting-row input[type=range]::-moz-range-thumb {
  width: 8px; height: 14px; border-radius: 0;
  background: var(--warm); border: 0; cursor: pointer;
}

.char-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: .5px solid rgba(236, 228, 210, 0.06);
  transition: background .15s;
}
.char-row:hover { background: rgba(236, 228, 210, 0.03); }
.char-row.active .char-name { color: var(--warm); }
.char-row.locked { opacity: 0.35; pointer-events: none; }
.char-row .portrait-mini {
  width: 32px; height: 32px;
  border: .5px solid rgba(236, 228, 210, 0.2);
  display: flex; align-items: center; justify-content: center;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 16px;
  color: var(--warm);
  flex-shrink: 0;
}
.char-row .meta { flex: 1; min-width: 0; }
.char-row .char-name {
  font-family: "Cormorant Garamond", serif;
  font-size: 17px; color: var(--ink);
}
.char-row .char-title {
  font-family: var(--mono);
  font-size: 8.5px; letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 1px;
}

/* Splash */
#splash {
  position: absolute; inset: 0;
  z-index: 100;
  background: radial-gradient(ellipse at center, #14110a 0%, #050402 90%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px;
  transition: opacity 1.2s ease;
}
#splash.hidden { opacity: 0; pointer-events: none; }
#splash .mark {
  width: 1px; height: 56px;
  background: linear-gradient(to bottom, transparent, var(--warm), transparent);
  opacity: 0.7;
}
#splash .title {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 36px;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0;
}
#splash .sub {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.34em;
  text-transform: lowercase;
  color: var(--ink-faint);
}
#splash .begin {
  margin-top: 28px;
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 17px;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 8px 24px;
  transition: color .2s, letter-spacing .25s;
  position: relative;
}
#splash .begin::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 2px;
  transform: translateX(-50%);
  width: 24px; height: .5px;
  background: var(--warm);
  transition: width .3s;
  opacity: 0.5;
}
#splash .begin:hover { color: var(--ink); letter-spacing: 0.08em; }
#splash .begin:hover::after { width: 60px; opacity: 1; }
#splash .begin[disabled] { opacity: 0.3; pointer-events: none; }

@media (max-width: 760px) {
  #dialogue-inner { grid-template-columns: 1fr; gap: 24px; }
  #dialogue { padding-bottom: 24px; }
  .host-line { font-size: 19px; }
  .choice { font-size: 16px; }
  #caption { left: 18px; bottom: 18px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  #scene-image, #scene-image-next { transition: opacity 0.4s ease; }
  .choice { animation-duration: 0.01s; opacity: 1; transform: none; }
}

/* Interactive object label (tooltip) */
.interactive-label {
  position: fixed;
  z-index: 25;
  pointer-events: none;
  background: rgba(15, 12, 10, 0.92);
  border: .5px solid rgba(236, 228, 210, 0.18);
  padding: 6px 12px;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: 0.02em;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.interactive-label::before {
  content: "·";
  margin-right: 6px;
  color: var(--warm);
}

/* Game HUD */
#game-hud-wrap { position: absolute; inset: 0; z-index: 30; pointer-events: none; }
.game-hud {
  position: absolute; top: 22px; left: 22px;
  background: rgba(15, 12, 10, 0.86);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: .5px solid rgba(236, 228, 210, 0.12);
  padding: 16px 18px; min-width: 220px;
  pointer-events: auto;
  font-family: var(--mono);
  color: var(--ink-dim);
}
.game-hud-title {
  font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--warm); margin-bottom: 12px;
}
.game-hud-row {
  display: flex; justify-content: space-between;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 4px 0;
}
.game-hud-row .hud-val { color: var(--ink); font-variant-numeric: tabular-nums; }
.game-hud-bar {
  height: 4px; background: rgba(236,228,210,0.08); margin-top: 12px;
  position: relative; overflow: hidden;
}
.game-hud-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--warm); width: 0%;
  transition: width 0.04s linear;
}
.game-hud-help {
  margin-top: 12px; font-size: 9px; letter-spacing: 0.16em;
  color: var(--ink-faint); line-height: 1.5;
}
.game-hud-exit {
  margin-top: 14px; appearance: none; border: 0;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.24em; text-transform: uppercase;
  cursor: pointer;
  padding: 6px 0;
  border-top: .5px solid rgba(236, 228, 210, 0.1);
  width: 100%; text-align: left;
}
.game-hud-exit:hover { color: var(--warm); }
