:root {
  color-scheme: dark;
  --paper: #f1e2cc;
  --muted: #c2b4a2;
  --edge: #4d4035;
  --line: #66513c64;
  --serif: 'Spectral', Georgia, serif;
  --chat-height: 100dvh;
  --chat-top: 0px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
.chat-page { background: #0b0a0a; color: var(--paper); font: 400 17px/1.35 var(--serif); }
.chat-page button, .chat-page textarea { font: inherit; color: inherit; }
.chat-page button, .chat-page a, .chat-page textarea, .chat-page summary { touch-action: manipulation; }
.chat-page button:not(:disabled), .chat-page summary { cursor: pointer; }
.chat-page a { color: inherit; text-decoration: none; }
.chat-page :is(button, a, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid #e6a4a0;
  outline-offset: -3px;
}
.chat-page [hidden], [data-chronicle='game'] [data-demo-only],
[data-chronicle='sample'] [data-game-only] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.chat-shell {
  --layout-columns: minmax(0, 24fr) minmax(0, 46fr) minmax(0, 30fr);
  --layout-gap: 9px;
  --layout-gutter: 10px;
  position: fixed;
  inset: var(--chat-top) 0 auto;
  height: var(--chat-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(ellipse at 48% 70%, #151212, #080808 76%);
}

.chat-header {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: var(--layout-columns);
  column-gap: var(--layout-gap);
  align-items: center;
  flex: none;
  min-height: 68px;
  padding-inline: var(--layout-gutter);
  border-bottom: 1px solid var(--edge);
  background: #0a0909;
}

.chat-header::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0 0 0 auto;
  width: min(58%, 1050px);
  background: url('/assets/chat/chicago-skyline.webp') right center / cover no-repeat;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 38%);
  mask-image: linear-gradient(90deg, transparent, #000 38%);
  pointer-events: none;
}

.chat-brand {
  margin: 0 0 0 clamp(6px, 1.55vw, 27px);
  font-size: clamp(25px, 2.3vw, 39px);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.header-character {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(17px, 1.48vw, 25px);
  white-space: nowrap;
}
.header-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding-right: clamp(5px, 1.5vw, 25px);
}
.connection-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid #8c75615e;
  border-radius: 4px;
  background: #0b0a0ad9;
}
.chat-page .connection-control, .mobile-status { font: 400 11px/1.3 'PT Sans', sans-serif; letter-spacing: .07em; }
.connection-dot { width: 6px; height: 6px; border-radius: 50%; background: #dfad77; }
[data-chat-mode='live'] .connection-dot { background: #94bc98; }
[data-chat-mode='error'] .connection-dot { background: #ed8a83; }
.menu-control, .mobile-status { display: none; }
.game-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--layout-columns);
  gap: var(--layout-gap);
  padding: 8px var(--layout-gutter) 15px;
}

.game-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: radial-gradient(ellipse at 47% 42%, #141313, #0b0b0b 85%);
  box-shadow: inset 0 0 0 1px #d3a4890a;
}
.sidebar { min-height: 0; scrollbar-width: thin; scrollbar-color: #514337 transparent; }
.journal-column { overflow: auto; }
#game-journal { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; min-height: 100%; }
.world-column { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; overflow: auto; }
.panel-heading, .scene-heading h2 {
  margin: 0;
  font-size: clamp(21px, 1.95vw, 33px);
  font-weight: 500;
  line-height: 1.1;
}
.panel-heading { padding: clamp(12px, 1.13vw, 19px) clamp(14px, 1.65vw, 28px); border-bottom: 1px solid var(--line); }
.journal-nav { display: grid; padding-bottom: 8px; }
.journal-nav button {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 2px solid transparent;
  padding: 7px clamp(12px, 2.2vw, 37px);
  min-height: clamp(32px, 5dvh, 47px);
  background: transparent;
  font-size: clamp(15px, 1.35vw, 23px);
  text-align: left;
}
.journal-nav button[aria-pressed='true'] {
  border-left-color: #c76767;
  background: linear-gradient(95deg, #45191c, #241314 60%, #130f0f);
}
.journal-nav button:hover, .chat-menu nav > :is(button, a):hover { background-color: #392122; }
.journal-content { min-height: 120px; overflow: auto; scrollbar-width: thin; scrollbar-color: #514337 transparent; }
.journal-page { min-width: 0; }
.journal-page > h3, .journal-page > ul, .journal-page > p { margin: 12px 16px; }
.journal-page > h3 { font-size: 1.23em; font-weight: 500; }
.journal-page > ul { padding-left: 22px; }
.journal-page .text-control { margin: 0 16px 12px; }
.note-filters {
  display: grid;
  grid-template-columns: 1fr 1.36fr 1fr;
  gap: 3px;
  padding: 14px clamp(6px, .83vw, 14px);
  border-bottom: 1px solid var(--line);
}
.note-filters button, .round-control, .menu-control, .text-control {
  border: 1px solid var(--edge);
  border-radius: 5px;
  padding: 6px;
  background: #121111;
}
.note-filters button { min-width: 0; min-height: 36px; font-size: clamp(12px, 1.15vw, 19px); }
.note-filters button[aria-pressed='true'], .send-control, .upload-button {
  border-color: #965257;
  background: linear-gradient(#3c161b, #220f12);
  box-shadow: inset 0 1px #ad68604d;
}
.journal-note { border-bottom: 1px solid var(--line); padding: 11px clamp(10px, 1.45vw, 24px) 13px; }
.journal-note summary { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; column-gap: 8px; list-style: none; }
.journal-note summary::-webkit-details-marker { display: none; }
.journal-note summary > span:first-child { font-weight: 500; font-size: clamp(15px, 1.24vw, 21px); }
.journal-note summary > small { margin-left: auto; color: var(--muted); font-size: .75em; }
.journal-note summary:hover > span:first-child { text-decoration: underline; text-underline-offset: 3px; }
.journal-note p { margin: 4px 0 0; color: #dfd1bd; font-size: clamp(13px, 1.06vw, 18px); }
.note-preview {
  flex-basis: 100%;
  margin-top: 3px;
  color: #dfd1bd;
  font-size: clamp(13px, 1.06vw, 18px);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.journal-note[open] .note-preview { display: none; }
.panel-empty { color: var(--muted); margin: 14px 16px; }

.chat-panel { display: flex; flex-direction: column; position: relative; overflow: hidden; }
.scene-heading {
  position: relative;
  flex: none;
  border-bottom: 1px solid var(--line);
  padding: clamp(12px, 1vw, 17px) clamp(15px, 1.4vw, 24px) 6px;
}
.scene-heading h2 { font-size: clamp(25px, 2.15vw, 37px); }
.scene-heading p { margin: 4px 0 0; color: var(--muted); font-size: clamp(15px, 1.23vw, 21px); }
.message-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  overflow-anchor: none;
  scrollbar-width: thin;
  scrollbar-color: #57453c transparent;
  padding: 4px clamp(13px, 1.25vw, 21px) 18px;
}
.message {
  display: block;
  padding: 13px 0 14px;
  border-bottom: 1px solid #8f776831;
}
.message:last-child { border-bottom: 0; }
.message-speaker {
  display: inline-block;
  min-width: 78px;
  margin: 0 0 2px;
  padding: 1px 16px;
  border-radius: 4px;
  background: linear-gradient(95deg, #381416, #291619);
  font-weight: 400;
  font-size: clamp(16px, 1.22vw, 21px);
}
.player .message-speaker { min-width: 68px; background: linear-gradient(95deg, #262525, #202020); }
.message-bubble { padding-left: clamp(6px, 1.35vw, 23px); }
.message-copy {
  margin: 0;
  font-size: clamp(16px, 1.27vw, 22px);
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-status { display: block; margin-top: 6px; color: var(--muted); font: 12px/1.35 'PT Sans', sans-serif; }
.message-status:empty, .chat-live-status:empty { display: none; }
.message[data-status='pending'] { opacity: .75; }
.message[data-status='failed'] .message-status { color: #f0a68f; }
.retry-message, .latest-messages { padding: 7px 12px; border: 1px solid #89504f; border-radius: 5px; background: #2a1416; }
.retry-message { margin-top: 8px; }
.latest-messages { position: absolute; z-index: 1; left: 50%; top: 58px; transform: translateX(-50%); max-width: 90%; white-space: nowrap; }
.chat-live-status { padding: 6px 15px; border-top: 1px solid var(--line); font: 13px/1.35 'PT Sans', sans-serif; color: #f0a68f; }
.chat-composer { flex: none; padding: clamp(9px, .9vw, 15px); border-top: 1px solid var(--line); }
.composer-frame { display: flex; align-items: flex-end; gap: 12px; }
.chat-page #chat-action {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  max-height: min(132px, 24dvh);
  padding: 10px 13px;
  border: 1px solid #85715d;
  border-radius: 7px;
  background: #151413;
  resize: none;
  font-size: clamp(16px, 1.2vw, 21px);
  line-height: 1.3;
  caret-color: #ee898b;
}
#chat-action::placeholder { color: #c6b6a2; opacity: 1; }
.send-control { flex: none; min-height: 48px; border-width: 1px; border-style: solid; border-radius: 7px; padding: 8px clamp(10px, 1.1vw, 18px); }
.send-control:disabled { opacity: .68; }
.send-control:not(:disabled):hover { background: #571d24; }

.atlas-panel { overflow: hidden; }
.atlas-panel a:hover { text-decoration: underline; text-underline-offset: 4px; }
.scene-map { position: relative; aspect-ratio: 15 / 11; overflow: hidden; background: #10191d; }
.scene-map img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lake-label {
  position: absolute;
  right: 4%;
  top: 39%;
  max-width: 23%;
  font-size: clamp(12px, 1.1vw, 19px);
  line-height: 1.12;
  text-align: center;
  color: #b4c9cd;
  font-style: italic;
  text-shadow: 0 1px 4px #000;
}
.map-pin {
  position: absolute;
  left: var(--pin-x);
  bottom: calc(100% - var(--pin-y));
  transform: translate(-50%, 35%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-height: 44px;
  border: 0;
  padding: 0 3px 8px;
  background: transparent;
  white-space: nowrap;
}
.map-pin::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #fff1db; box-shadow: 0 0 0 5px #0e0b09d9; }
.map-pin span { padding: 1px 6px; border-radius: 4px; background: #100e0ce8; font-size: clamp(12px, 1.1vw, 19px); }
.map-pin:hover span, .map-pin[aria-expanded='true'] span, .map-pin-succubus span { background: #47191ae8; }
.map-pin-succubus::after { box-shadow: 0 0 0 6px #632126, 0 0 0 8px #d89865aa, 0 0 18px 10px #ffc06a88; }
.map-pin-red { --pin-x: 31%; --pin-y: 67%; }
.map-pin-succubus { --pin-x: 58%; --pin-y: 56%; }
.map-pin-loop { --pin-x: 64%; --pin-y: 36%; }
.map-locations p { margin: 0; padding: 8px 15px; border-top: 1px solid var(--line); font-size: .85em; }

.inventory-panel { min-height: 135px; overflow: auto; scrollbar-width: thin; scrollbar-color: #514337 transparent; }
.inventory-list { margin: 0 clamp(11px, 1.7vw, 29px) 10px; }
.inventory-list div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.inventory-list dt, .inventory-list dd { margin: 0; font-size: clamp(15px, 1.2vw, 21px); }
.inventory-list dd { text-align: right; white-space: nowrap; }

.chat-dialog {
  width: min(440px, 100% - 26px);
  max-height: calc(100dvh - 36px);
  margin: auto;
  padding: 19px;
  border: 1px solid #816456;
  border-radius: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  background: linear-gradient(145deg, #201718, #100e0e 65%);
  color: var(--paper);
  box-shadow: 0 12px 60px #000c;
}
.chat-dialog::backdrop { background: #080607d9; backdrop-filter: blur(6px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.dialog-heading h2 { margin: 0; font-size: 25px; font-weight: 500; }
.chat-page .round-control { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0; font-size: 27px; line-height: 1; }
.chat-menu nav { display: flex; flex-direction: column; }
.chat-menu nav > :is(a, button) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 46px;
  padding: 8px 5px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}
.chat-menu nav span { color: #db9188; }
.chat-menu nav > .sidebar-menu-item { display: none; }
.chat-languages { display: flex; gap: 10px; margin-top: 14px; }
.chat-languages a { display: grid; place-items: center; min-width: 44px; min-height: 44px; opacity: .75; }
.chat-languages a[aria-current] { opacity: 1; border-bottom: 1px solid #bd6563; }
.text-control { padding: 7px 12px; min-height: 44px; }
.dialog-note, .info-dialog > p { line-height: 1.5; color: var(--muted); }
.avatar-preview { width: 110px; margin: 12px auto 0; }
.avatar-image { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border: 1px solid #9a5754; border-radius: 7px; }
.avatar-character-name, .file-note { text-align: center; }
.file-note { font-size: 13px; color: var(--muted); }
.upload-button { display: grid; place-items: center; min-height: 44px; padding: 8px; border: 1px solid #965257; border-radius: 5px; cursor: pointer; }
.avatar-dialog:has(#avatar-file:focus-visible) .upload-button { outline: 2px solid #e6a4a0; outline-offset: 2px; }
.remove-avatar { display: block; margin: 8px auto; padding: 8px; border: 0; background: transparent; text-decoration: underline; }
.avatar-feedback { color: #e6a4a0; }
.age-gate { z-index: 20; }

@media (min-width: 1050px) {
  .menu-control { display: flex; }
  .chat-page .menu-control { min-width: 38px; min-height: 38px; }
}

@media (max-width: 1049px) {
  .chat-header {
    display: flex;
    justify-content: space-between;
    min-height: 62px;
    padding: env(safe-area-inset-top, 0px) max(13px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    gap: 8px;
  }
  .chat-header::before { width: 70%; opacity: .75; }
  .chat-brand { margin: 0; font-size: clamp(22px, 5.8vw, 31px); }
  .header-controls { padding-right: 0; }
  .header-character, .connection-control, .sidebar { display: none; }
  .game-layout { display: flex; justify-content: center; padding: 0; }
  .chat-panel { width: min(100%, 680px); border-block: 0; border-radius: 0; }
  .scene-heading { padding: 11px 15px 8px; }
  .scene-heading h2 { padding-right: 73px; font-size: clamp(22px, 5.4vw, 28px); }
  .scene-heading p { margin-top: 2px; font-size: 14px; }
  .mobile-status { display: block; position: absolute; right: 15px; top: 14px; color: #dfad77; }
  .menu-control { display: flex; }
  .chat-menu nav > .sidebar-menu-item { display: flex; }
  .chat-composer { padding: 9px max(11px, env(safe-area-inset-right)) calc(9px + env(safe-area-inset-bottom, 0px)) max(11px, env(safe-area-inset-left)); }
  .composer-frame { gap: 8px; }
  .message { padding: 11px 0; }
  .message-speaker { padding-inline: 10px; min-width: 72px; }
  .message-bubble { padding-left: 0; }
  .message-copy { font-size: 17px; line-height: 1.38; }
  .panel-dialog .game-panel { overflow: visible; }
  .panel-dialog .atlas-panel { overflow: hidden; }
  .panel-dialog .panel-heading { font-size: 23px; }
  .panel-dialog .journal-nav button { min-height: 44px; font-size: 16px; }
  .panel-dialog .note-filters button { font-size: 15px; min-height: 44px; }
  .panel-dialog .journal-note p { font-size: 15px; }
  .keyboard-open .chat-header { display: none; }
  .keyboard-open .chat-composer { padding-bottom: 8px; }
}

.menu-control {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}
.menu-control span {
  display: block;
  width: 19px;
  height: 12px;
  border-block: 1px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat;
}
