:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #12100f;
  color: #f7ecd8;
  --ink: #080807;
  --paper: #f7ecd8;
  --gold: #f0bf58;
  --cyan: #54d8ff;
  --green: #4fd47d;
  --red: #e84a3a;
  --violet: #c06cff;
  --panel: rgba(18, 16, 13, 0.88);
  --panel-strong: rgba(7, 7, 6, 0.94);
  --line: rgba(247, 236, 216, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(10, 8, 7, 0.5), rgba(10, 8, 7, 0.8)),
    url("/assets/frontend/boiler-room.png") center / cover fixed no-repeat,
    #12100f;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: var(--gold);
  color: #14100c;
  cursor: pointer;
  font-weight: 900;
  transition: transform 140ms ease, filter 140ms ease, background-color 140ms ease;
}

button:hover,
button:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  filter: grayscale(0.65);
  transform: none;
}

.game-shell {
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-columns: minmax(250px, 30vw) minmax(360px, 1fr) minmax(280px, 27vw);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 100vh;
  height: 100vh;
  padding: 12px;
  overflow: hidden;
}

#market-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
}

.top-bar,
.investor-panel,
.play-panel,
.truth-desk,
.close-trade-bar {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(9px);
}

.top-bar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
}

/* Utility sound toggle — sits to the right of the HUD. Deliberately not gold-
   filled like the game buttons so it reads as a chrome control, not an action. */
.mute-toggle {
  min-height: 44px;
  width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  border: 1px solid rgba(84, 216, 255, 0.4);
  border-radius: 8px;
  background: rgba(7, 9, 10, 0.74);
  color: var(--cyan);
  font-weight: 400;
}

.mute-toggle .snd-slash {
  display: none;
}

.mute-toggle[data-muted="true"] {
  color: rgba(247, 236, 216, 0.5);
  border-color: var(--line);
}

.mute-toggle[data-muted="true"] .snd-wave {
  display: none;
}

.mute-toggle[data-muted="true"] .snd-slash {
  display: inline;
}

.brand-stack {
  min-width: 0;
}

.kicker {
  margin: 0;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 1px 0 2px;
  color: #fff8e9;
  font-size: clamp(26px, 4.6vw, 56px);
  line-height: 0.95;
}

.core-message {
  margin: 0;
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
}

.hud-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 1fr));
  gap: 8px;
  min-width: min(560px, 55vw);
}

.hud-strip div {
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid rgba(84, 216, 255, 0.28);
  background: rgba(7, 9, 10, 0.74);
}

.hud-strip span {
  display: block;
  color: rgba(247, 236, 216, 0.64);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.hud-strip strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: #fff8e9;
  font-size: 16px;
}

#capital-readout {
  color: var(--green);
}

#clock-readout {
  color: var(--gold);
}

.investor-panel,
.play-panel,
.truth-desk {
  min-width: 0;
  min-height: 0;
}

.investor-panel {
  display: grid;
  /* Portrait sizes to its own landscape ratio (auto); the brief and hype meter follow.
     align-content keeps them balanced in whatever height the panel is given. */
  grid-template-rows: auto auto auto;
  align-content: center;
  gap: 12px;
  padding: 12px;
}

.portrait-frame {
  position: relative;
  min-height: 0;
  /* The square (256x256) source art has a stray strip of a different figure across the
     top ~20%. A landscape frame with the image anchored to the bottom (see img rule)
     trims exactly that strip via object-fit:cover -- full character width, no face cut --
     and stays short enough to leave room for the brief and hype meter below. */
  width: 100%;
  max-height: 100%;
  aspect-ratio: 5 / 4;
  overflow: hidden;
  border: 2px solid rgba(240, 191, 88, 0.58);
  border-radius: 6px;
  background: #211916;
  will-change: transform, opacity;
}

.portrait-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Anchor to the bottom so the landscape frame trims the stray top strip, never the
     character's face or glass. */
  object-position: center bottom;
}

.portrait-frame[data-state="cold"] {
  border-color: rgba(84, 216, 255, 0.62);
}

.portrait-frame[data-state="hooked"] {
  border-color: rgba(79, 212, 125, 0.74);
}

