/* ==========================================================================
   Captain Nemo's Prompt Injection Trials — mobile-first, mood-aware.

   Layout is an app shell: #app is a flex column pinned to the viewport, and
   only .chat-log scrolls. That is what keeps the composer reachable above a
   phone keyboard instead of being pushed off-screen.

   The per-act palette lives on <body>, written by a watcher in app.js — the
   body element sits outside the Vue mount root, so it cannot be bound in the
   template.
   ========================================================================== */

:root {
  --ocean-deep: #0a1929;
  --ocean-mid: #1e3a5f;
  --ocean-shallow: #0d4f6c;
  --parchment: #f4e8c1;
  --parchment-dark: #e0d3a4;
  --ink: #1a0e08;
  --rust: #a05a2c;

  --accent: #b8860b;
  --accent-bright: #daa520;
  --accent-text: #0a1929;
  --accent-shadow: rgba(218, 165, 32, 0.35);

  --danger: #e0574f;
  --ok: #4ec98a;

  --ink-line: #0a1420;
  --shadow-deep: 6px 6px 0 var(--ink-line), 0 10px 26px rgba(0, 0, 0, 0.5);
  --shadow-card: 3px 3px 0 var(--ink-line);
  --shadow-pop: 4px 4px 0 var(--ink-line);

  --font-display: "Bungee", "Pirata One", system-ui, sans-serif;
  --font-fancy: "Pirata One", "Patrick Hand", serif;
  --font-modern: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body: "IM Fell English", Georgia, serif;
  --font-hand: "Patrick Hand", "Comic Neue", sans-serif;

  --gutter: 12px;
  --radius: 12px;
}

body.theme-1 {
  --accent: #d94f3a; --accent-bright: #ff7a5f; --accent-text: #2a0a05;
  --accent-shadow: rgba(217, 79, 58, 0.45);
}
body.theme-2 {
  --accent: #18b3c9; --accent-bright: #5ee0f5; --accent-text: #02141a;
  --accent-shadow: rgba(94, 224, 245, 0.45);
}
body.theme-3 {
  --accent: #c93f8a; --accent-bright: #ff7ac0; --accent-text: #2a0420;
  --accent-shadow: rgba(255, 122, 192, 0.5);
}

[v-cloak] { display: none; }
* { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,0.04) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, var(--accent-shadow) 0%, transparent 55%),
    linear-gradient(180deg, var(--ocean-deep) 0%, var(--ocean-mid) 60%, var(--ocean-shallow) 100%);
  background-attachment: fixed;
  color: var(--parchment);
  font-family: var(--font-modern);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  transition: --accent 400ms;
}

/* Ambient bubbles */
.bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bubbles span {
  position: absolute;
  bottom: -60px;
  left: var(--left);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.22), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.12);
  animation: rise var(--dur) linear var(--delay) infinite;
}
@keyframes rise {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  10%  { opacity: 0.7; }
  90%  { opacity: 0.5; }
  100% { transform: translateY(-105vh) translateX(20px); opacity: 0; }
}

/* ==========================================================================
   App shell
   ========================================================================== */

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--gutter);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ==========================================================================
   Gate
   ========================================================================== */

.gate-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px var(--gutter);
  background: rgba(5, 14, 24, 0.82);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.gate-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(170deg, rgba(30,58,95,0.96), rgba(10,25,41,0.98));
  border: 3px solid var(--accent);
  outline: 2px solid var(--ink-line);
  border-radius: 16px;
  box-shadow: var(--shadow-deep);
  padding: 22px 20px 24px;
  text-align: center;
}
.gate-logo { width: 108px; height: 54px; object-fit: contain; margin-bottom: 6px; }
.gate-title {
  font-family: var(--font-display);
  font-size: 21px;
  line-height: 1.25;
  margin: 4px 0 10px;
  color: var(--accent-bright);
  text-shadow: 0 2px 0 rgba(0,0,0,0.5);
}
.gate-lead {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--parchment-dark);
  margin: 0 0 18px;
}
.gate-form { display: flex; flex-direction: column; gap: 13px; text-align: left; }
.gate-field { display: flex; flex-direction: column; gap: 5px; }
.gate-field > span {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-bright);
  font-weight: 600;
}
.gate-field small { font-size: 11.5px; color: rgba(244,232,193,0.55); line-height: 1.35; }
.gate-field input {
  font-family: var(--font-modern);
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid rgba(244,232,193,0.25);
  background: rgba(10,25,41,0.75);
  color: var(--parchment);
}
.gate-field input:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px var(--accent-shadow);
}
.gate-error {
  margin: 0;
  color: #ffb3ad;
  font-size: 13.5px;
  background: rgba(224,87,79,0.14);
  border: 1px solid rgba(224,87,79,0.4);
  border-radius: 8px;
  padding: 8px 10px;
}

