:root {
  /* Risograph print palette pulled from the slide deck */
  --paper: #ece1c4;
  --paper-2: #e5d9ba;
  --card: #f4ecd6;
  --field: #fff8e6;

  --teal: #1a6b7a;
  --red: #e8472b;
  --red-deep: #c8381f;

  --ink: #191613;
  --ink-soft: #4a4339;

  /* Type */
  --font-display: "Anton", Impact, "Arial Narrow", sans-serif;
  --font-mono: "Space Mono", ui-monospace, "Courier New", monospace;
  --font-ui: "Archivo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

/* Paper grain laid over the whole page, riso-style */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.08;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================ PASSWORD GATE ============================ */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--paper);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

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

.gate__bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  mix-blend-mode: multiply;
}

.blob::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background-image: radial-gradient(rgba(0, 0, 0, 0.22) 1px, transparent 1.4px);
  background-size: 5px 5px;
  mix-blend-mode: multiply;
}

.blob--teal {
  width: 52vmin;
  height: 52vmin;
  background: var(--teal);
  top: -16vmin;
  right: -12vmin;
  opacity: 0.9;
}

.blob--red {
  width: 34vmin;
  height: 34vmin;
  background: var(--red);
  top: 10vmin;
  right: 4vmin;
  opacity: 0.92;
}

.gate__card {
  position: relative;
  z-index: 2;
  width: min(92vw, 440px);
  padding: 44px 40px 38px;
  text-align: left;
  background: var(--card);
  border: 3px solid var(--ink);
  box-shadow: 14px 14px 0 var(--teal);
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

.gate__kicker {
  display: block;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 12px;
}

.gate__title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(48px, 9vw, 78px);
  line-height: 0.9;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--teal);
  margin: 0 0 16px;
  text-shadow: 3px 3px 0 rgba(232, 71, 43, 0.22);
}

.gate__subtitle {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 26px;
}

.gate__field {
  display: flex;
  gap: 10px;
}

.gate__input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--ink);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 0;
  outline: none;
  transition: box-shadow 0.2s;
}

.gate__input:focus {
  box-shadow: 0 0 0 3px rgba(26, 107, 122, 0.3);
}

.gate__btn {
  padding: 12px 24px;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--font-display);
  font-weight: 400;
  cursor: pointer;
  color: var(--card);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}

.gate__btn:hover {
  background: var(--red);
  transform: translateY(-1px);
}

.gate__btn:active {
  transform: translateY(0);
}

.gate__error {
  min-height: 18px;
  margin: 16px 0 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--red-deep);
  opacity: 0;
  transition: opacity 0.2s;
}

.gate__error.is-visible {
  opacity: 1;
}

.gate.is-shake .gate__card {
  animation: shake 0.4s;
}

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

/* ============================ LAYOUT ============================ */
.app {
  display: grid;
  grid-template-columns: 1fr clamp(320px, 26vw, 380px);
  height: 100vh;
  width: 100vw;
  background: var(--paper);
}

.app[hidden] {
  display: none;
}

/* ============================ STAGE ============================ */
.stage-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: clamp(20px, 3.4vh, 40px) 30px;
  overflow: hidden;
}

/* Faint printed circles echoing the slide motifs */
.stage-area::before,
.stage-area::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.stage-area::before {
  width: 42vmin;
  height: 42vmin;
  background: var(--teal);
  opacity: 0.09;
  top: -15vmin;
  left: -13vmin;
}

.stage-area::after {
  width: 36vmin;
  height: 36vmin;
  background: var(--red);
  opacity: 0.09;
  bottom: -16vmin;
  right: -11vmin;
}

.stage-wrap {
  position: relative;
  z-index: 2;
  width: min(96%, 1120px);
  max-height: 80vh;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
}

/* Flat printed-poster frame around the live slide */
.stage-frame {
  position: absolute;
  inset: 0;
  background: var(--card);
  border: 3px solid var(--ink);
  box-shadow: 12px 12px 0 var(--teal);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stage-frame:hover {
  transform: translate(-2px, -2px);
  box-shadow: 16px 16px 0 var(--teal);
}

.stage-frame:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 4px;
}

.slide-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: slideIn 0.45s ease both;
}

/* The hidden attribute must win over display:block, otherwise an empty
   <img> renders a broken-image placeholder box over the frame. */
.slide-image[hidden] {
  display: none;
}

@keyframes slideIn {
  from { opacity: 0; transform: scale(1.015); }
}

.stage-empty {
  padding: 24px;
  text-align: center;
}

.stage-empty__inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage-empty__title {
  font-family: var(--font-display);
  font-size: clamp(22px, 2.4vw, 34px);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--teal);
}

.stage-empty__hint {
  font-family: var(--font-mono);
  font-size: clamp(12px, 1.1vw, 14px);
  color: var(--ink-soft);
  line-height: 1.6;
}

.stage-empty code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--red-deep);
  background: rgba(232, 71, 43, 0.1);
  padding: 1px 6px;
}

/* Controls */
.controls {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 18px;
}

.ctl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--font-display);
  font-weight: 400;
  cursor: pointer;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease,
    color 0.15s ease;
}

.ctl-btn__icon {
  font-size: 20px;
  line-height: 1;
}