.portrait-frame[data-state="burned"] {
  border-color: rgba(232, 74, 58, 0.76);
}

.portrait-scrim {
  position: absolute;
  inset: auto 0 0;
  height: 34%;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.78), transparent);
  pointer-events: none;
}

.portrait-caption {
  position: absolute;
  inset: auto 10px 10px;
  display: grid;
  gap: 4px;
}

#portrait-state {
  width: fit-content;
  padding: 5px 8px;
  border: 1px solid rgba(84, 216, 255, 0.48);
  border-radius: 5px;
  background: rgba(6, 11, 12, 0.82);
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

#investor-name {
  color: #fff8e9;
  font-size: clamp(20px, 2.5vw, 30px);
  line-height: 1;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.75);
}

.investor-brief {
  min-height: 54px;
  margin: 0;
  color: rgba(247, 236, 216, 0.82);
  font-size: 14px;
  line-height: 1.35;
}

.hype-meter {
  display: grid;
  gap: 8px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 900;
}

.meter-track {
  height: 18px;
  overflow: hidden;
  border: 1px solid rgba(247, 236, 216, 0.44);
  border-radius: 5px;
  background: #181714;
}

#hype-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
  box-shadow: 0 0 18px rgba(79, 212, 125, 0.55);
}

.play-panel {
  display: grid;
  grid-template-rows: minmax(180px, 1fr) auto auto;
  gap: 12px;
  padding: 12px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  margin: 0;
  padding: 0 4px 0 0;
  overflow-y: auto;
  list-style: none;
}

.chat-log li {
  max-width: min(82%, 680px);
  padding: 10px 12px;
  border: 1px solid rgba(247, 236, 216, 0.18);
  border-radius: 6px;
  background: rgba(247, 236, 216, 0.08);
  line-height: 1.38;
}

.chat-log li.assistant::before,
.chat-log li.user::before {
  display: block;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 900;
}

.chat-log li.assistant::before {
  content: "INVESTOR";
  color: var(--gold);
}

.chat-log li.user {
  align-self: flex-end;
  border-color: rgba(84, 216, 255, 0.35);
  background: rgba(84, 216, 255, 0.1);
}

.chat-log li.user::before {
  content: "BROKER";
  color: var(--cyan);
}

.chat-log li.thinking {
  width: fit-content;
}

.chat-log li.thinking span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.4;
}

@media (prefers-reduced-motion: no-preference) {
  .chat-log li.thinking span {
    animation: thinking-pulse 1.2s infinite ease-in-out;
  }
  .chat-log li.thinking span:nth-child(2) {
    animation-delay: 0.2s;
  }
  .chat-log li.thinking span:nth-child(3) {
    animation-delay: 0.4s;
  }
}

@keyframes thinking-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.tactic-feedback {
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid rgba(232, 74, 58, 0.42);
  border-radius: 6px;
  background:
    linear-gradient(rgba(20, 10, 10, 0.78), rgba(20, 10, 10, 0.78)),
    url("/assets/frontend/alert-panel.png") center / cover no-repeat;
  color: #ffe0c8;
  line-height: 1.35;
}

.pitch-form {
  display: grid;
  grid-template-columns: 1fr 64px minmax(110px, 150px);
  gap: 10px;
}

#pitch-input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid rgba(247, 236, 216, 0.28);
  border-radius: 6px;
  background: #090908;
  color: #f7ecd8;
  padding: 12px;
}

/* Red mic button: overrides the gold base button. Sits between the pitch input
   and Push It; swaps its icon for a live countdown while recording. */
.mic-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 64px;
  padding: 0;
  border: 1px solid var(--red);
  background: var(--red);
  color: #fff0ec;
}

.mic-button[hidden] {
  display: none;
}

.mic-icon {
  display: block;
}

.mic-timer {
  display: none;
  font-size: 14px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.mic-button.is-recording .mic-icon {
  display: none;
}

.mic-button.is-recording .mic-timer {
  display: inline;
}

.mic-button.is-recording {
  border-color: var(--red);
  box-shadow: 0 0 22px rgba(232, 74, 58, 0.55);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(232, 74, 58, 0.45); }
  50% { box-shadow: 0 0 30px rgba(232, 74, 58, 0.8); }
}