/* ==========================================================================
   Masthead
   ========================================================================== */

.masthead {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 6px;
}
.masthead-logo { width: 54px; height: 30px; object-fit: contain; flex: none; }
.masthead-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.title-line-1 {
  font-family: var(--font-fancy);
  font-size: 12px;
  color: var(--parchment-dark);
  letter-spacing: 0.05em;
  line-height: 1;
}
.title-line-2 {
  font-family: var(--font-display);
  text-shadow: 2px 2px 0 var(--ink-line);
  font-size: 15px;
  color: var(--accent-bright);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.masthead-meta { display: flex; align-items: center; gap: 6px; flex: none; }
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  border: 2px solid var(--ink-line);
  background: rgba(10,25,41,0.55);
  color: var(--parchment);
  text-decoration: none;
  white-space: nowrap;
}
.meta-pill.score { border-color: var(--accent); color: var(--accent-bright); }
.meta-pill.who {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none;
}
.board-link:active { transform: scale(0.96); }
.meta-pill-text { display: none; }

/* ==========================================================================
   Act selector
   ========================================================================== */

.chapters {
  flex: none;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
}
.chapters::-webkit-scrollbar { display: none; }

.chapter-card {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: 999px;
  border: 2px solid var(--ink-line);
  background: rgba(10,25,41,0.5);
  box-shadow: var(--shadow-card);
  color: var(--parchment-dark);
  font-family: var(--font-modern);
  cursor: pointer;
  scroll-snap-align: start;
  transition: border-color 150ms, background 150ms, color 150ms;
}
.chapter-card.active {
  border-color: var(--accent-bright);
  background: rgba(0,0,0,0.42);
  color: var(--parchment);
  box-shadow: var(--shadow-pop), 0 0 0 3px var(--accent-shadow);
  transform: translate(-1px, -1px);
}
.chapter-card.completed .chapter-num { color: var(--ok); }
.chapter-num {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--accent-bright);
  flex: none;
}
.chapter-meta { display: flex; flex-direction: column; min-width: 0; text-align: left; }
/* Name and tag appear from 560px up; below that the banner carries the name. */
.chapter-name { display: none; font-size: 12.5px; font-weight: 600; }
.chapter-tag { display: none; }
.status-icon { width: 15px; height: 15px; flex: none; }
.checkmark { color: var(--ok); }

/* ==========================================================================
   Banner
   ========================================================================== */

.chapter-banner { display: none; }
.banner-act {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--accent);
}
.banner-title {
  font-family: var(--font-fancy);
  text-shadow: 2px 2px 0 var(--ink-line);
  font-size: 23px;
  margin: 1px 0 3px;
  color: var(--parchment);
  line-height: 1.1;
}
.banner-stakes {
  font-family: var(--font-hand);
  font-size: 12.5px;
  color: var(--parchment-dark);
  opacity: 0.85;
}

/* ==========================================================================
   Stage
   ========================================================================== */

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nemo-panel { flex: none; display: flex; flex-direction: column; gap: 7px; }

