:root {
  color-scheme: dark;
  --play-area-height: clamp(520px, calc(100vh - 124px), 780px);
  --ink: #12110f;
  --ink-2: #1b1715;
  --panel: rgba(25, 22, 20, 0.94);
  --paper: #f5ead8;
  --muted: #bcae9e;
  --lacquer: #9f2540;
  --lacquer-2: #d34a53;
  --teal: #1f8b84;
  --gold: #f0b85a;
  --line: rgba(245, 234, 216, 0.16);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(135deg, rgba(159, 37, 64, 0.28), transparent 34%),
    linear-gradient(225deg, rgba(31, 139, 132, 0.24), transparent 38%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 44px),
    var(--ink);
  color: var(--paper);
}

.version-footer {
  position: fixed;
  left: 50%;
  bottom: 4px;
  z-index: 8;
  transform: translateX(-50%);
  color: rgba(245, 234, 216, 0.52);
  font-size: 0.68rem;
  line-height: 1;
  pointer-events: none;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: wait;
  opacity: 0.64;
}

a {
  color: var(--gold);
}

code {
  color: var(--gold);
}

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(18, 17, 15, 0.78);
  box-shadow: var(--shadow);
}

.topbar h1,
.setup-panel h1,
.modal-panel h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
}

.eyebrow,
.side-label {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-action,
.ghost-action,
.command-line button,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--paper);
  background: var(--lacquer);
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-action:hover,
.ghost-action:hover,
.command-line button:hover,
.chip:hover {
  transform: translateY(-1px);
  background: var(--lacquer-2);
}

.ghost-action {
  background: transparent;
  border: 1px solid var(--line);
}

.ghost-action.danger {
  border-color: rgba(211, 74, 83, 0.55);
}

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(360px, 0.95fr) minmax(240px, 0.46fr);
  gap: 14px;
  align-items: start;
  min-height: 0;
}

.scene-pane,
.terminal-pane,
.side-pane,
.setup-panel,
.modal-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scene-pane {
  height: var(--play-area-height);
  min-height: 0;
  padding: 10px;
}

.scene-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 6px;
  background: #211b18;
}

.scene-frame img,
.scene-placeholder {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  display: block;
}

.scene-placeholder {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(155deg, rgba(31, 139, 132, 0.34), transparent 45%),
    linear-gradient(25deg, rgba(159, 37, 64, 0.5), transparent 44%),
    #201715;
}

.scene-placeholder::before {
  content: "";
  position: absolute;
  inset: 12% 12% auto auto;
  width: 34%;
  height: 18%;
  border: 2px solid rgba(240, 184, 90, 0.68);
  transform: skew(-10deg);
  background: rgba(18, 17, 15, 0.42);
}

.street-lines {
  position: absolute;
  inset: 42% 0 0;
  background:
    linear-gradient(115deg, transparent 0 38%, rgba(245, 234, 216, 0.13) 38.5% 39.5%, transparent 40%),
    repeating-linear-gradient(0deg, transparent 0 32px, rgba(245, 234, 216, 0.08) 32px 33px);
  transform: perspective(500px) rotateX(58deg) scale(1.3);
  transform-origin: top center;
}

.scene-caption {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  border-left: 4px solid var(--gold);
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(18, 17, 15, 0.82);
  backdrop-filter: blur(8px);
}

.scene-caption p,
.scene-caption h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.scene-caption p {
  color: var(--gold);
  font-size: 0.86rem;
  font-weight: 800;
}

.scene-caption h2 {
  margin-top: 2px;
  font-size: 1.35rem;
  line-height: 1.1;
}

.connection-badge {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid rgba(240, 184, 90, 0.52);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--paper);
  background: rgba(159, 37, 64, 0.62);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.connection-badge[hidden] {
  display: none;
}