@media (prefers-reduced-motion: reduce) {
  .mic-button.is-recording { animation: none; }
}

.truth-desk {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  justify-content: space-between;
}

.panel-heading h2 {
  margin: 0;
  color: var(--gold);
  font-size: 24px;
}

.panel-heading span {
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.red-flags-strip {
  display: grid;
  gap: 8px;
}

.red-flag {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid rgba(232, 74, 58, 0.42);
  border-radius: 6px;
  background: rgba(33, 8, 7, 0.7);
}

.red-flag strong {
  color: #ffd0c5;
  font-size: 13px;
}

.red-flag span {
  color: rgba(247, 236, 216, 0.72);
  font-size: 12px;
}

.dossier-content {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  color: rgba(247, 236, 216, 0.86);
  font-size: 14px;
  line-height: 1.45;
}

.dossier-content h2,
.dossier-content h3,
.dossier-content h4 {
  color: #ffe0a6;
}

.dossier-content ul {
  margin: 6px 0;
  padding-left: 18px;
}

.dossier-content li {
  margin: 3px 0;
}

/* Indented "  - " sub-bullets (finance phrasing, pushback, reframe hints) read as a
   quiet supporting note under their parent point rather than a flat dashed list. */
.dossier-content li.sub {
  list-style: none;
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
  color: rgba(247, 236, 216, 0.66);
  font-size: 13px;
}

.dossier-content p {
  margin: 7px 0;
}

.close-trade-bar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(360px, 46vw);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

#order-preview {
  display: block;
  margin-top: 3px;
  color: #fff8e9;
  font-size: 15px;
  line-height: 1.25;
}

.trade-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.trade-actions button[data-order-size] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 5px 6px;
  line-height: 1.05;
}

.trade-size-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.78;
}

.trade-size-amount {
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* Colour each Close-the-Trade size by how likely that order is to close: a safe bet
   reads green, a coin-flip yellow (the default gold), cold feet red. */
.trade-actions button.likelihood-likely {
  border-color: var(--green);
  background: var(--green);
  color: #06140b;
}

.trade-actions button.likelihood-even {
  border-color: var(--gold);
  background: var(--gold);
  color: #14100c;
}

.trade-actions button.likelihood-unlikely {
  border-color: var(--red);
  background: var(--red);
  color: #fff0ec;
}

.trade-actions button:last-child {
  border-color: rgba(84, 216, 255, 0.64);
  background: #112732;
  color: #c7f3ff;
}

.trade-actions button.is-spotlight {
  border-color: rgba(79, 212, 125, 0.85);
  box-shadow: 0 0 22px rgba(79, 212, 125, 0.5);
  animation: spotlight-pulse 1.4s ease-in-out infinite;
}

/* Keep the "move on" cue inviting even while disabled controls grey out. */
.trade-actions button.is-spotlight:disabled {
  filter: none;
}

@keyframes spotlight-pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(79, 212, 125, 0.4); }
  50% { box-shadow: 0 0 30px rgba(79, 212, 125, 0.7); }
}