.ctl-btn:hover:not(:disabled) {
  background: var(--teal);
  color: var(--card);
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 var(--ink);
}

.ctl-btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.ctl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.counter {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  min-width: 130px;
  text-align: center;
}

/* Audio bar */
.audiobar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  width: min(92%, 720px);
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}

.audiobar.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.audiobar__transport {
  display: flex;
  gap: 8px;
}

.audio-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.audio-btn:hover {
  background: var(--red);
  color: var(--card);
  transform: translateY(-1px);
}

.scrubber {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border: 2px solid var(--ink);
  background: linear-gradient(
    90deg,
    var(--teal) var(--progress, 0%),
    rgba(25, 22, 19, 0.16) var(--progress, 0%)
  );
  cursor: pointer;
}

.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 0;
  background: var(--red);
  border: 2px solid var(--ink);
}

.scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 0;
  background: var(--red);
  border: 2px solid var(--ink);
}

.audio-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 92px;
  text-align: right;
}

/* ============================ CHAT ============================ */
.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--paper-2);
  border-left: 3px solid var(--ink);
}

.chat__header {
  padding: 22px 22px 16px;
  border-bottom: 2px solid var(--ink);
}

.chat__title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--ink);
}

.chat__title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

.chat__subtitle {
  margin: 8px 0 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(25, 22, 19, 0.35) transparent;
}

.chat__log::-webkit-scrollbar {
  width: 8px;
}

.chat__log::-webkit-scrollbar-thumb {
  background: rgba(25, 22, 19, 0.3);
}

.msg {
  display: flex;
  animation: msgIn 0.3s ease both;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
}

.msg--user {
  justify-content: flex-end;
}

.msg__bubble {
  max-width: 84%;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(25, 22, 19, 0.16);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg--assistant .msg__bubble {
  background: var(--card);
  color: var(--ink);
}

.msg--user .msg__bubble {
  background: var(--teal);
  color: var(--card);
}

.msg--error .msg__bubble {
  background: var(--red);
  color: #fff;
}

/* Markdown-rendered assistant bubbles */
.msg__bubble--md {
  white-space: normal;
}

.msg__bubble--md > :first-child {
  margin-top: 0;
}

.msg__bubble--md > :last-child {
  margin-bottom: 0;
}

.msg__bubble--md p {
  margin: 0 0 0.6em;
}

.msg__bubble--md h1,
.msg__bubble--md h2,
.msg__bubble--md h3,
.msg__bubble--md h4 {
  margin: 0.7em 0 0.4em;
  line-height: 1.25;
  font-weight: 700;
}

.msg__bubble--md h1 { font-size: 1.25em; }
.msg__bubble--md h2 { font-size: 1.15em; }
.msg__bubble--md h3 { font-size: 1.05em; }
.msg__bubble--md h4 { font-size: 1em; }

.msg__bubble--md ul,
.msg__bubble--md ol {
  margin: 0 0 0.6em;
  padding-left: 1.3em;
}

.msg__bubble--md li {
  margin: 0.15em 0;
}

.msg__bubble--md a {
  color: var(--teal);
  text-decoration: underline;
}

.msg__bubble--md code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(25, 22, 19, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.msg__bubble--md pre {
  margin: 0 0 0.6em;
  padding: 10px 12px;
  background: rgba(25, 22, 19, 0.9);
  color: #f5f1e8;
  overflow-x: auto;
  border: 2px solid var(--ink);
}

.msg__bubble--md pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.85em;
}

.msg__bubble--md blockquote {
  margin: 0 0 0.6em;
  padding-left: 0.8em;
  border-left: 3px solid var(--ink);
  opacity: 0.85;
}

.msg__bubble--md strong { font-weight: 700; }
.msg__bubble--md em { font-style: italic; }

/* Typing indicator */
.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  background: var(--red);
  opacity: 0.5;
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat__compose {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 16px 18px;
  border-top: 2px solid var(--ink);
}

.chat__input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 11px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--field);
  border: 2px solid var(--ink);
  outline: none;
  transition: box-shadow 0.2s;
}

.chat__input:focus {
  box-shadow: 0 0 0 3px rgba(26, 107, 122, 0.25);
}

.chat__send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-family: var(--font-ui);
  cursor: pointer;
  color: var(--card);
  background: var(--ink);
  border: 2px solid var(--ink);
  transition: background 0.15s ease, transform 0.12s ease;
}

.chat__send:hover:not(:disabled) {
  background: var(--red);
  transform: translateY(-1px);
}

.chat__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================ LARGE MONITORS ============================ */
@media (min-width: 1700px) {
  .stage-wrap {
    width: min(80%, 1120px);
  }
}

/* ============================ NARROW / FALLBACK ============================ */
@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .stage-area {
    min-height: 72vh;
    padding: 24px 16px;
  }

  .stage-wrap {
    width: 96%;
    max-height: none;
  }

  .chat {
    height: auto;
    min-height: 60vh;
    border-left: none;
    border-top: 3px solid var(--ink);
  }

  .audiobar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
  }

  .scrubber {
    flex: 1 1 120px;
    min-width: 0;
  }

  .audio-time {
    min-width: 0;
    flex: 0 0 auto;
    margin-left: auto;
  }
}

/* ============================ REDUCED MOTION ============================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