.terminal-pane {
  height: var(--play-area-height);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.line {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.line-speaker {
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.line p {
  margin: 0;
  color: var(--paper);
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.line.player p {
  color: #a5e2dc;
}

.line.system p {
  color: var(--muted);
}

.command-line {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 10px;
  background: rgba(0, 0, 0, 0.16);
}

.command-line span {
  color: var(--gold);
  font-weight: 900;
}

.command-line input,
.inline-form input,
.setup-form input,
.account-form input,
.profile-form input,
.profile-form select,
.profile-form textarea,
.admin-form input,
.admin-form select,
.table-action input,
.table-action select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.06);
}

.command-line input:focus,
.inline-form input:focus,
.setup-form input:focus,
.account-form input:focus,
.profile-form input:focus,
.profile-form select:focus,
.profile-form textarea:focus,
.admin-form input:focus,
.admin-form select:focus,
.table-action input:focus,
.table-action select:focus {
  border-color: var(--gold);
}

.side-pane {
  height: var(--play-area-height);
  min-height: 0;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.status-block:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.connection-status {
  display: grid;
  gap: 8px;
}

.connection-name,
.connection-copy {
  margin: 0;
}

.connection-name {
  color: var(--paper);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.connection-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.level-pill,
.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(245, 234, 216, 0.14);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.level-pill {
  color: var(--ink);
  background: var(--gold);
}

.mode-pill {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
}

.mode-pill.side-quest {
  color: var(--paper);
  border-color: rgba(31, 139, 132, 0.72);
  background: rgba(31, 139, 132, 0.48);
}

.connection-copy {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.connection-details,
.connection-items,
.connection-quests {
  display: grid;
  gap: 7px;
}

.connection-detail,
.connection-item,
.mini-label {
  margin: 0;
}

.connection-detail {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.connection-detail span,
.mini-label {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.connection-detail strong {
  color: var(--paper);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.connection-item {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(245, 234, 216, 0.12);
  background: rgba(31, 139, 132, 0.34);
}

button.chip {
  color: var(--paper);
}

.quest-chip.current {
  border-color: rgba(240, 184, 90, 0.7);
  background: rgba(240, 184, 90, 0.24);
}

.muted {
  color: var(--muted);
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.map-row span:last-child {
  overflow-wrap: anywhere;
}

.map-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(245, 234, 216, 0.32);
}

.map-row.current {
  color: var(--paper);
  font-weight: 800;
}

.map-row.current .map-dot {
  background: var(--gold);
}

.map-row.side-quest .map-dot {
  background: var(--teal);
}

.map-row.side-quest span:last-child::after {
  content: " side";
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.start-panel {
  margin: auto;
  max-width: 460px;
  text-align: center;
  padding: 24px;
}

.start-panel h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.start-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 17, 15, 0.82);
  backdrop-filter: blur(10px);
}

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

.modal-panel {
  width: min(520px, 100%);
  padding: 22px;
}

.profile-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.modal-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.form-error,
.notice.error {
  color: #ffb1b1;
}

.login-backdrop {
  padding: 18px;
}

.login-panel {
  width: min(1080px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.78fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-art {
  min-height: 620px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #101010;
}

.login-art img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  overflow: auto;
  padding: 28px;
  background: rgba(18, 17, 15, 0.94);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card > p:not(.eyebrow):not(.fine-print):not(.form-error) {
  color: var(--muted);
  line-height: 1.48;
}

.account-form,
.profile-form,
.admin-form {
  display: grid;
  gap: 12px;
}

.account-form label,
.profile-form label,
.admin-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.account-form label span,
.profile-form label span,
.admin-form label span {
  color: var(--paper);
  font-weight: 800;
}

.profile-form textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.secondary-account-form {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.text-action {
  width: fit-content;
  padding: 0;
  color: var(--gold);
  background: transparent;
  font-weight: 800;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid rgba(240, 184, 90, 0.5);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--gold);
  background: rgba(240, 184, 90, 0.08);
  font-size: 0.86rem;
  font-weight: 900;
}

.user-badge[hidden] {
  display: none;
}

.setup-body,
.admin-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}

.setup-shell,
.admin-shell {
  width: min(980px, 100%);
}

.setup-panel,
.admin-panel {
  padding: 24px;
}

.setup-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.setup-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.setup-form label span {
  color: var(--paper);
  font-weight: 800;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.check-row {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.42fr) minmax(0, 1fr);
  gap: 16px;
}

.admin-stack {
  display: grid;
  gap: 16px;
  align-content: start;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.admin-table-wrap {
  overflow: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--gold);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.admin-table td {
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-table strong {
  color: var(--paper);
}

.table-action {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 8px;
  margin-bottom: 8px;
}

.table-action.single {
  grid-template-columns: 1fr;
}

.table-action button {
  min-height: 42px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 18px 0 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.notice.success {
  color: #a5e2dc;
}

.fine-print {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.48;
}

.is-busy .scene-frame::after {
  content: "";
  position: absolute;
  inset: auto 14px 14px auto;
  width: 26px;
  height: 26px;
  border: 3px solid rgba(245, 234, 216, 0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1120px) {
  :root {
    --play-area-height: clamp(500px, calc(100vh - 124px), 740px);
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.72fr);
  }

  .side-pane {
    grid-column: 1 / -1;
    height: auto;
    max-height: 240px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .status-block {
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding-right: 14px;
    padding-bottom: 0;
  }

  .status-block:last-child {
    border-right: 0;
  }

  .login-panel,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .login-art {
    min-height: 320px;
  }
}

@media (max-width: 760px) {
  :root {
    --play-area-height: auto;
  }

  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 150px;
  }

  .game-layout,
  .side-pane,
  .setup-grid,
  .profile-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .login-panel {
    max-height: calc(100vh - 20px);
  }

  .login-art {
    min-height: 220px;
  }

  .login-card {
    padding: 18px;
  }

  .admin-header {
    flex-direction: column;
  }

  .scene-frame,
  .scene-frame img,
  .scene-placeholder {
    height: min(64vh, 520px);
    min-height: 360px;
  }

  .terminal-pane {
    height: min(58vh, 520px);
    min-height: 430px;
  }

  .side-pane {
    height: auto;
    max-height: none;
  }

  .line {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .command-line,
  .inline-form {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .command-line button,
  .inline-form button {
    grid-column: 1 / -1;
  }

  .status-block {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 14px;
  }
}