@media (prefers-reduced-motion: reduce) {
  .trade-actions button.is-spotlight { animation: none; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 1040px) {
  body {
    overflow: auto;
  }

  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .top-bar,
  .close-trade-bar {
    grid-template-columns: 1fr;
  }

  .hud-strip {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .investor-panel {
    grid-template-rows: auto auto auto;
  }

  .portrait-frame {
    /* Single-column layout: undo the desktop height-driven sizing and let the portrait
       fill the column width again, capped so it never dominates the stacked view. */
    height: auto;
    width: 100%;
    max-height: 520px;
  }

  .play-panel {
    min-height: 520px;
  }

  .truth-desk {
    max-height: none;
    overflow: visible;
  }

  .dossier-content {
    max-height: 420px;
  }

  .trade-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .game-shell {
    padding: 8px;
    gap: 8px;
  }

  .hud-strip {
    grid-template-columns: 1fr;
  }

  .pitch-form {
    grid-template-columns: 1fr 64px;
  }

  .pitch-form button[type="submit"] {
    grid-column: 1 / -1;
  }

  .chat-log li {
    max-width: 100%;
  }

  .trade-actions {
    grid-template-columns: 1fr;
  }
}

/* Very short windows (wide-but-short, split-screen, etc.): stop pinning the shell to
   the viewport and let the page scroll, so the hype meter and trade bar can never be
   clipped off the bottom. */
@media (max-height: 620px) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .portrait-frame {
    height: auto;
    min-height: 240px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* --- Chrome buttons (rules / leaderboard) + modal system ------------------ */
.chrome-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: center;
}

.chrome-btn {
  min-height: 44px;
  width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(84, 216, 255, 0.4);
  border-radius: 8px;
  background: rgba(7, 9, 10, 0.74);
  color: var(--cyan);
  font-size: 18px;
  font-weight: 900;
}

.chrome-btn--trophy { font-size: 20px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 4, 3, 0.72);
  backdrop-filter: blur(6px);
  animation: modal-fade 180ms ease-out;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px 26px 24px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--panel-strong);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  animation: modal-rise 200ms ease-out;
}

.modal-card--wide { width: min(720px, 100%); }

.modal-card h2 {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 26px;
}

.modal-sub {
  margin: 0 0 16px;
  color: rgba(247, 236, 216, 0.78);
  font-size: 14px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 34px;
  width: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 9, 10, 0.8);
  color: var(--paper);
  font-size: 20px;
  line-height: 1;
}

.modal-primary {
  margin-top: 18px;
  width: 100%;
  padding: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .modal-primary { margin-top: 0; flex: 1; }

.modal-ghost {
  border: 1px solid var(--line);
  background: rgba(7, 9, 10, 0.7);
  color: var(--paper);
  padding: 12px 18px;
}

.rules-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 12px;
  color: rgba(247, 236, 216, 0.92);
  font-size: 15px;
  line-height: 1.45;
}

.rules-list strong { color: #fff8e9; }

.chip {
  display: inline-block;
  margin: 0 2px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  color: #0a0a08;
}

.chip--green { background: var(--green); }
.chip--gold { background: var(--gold); }
.chip--red { background: var(--red); color: #fff0ec; }

.submit-score {
  margin: 0 0 14px;
  color: var(--green);
  font-size: 18px;
  font-weight: 900;
}

#submit-name {
  width: 100%;
  min-height: 46px;
  padding: 12px;
  border: 1px solid rgba(247, 236, 216, 0.28);
  border-radius: 6px;
  background: #090908;
  color: #f7ecd8;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.lb-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 236, 216, 0.05);
  color: var(--paper);
  text-align: left;
  font-weight: 600;
}

.lb-row:hover,
.lb-row:focus-visible {
  border-color: var(--gold);
  filter: none;
  transform: none;
}

.lb-row:disabled { cursor: default; filter: none; }

.lb-rank { color: var(--gold); font-weight: 900; font-variant-numeric: tabular-nums; }
.lb-name { color: #fff8e9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name small { display: block; color: rgba(247, 236, 216, 0.55); font-size: 11px; font-weight: 700; }
.lb-dollars { color: var(--green); font-weight: 900; font-variant-numeric: tabular-nums; }

.lb-empty,
.lb-error {
  padding: 16px;
  color: rgba(247, 236, 216, 0.7);
  text-align: center;
}

.viewer-body {
  display: grid;
  gap: 18px;
  max-height: 64vh;
  overflow-y: auto;
}

.viewer-investor h3 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 16px;
}

.viewer-investor h3 span {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 800;
  color: rgba(247, 236, 216, 0.6);
  text-transform: uppercase;
}

.viewer-chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.viewer-chat li {
  max-width: 86%;
  padding: 8px 11px;
  border: 1px solid rgba(247, 236, 216, 0.16);
  border-radius: 6px;
  background: rgba(247, 236, 216, 0.07);
  font-size: 14px;
  line-height: 1.36;
}

.viewer-chat li.user {
  align-self: flex-end;
  border-color: rgba(84, 216, 255, 0.32);
  background: rgba(84, 216, 255, 0.1);
}

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-rise { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