.porthole-wrap { display: flex; align-items: center; gap: 11px; }
.porthole-caption { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.porthole-act {
  font-family: var(--font-fancy);
  text-shadow: 2px 2px 0 var(--ink-line);
  font-size: 17px;
  line-height: 1.15;
  color: var(--parchment);
}
.porthole {
  position: relative;
  width: 76px;
  height: 76px;
  flex: none;
  border-radius: 50%;
  border: 4px solid var(--accent);
  outline: 2px solid var(--ink-line);
  background: var(--ocean-deep);
  overflow: hidden;
  box-shadow: var(--shadow-card), inset 0 0 18px rgba(0,0,0,0.6);
}
.porthole-rim { display: none; }
.porthole-glass { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; }
.nemo-face { width: 100%; height: 100%; display: block; }
.porthole-mood-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  font-family: var(--font-modern);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-bright);
  background: rgba(10, 25, 41, 0.72);
  border: 2px solid var(--ink-line);
  border-radius: 999px;
  padding: 3px 10px;
  box-shadow: var(--shadow-card);
}
/* A small dot that picks up the act accent and pulses while Nemo is talking. */
.porthole-mood-tag::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-bright);
  flex: none;
}
body.mood-speaking .porthole-mood-tag::before { animation: blink 1s ease-in-out infinite; }
body.mood-success .porthole-mood-tag::before { background: var(--ok); }
body.mood-blocked-input .porthole-mood-tag::before,
body.mood-blocked-output .porthole-mood-tag::before,
body.mood-blocked-guard .porthole-mood-tag::before { background: var(--danger); }
.porthole.shaking { animation: shake 520ms ease-in-out; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(5px) rotate(2deg); }
  60% { transform: translateX(-4px) rotate(-1deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

/* Captain's log */
.captains-log {
  background: linear-gradient(160deg, rgba(244,232,193,0.11), rgba(244,232,193,0.04));
  border: 2px solid var(--ink-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.log-summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.log-summary::-webkit-details-marker { display: none; }
.log-summary::after {
  content: "▸";
  margin-left: auto;
  color: var(--accent-bright);
  transition: transform 180ms;
}
.captains-log[open] .log-summary::after { transform: rotate(90deg); }
.log-stamp {
  font-family: var(--font-display);
  letter-spacing: 0.14em;
  color: var(--accent-bright);
}
.log-hint-text { color: rgba(244,232,193,0.45); font-size: 10.5px; }
.captains-log[open] .log-hint-text { display: none; }
.log-content { padding: 0 11px 11px; }
.log-body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 9px;
  color: var(--parchment-dark);
}
.log-objective {
  font-size: 13px;
  padding: 7px 9px;
  border-left: 3px solid var(--accent);
  background: rgba(0,0,0,0.22);
  border-radius: 0 7px 7px 0;
  margin-bottom: 9px;
}
.log-objective strong { color: var(--accent-bright); }
.log-defenses strong { font-size: 12px; color: var(--accent-bright); }
.log-defenses ul { margin: 5px 0 0; padding-left: 17px; }
.log-defenses li { font-size: 12.5px; line-height: 1.45; color: var(--parchment-dark); margin-bottom: 3px; }

/* ==========================================================================
   Chat
   ========================================================================== */

.chat-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(10, 25, 41, 0.45);
  border: 2px solid var(--ink-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  font-family: var(--font-hand);
  font-size: 15px;
  color: rgba(244,232,193,0.5);
  padding: 18px;
}

.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.nemo { justify-content: flex-start; }

.bubble {
  max-width: 88%;
  padding: 9px 13px 11px;
  border-radius: 16px;
  border: 2px solid var(--ink-line);
  box-shadow: var(--shadow-card);
  animation: popIn 200ms ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble-name {
  display: block;
  font-family: var(--font-display);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 4px;
}
.bubble-text {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: rgba(0,0,0,0.3);
  padding: 1px 4px;
  border-radius: 4px;
}
.nemo-bubble {
  background: linear-gradient(150deg, #2a4f7d, #12607f);
  border-bottom-left-radius: 5px;
}
.nemo-bubble.blocked {
  background: linear-gradient(150deg, #6d2226, #3c141b);
}
.user-bubble {
  background: linear-gradient(150deg, #f8eecb, #e6d7a6);
  color: var(--ink);
  border-bottom-right-radius: 5px;
}
.hint-bubble {
  background: linear-gradient(150deg, rgba(184,134,11,0.26), rgba(184,134,11,0.12));
  border: 1px dashed var(--accent-bright);
  max-width: 94%;
}
.block-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(224,87,79,0.45);
  color: #ffb3ad;
  margin-bottom: 5px;
}
.block-tag.tag-guard { border-color: rgba(94,224,245,0.5); color: #bff0fa; }
.block-tag.tag-output { border-color: rgba(218,165,32,0.5); color: #f3d68a; }
.block-tag.tag-rate,
.block-tag.tag-governor { border-color: rgba(244,232,193,0.4); color: var(--parchment-dark); }

.dots { display: flex; gap: 4px; margin: 4px 0 2px; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-bright);
  animation: blink 1.2s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%,80%,100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ==========================================================================
   Composer
   ========================================================================== */

.input-bar {
  flex: none;
  border-top: 1px solid rgba(244,232,193,0.16);
  background: rgba(10,25,41,0.7);
  padding: 8px 9px calc(8px + env(safe-area-inset-bottom));
}
.input-row { display: flex; gap: 7px; align-items: flex-end; }
.input-bar textarea {
  flex: 1;
  min-height: 56px;
  max-height: 140px;
  resize: none;
  font-family: var(--font-modern);
  font-size: 16px; /* keeps iOS from zooming on focus */
  line-height: 1.35;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(244,232,193,0.25);
  background: rgba(10,25,41,0.85);
  color: var(--parchment);
}
.input-bar textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 2px var(--accent-shadow);
}
.input-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
}
.char-count { font-size: 11px; color: rgba(244,232,193,0.4); margin-right: auto; }
.char-count.near { color: #ffb3ad; }

.btn {
  font-family: var(--font-modern);
  font-weight: 700;
  border-radius: 10px;
  border: 2px solid var(--ink-line);
  cursor: pointer;
  padding: 9px 14px;
  font-size: 14px;
  box-shadow: var(--shadow-card);
  transition: transform 90ms, box-shadow 90ms, filter 150ms;
}
/* Press the sticker into the page instead of just shrinking it. */
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent-bright); color: var(--accent-text); }
.btn-secondary {
  background: rgba(244,232,193,0.12);
  color: var(--parchment);
  border-color: rgba(244,232,193,0.3);
}
.btn-ghost {
  background: transparent;
  color: var(--parchment-dark);
  border-color: rgba(244,232,193,0.22);
}
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-lg { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn-send {
  flex: none;
  width: 50px;
  height: 56px;
  padding: 0;
  font-size: 17px;
  display: grid;
  place-items: center;
}

/* Flag */
.flag-bar { display: flex; gap: 7px; margin-top: 7px; }
.flag-input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px dashed var(--accent);
  background: rgba(0,0,0,0.32);
  color: var(--accent-bright);
}
.flag-input:focus { outline: none; border-style: solid; box-shadow: 0 0 0 2px var(--accent-shadow); }
.flag-feedback { margin: 6px 0 0; font-size: 12.5px; color: #ffb3ad; font-family: var(--font-hand); }
.flag-success {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  padding: 8px 11px;
  border-radius: 9px;
  background: rgba(78,201,138,0.14);
  border: 1px solid rgba(78,201,138,0.45);
  font-size: 13px;
}
.flag-success-mark {
  display: grid; place-items: center;
  width: 20px; height: 20px; flex: none;
  border-radius: 50%;
  background: var(--ok);
  color: #052015;
  font-weight: 700;
  font-size: 12px;
}

/* ==========================================================================
   Footer, toast, confetti
   ========================================================================== */

.footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 0 9px;
  font-size: 11px;
  color: rgba(244,232,193,0.42);
}
.footer code { font-size: 10.5px; }
.link {
  background: none; border: none; padding: 0;
  color: var(--accent-bright);
  font: inherit; cursor: pointer; text-decoration: underline;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  border-radius: 999px;
  background: rgba(10,25,41,0.96);
  border: 1px solid var(--accent);
  color: var(--parchment);
  font-size: 13.5px;
  text-align: center;
  box-shadow: var(--shadow-deep);
  animation: popIn 220ms ease-out;
}

.confetti-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti-piece { position: absolute; top: -40px; animation: confettiFall linear forwards; }
@keyframes confettiFall {
  0%   { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ==========================================================================
   Mood states — drive Nemo's face
   ========================================================================== */

.mouth, .sparkles, .vein, .guardian-fx, .eyelids, .zzz { display: none; }
.mouth-neutral { display: inline; }

/* Dozing — shown when a reply is taking long enough that a player would
   otherwise wonder whether the thing is broken. Nemo shuts his eyes and
   snores instead of the page just sitting there. */
.porthole.mood-dozing .eyes { display: none; }
.porthole.mood-dozing .eyelids { display: inline; }
.porthole.mood-dozing .zzz { display: inline; }
.zz {
  fill: #cfe8ff;
  font-family: var(--font-display, sans-serif);
  font-size: 19px;
  font-weight: 700;
  opacity: 0;
  /* Without fill-box each glyph translates from the SVG origin, which throws
     them off the side of the porthole instead of drifting off his head. */
  transform-box: fill-box;
  transform-origin: center;
  animation: snooze 2.7s ease-in-out infinite;
}
.zz.z2 { animation-delay: 0.9s; }
.zz.z3 { animation-delay: 1.8s; }
@keyframes snooze {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.7) rotate(-8deg); }
  25%  { opacity: 0.95; }
  100% { opacity: 0; transform: translate(10px, -22px) scale(1.15) rotate(8deg); }
}

.porthole.mood-speaking .mouth-neutral { display: none; }
.porthole.mood-speaking .mouth-open {
  display: inline;
  /* Without fill-box the scale is measured from the SVG origin, so the mouth
     travels up and down across the whole face instead of opening in place. */
  transform-box: fill-box;
  transform-origin: center;
  animation: talk 420ms ease-in-out infinite;
}
@keyframes talk { 0%, 100% { transform: scaleY(0.75); } 50% { transform: scaleY(1.15); } }

.porthole.mood-success .mouth-neutral { display: none; }
.porthole.mood-success .mouth-smile { display: inline; }
.porthole.mood-success .sparkles { display: inline; }
.sparkle { fill: #ffe27a; font-size: 15px; animation: twinkle 1.5s ease-in-out infinite; }
.sparkle.s2 { animation-delay: 0.35s; }
.sparkle.s3 { animation-delay: 0.7s; }
@keyframes twinkle { 0%,100% { opacity: 0.2; } 50% { opacity: 1; } }

.porthole.mood-blocked-input .mouth-neutral { display: none; }
.porthole.mood-blocked-input .mouth-open { display: inline; }
.porthole.mood-blocked-input .vein { display: inline; animation: veinPulse 1.4s ease-in-out infinite; }
@keyframes veinPulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }

.porthole.mood-blocked-output .mouth-neutral { display: none; }
.porthole.mood-blocked-output .mouth-smile { display: inline; }

.porthole.mood-blocked-guard .mouth-neutral { display: none; }
.porthole.mood-blocked-guard .mouth-frown { display: inline; }
.porthole.mood-blocked-guard .guardian-fx { display: inline; }
.porthole.mood-blocked-guard .guardian-iris { animation: spin 2.4s linear infinite; }
.porthole.mood-blocked-guard .guardian-radar { animation: radar 1.8s ease-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes radar {
  0%   { r: 6; opacity: 0.9; }
  100% { r: 26; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .bubbles { display: none; }
}


/* Slim, themed scrollbars. The default chrome is far too heavy next to the
   ink-outlined panels. */
.captains-log,
.chat-log,
.chapters,
.scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
.captains-log::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
.scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.captains-log::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track,
.scroll::-webkit-scrollbar-track {
  background: transparent;
}
.captains-log::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
.scroll::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 999px;
  opacity: 0.6;
}
.captains-log::-webkit-scrollbar-thumb:hover,
.chat-log::-webkit-scrollbar-thumb:hover,
.scroll::-webkit-scrollbar-thumb:hover {
  background: var(--accent-bright);
}

/* ==========================================================================
   Larger screens
   ========================================================================== */

@media (min-width: 560px) {
  :root { --gutter: 16px; }
  .meta-pill-text { display: inline; }
  .meta-pill.who { display: inline-flex; }
  .title-line-1 { font-size: 13px; }
  .title-line-2 { font-size: 19px; }
  .masthead-logo { width: 74px; height: 40px; }
  .banner-title { font-size: 28px; }
  .chapter-banner {
    display: block;
    flex: none;
    text-align: center;
    padding: 5px 0 8px;
  }
  .porthole-act { display: none; }
  .porthole { width: 84px; height: 84px; }
  .bubble { max-width: 78%; }
  .chapter-card { padding: 8px 13px; justify-content: flex-start; flex: 1 0 auto; }
  .chapter-name {
    display: block;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (min-width: 900px) {
  :root { --gutter: 20px; }

  .masthead { padding: 14px 0 10px; gap: 14px; }
  .masthead-logo { width: 104px; height: 52px; }
  .title-line-1 { font-size: 15px; }
  .title-line-2 { font-size: 26px; white-space: normal; }
  .meta-pill { font-size: 13px; padding: 6px 12px; }
  .meta-pill.who { max-width: 160px; }

  .chapters { gap: 10px; padding-bottom: 10px; overflow: visible; }
  .chapter-card {
    flex: 1 1 0;
    border-radius: var(--radius);
    padding: 12px 14px;
    align-items: center;
    gap: 13px;
  }
  .chapter-num {
    font-size: 20px;
    min-width: 34px;
    text-align: center;
    align-self: center;
  }
  .chapter-name { display: block; font-size: 14.5px; white-space: normal; }
  .chapter-tag {
    display: block;
    font-size: 11.5px;
    opacity: 0.65;
    margin-top: 2px;
  }
  .status-icon { width: 18px; height: 18px; margin-left: auto; }

  .banner-act { font-size: 12px; }
  .banner-title { font-size: 34px; }
  .banner-stakes { font-size: 14px; }
  .chapter-banner { padding: 6px 0 12px; }

  .stage { flex-direction: row; gap: 16px; }
  .nemo-panel { width: 268px; flex: none; min-height: 0; }
  /* Only the log scrolls; the porthole stays put. The <details> box itself is
     the scroll container because it wraps its body in an internal element that
     flex rules on .log-content cannot reach. The summary is stuck to the top so
     the "CAPTAIN'S LOG" header does not scroll away with the text. */
  .captains-log {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* Collapsed it must shrink to the summary bar, otherwise the rail keeps the
     leftover height and renders as an empty panel. */
  .captains-log:not([open]) {
    flex: 0 0 auto;
    overflow: hidden;
  }
  .log-summary {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #1c3350;
  }
  .porthole { width: 168px; height: 168px; border-width: 6px; margin: 0 auto; }
  .porthole-wrap { flex-direction: column; gap: 8px; }
  .porthole-caption { align-items: center; }
  .porthole-mood-tag { align-self: center; }
  .porthole-rim { display: block; position: absolute; inset: 0; pointer-events: none; }
  .rivet {
    position: absolute;
    top: 50%; left: 50%;
    width: 7px; height: 7px;
    margin: -3.5px 0 0 -3.5px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #f0d98a, var(--accent));
  }
  .porthole-mood-tag { font-size: 15px; }
  .log-hint-text { display: none; }

  .bubble { max-width: 74%; }
  .bubble-text { font-size: 15.5px; }
  .input-bar { padding: 11px 12px; }
  /* 56px is a thumb target on a phone; on a pointer device it just looks like
     a giant empty field. autoGrow() still expands it as the player types. */
  .input-bar textarea { min-height: 44px; }
  .btn-send { height: 44px; width: 46px; }
  .footer { font-size: 12px; padding: 10px 0 14px; }
}
