:root {
  color-scheme: light;
  --ink: #0b0a0f;
  --ink-2: #15121c;
  --modern-surface: rgba(255, 255, 255, 0.045);
  --modern-surface-2: rgba(255, 255, 255, 0.08);
  --modern-line: rgba(255, 255, 255, 0.09);
  --modern-text: #f4efe7;
  --modern-muted: #a79f97;
  --modern-faint: #6f6860;
  --modern-amber: #f4ad5c;
  --modern-ember: #e8744e;
  --modern-teal: #74b6bf;
  --modern-rose: #d98a8a;
  --modern-glow: rgba(244, 173, 92, 0.5);
  --modern-radius: 22px;
  --font-modern-display: "Shippori Mincho", serif;
  --font-modern-body: "Zen Kaku Gothic New", sans-serif;
  --bg: #fff9ea;
  --bg-deep: #f4ebd8;
  --surface: rgba(255, 252, 242, 0.86);
  --surface-strong: rgba(255, 252, 242, 0.96);
  --surface-subtle: rgba(244, 235, 216, 0.84);
  --text: #152033;
  --muted: #646b76;
  --muted-dim: #7a7566;
  --navy: #061b3a;
  --navy-soft: #123160;
  --navy-rgb: 18, 49, 96;
  --deep-navy-rgb: 6, 27, 58;
  --accent: #d99c2f;
  --accent-dark: #b98222;
  --accent-ink: #07162e;
  --accent-rgb: 185, 130, 34;
  --accent-dark-rgb: 138, 94, 24;
  --accent-soft-rgb: 255, 242, 184;
  --accent-hover-rgb: 246, 201, 91;
  --secondary-rgb: 51, 77, 143;
  --secondary-container-rgb: 232, 221, 189;
  --border: rgba(var(--navy-rgb), 0.16);
  --border-strong: rgba(var(--accent-rgb), 0.34);
  --assistant: rgba(255, 255, 255, 0.9);
  --user: linear-gradient(135deg, #fff2b8 0%, #fffdf6 100%);
  --violet: #334d8f;
  --violet-container: #fff2b8;
  --danger: #ba1a1a;
  --glass-blur: blur(22px);
  --panel-shadow: 0 24px 70px rgba(25, 28, 29, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.58);
  --soft-shadow: 0 14px 38px rgba(25, 28, 29, 0.09), 0 0 24px rgba(var(--accent-rgb), 0.08);
  --cyan-glow: 0 0 18px rgba(var(--accent-rgb), 0.16);
  --violet-glow: 0 0 18px rgba(var(--secondary-rgb), 0.16);
  --font-display: "Montserrat", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  --bottom-nav-height: 0px;
}

[data-theme="light"] {
  color-scheme: light;
  --ink: #f3ece2;
  --ink-2: #fbf6ee;
  --modern-surface: rgba(40, 28, 18, 0.04);
  --modern-surface-2: rgba(40, 28, 18, 0.07);
  --modern-line: rgba(40, 28, 18, 0.12);
  --modern-text: #2a2118;
  --modern-muted: #7c7064;
  --modern-faint: #a99d8e;
  --modern-glow: rgba(232, 116, 78, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 6%, rgba(var(--accent-soft-rgb), 0.68), transparent 32%),
    radial-gradient(circle at 88% 0%, rgba(var(--navy-rgb), 0.22), transparent 34%),
    linear-gradient(rgba(var(--navy-rgb), 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--navy-rgb), 0.035) 1px, transparent 1px),
    var(--bg);
  background-size:
    auto,
    auto,
    40px 40px,
    40px 40px;
  color: var(--text);
  font-family: var(--font-body);
}

body.ui-v2[data-theme="dark"],
body.ui-v2[data-theme="light"] {
  background:
    radial-gradient(1200px 800px at 15% -5%, rgba(232, 116, 78, 0.18), transparent 55%),
    radial-gradient(1000px 700px at 95% 10%, rgba(116, 182, 191, 0.12), transparent 50%),
    radial-gradient(900px 900px at 50% 120%, rgba(244, 173, 92, 0.10), transparent 55%),
    var(--ink);
  color: var(--modern-text);
  font-family: var(--font-modern-body);
}

body.ui-v2[data-theme="dark"]::after,
body.ui-v2[data-theme="light"]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.045;
  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='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: var(--border-strong);
  box-shadow: var(--cyan-glow);
  transform: translateY(-1px);
}

button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.is-loading::before,
.busy-spinner {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin 760ms linear infinite;
}

#loadButton.is-loading::before,
button[type="submit"].is-loading::before {
  border-color: rgba(255, 255, 255, 0.95);
  border-right-color: transparent;
}

button[type="submit"],
#loadButton {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 28px rgba(var(--accent-rgb), 0.22);
}

button[type="submit"]:hover,
#loadButton:hover {
  background: var(--accent-dark);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(var(--accent-rgb), 0.5);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

textarea {
  resize: none;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  line-height: 1.45;
}

.boot-splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(var(--navy-rgb), 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--navy-rgb), 0.045) 1px, transparent 1px),
    linear-gradient(180deg, #fffaf0 0%, var(--bg-deep) 100%);
  background-size:
    40px 40px,
    40px 40px,
    auto;
  transition:
    opacity 520ms ease,
    visibility 520ms ease;
}

.boot-splash[hidden] {
  display: none;
}

.boot-splash.is-hiding {
  opacity: 0;
  visibility: hidden;
}

.boot-copy {
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(520px, 100%);
  text-align: center;
  animation: bootRise 860ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.boot-mark {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 20px;
  box-shadow:
    0 16px 40px rgba(25, 28, 29, 0.12),
    0 0 0 1px rgba(var(--accent-rgb), 0.28);
}

.boot-icon {
  display: block;
  width: 68px;
  height: 68px;
  border-radius: 20px;
}

.boot-title {
  margin: 0;
  color: var(--navy);
  font-family: var(--font-display);
  font-size: clamp(40px, 7vw, 72px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
}

.boot-tagline {
  margin: 0;
  color: var(--text);
  font-size: clamp(18px, 3.2vw, 27px);
  font-weight: 700;
  line-height: 1.45;
}

.boot-subcopy {
  margin: -7px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.boot-rule {
  width: min(220px, 46vw);
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(var(--navy-rgb), 0.12);
}

.boot-rule span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: bootRule 1500ms ease-in-out infinite;
}

@keyframes bootRise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bootRule {
  0% {
    transform: translateX(-110%);
  }

  50% {
    transform: translateX(80%);
  }

  100% {
    transform: translateX(250%);
  }
}

@media (max-width: 560px) {
  .boot-copy {
    gap: 15px;
  }

  .boot-title {
    font-size: 44px;
  }

  .boot-tagline {
    font-size: 19px;
  }
}

.auth-view {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  color: var(--modern-text);
  background:
    radial-gradient(520px 340px at 80% 0%, rgba(232, 116, 78, 0.18), transparent 62%),
    radial-gradient(420px 360px at 8% 18%, rgba(116, 182, 191, 0.12), transparent 58%),
    linear-gradient(180deg, var(--ink-2), var(--ink));
}

.auth-view[hidden] {
  display: none;
}

.auth-card {
  width: min(760px, 100%);
  border: 1px solid var(--modern-line);
  border-radius: 24px;
  background: color-mix(in srgb, var(--modern-surface) 86%, transparent);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.22);
  padding: 26px;
  backdrop-filter: blur(18px);
}

.auth-card header {
  margin-bottom: 22px;
}

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

.auth-card h1 {
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 28px;
}

.auth-card p {
  margin-top: 6px;
  color: var(--modern-muted);
  font-size: 14px;
}

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

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-step {
  display: grid;
  gap: 12px;
}

.auth-step[hidden] {
  display: none;
}

.auth-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
}

.auth-form h2 {
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--modern-muted);
  font-size: 12px;
  font-weight: 600;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 286px minmax(420px, 1fr) 336px;
  gap: 14px;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  padding: 14px 14px calc(14px + var(--bottom-nav-height));
}

.app-shell[hidden] {
  display: none;
}

.app-shell.ui-v2 {
  display: block;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
}

.app-shell.ui-v2 > :not(#modernShell):not(#modernSheetBackdrop):not(#modernNewConversationSheet):not(#adminPane):not(dialog) {
  display: none !important;
}

/* Admin dashboard (admin-only) shows as a full-screen overlay over v2. */
.app-shell.ui-v2 #adminPane {
  position: fixed;
  inset: 0;
  z-index: 70;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
}
.app-shell.ui-v2 #adminPane[hidden] {
  display: none !important;
}

/* ---- v2: display-name (呼び名) editor ---- */
.modern-profile-info {
  flex: 1;
  min-width: 0;
}
.modern-edit-name {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--modern-line);
  background: var(--modern-surface);
  color: var(--modern-muted);
  font-size: 16px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.modern-edit-name:hover {
  color: var(--modern-amber);
  border-color: rgba(244, 173, 92, 0.5);
}
.modern-name-dialog {
  border: 1px solid var(--modern-line);
  border-radius: 20px;
  padding: 22px;
  max-width: 360px;
  width: calc(100vw - 48px);
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  color: var(--modern-text);
}
.modern-name-dialog::backdrop {
  background: rgba(5, 4, 8, 0.6);
  backdrop-filter: blur(3px);
}
.modern-name-dialog h3 {
  font-family: var(--font-modern-display);
  font-size: 19px;
  margin-bottom: 8px;
}
.modern-name-dialog p {
  color: var(--modern-muted);
  font-size: 12.5px;
  line-height: 1.6;
  margin-bottom: 14px;
}
.modern-name-dialog input {
  width: 100%;
  padding: 13px 15px;
  border-radius: 13px;
  border: 1px solid var(--modern-line);
  background: var(--modern-surface);
  color: var(--modern-text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.modern-name-dialog input:focus {
  border-color: var(--modern-amber);
}
.modern-name-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.modern-mini-btn {
  border: 0;
  cursor: pointer;
  padding: 11px 20px;
  border-radius: 12px;
  font-family: var(--font-modern-body);
  font-weight: 700;
  font-size: 13.5px;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  color: #1a0f06;
}
.modern-mini-btn.ghost {
  background: var(--modern-surface);
  color: var(--modern-text);
  border: 1px solid var(--modern-line);
}

/* New UI is gated behind the ui-v2 flag. By default (legacy UI) the modern
   shell and its sheets are hidden so the existing app works unchanged. */
.app-shell:not(.ui-v2) #modernShell,
.app-shell:not(.ui-v2) #modernNewConversationSheet,
.app-shell:not(.ui-v2) #modernSheetBackdrop {
  display: none !important;
}

.sidebar[hidden],
.memory-pane[hidden] {
  display: none !important;
}

.app-shell.hide-left {
  grid-template-columns: minmax(420px, 1fr) 336px;
}

.app-shell.hide-right {
  grid-template-columns: 286px minmax(420px, 1fr);
}

.app-shell.hide-left.hide-right {
  grid-template-columns: minmax(420px, 1fr);
}

.app-shell.edit-mode {
  grid-template-columns: minmax(420px, 1fr);
}

.app-shell.no-memory {
  grid-template-columns: 286px minmax(420px, 1fr);
}

.app-shell.hide-left.no-memory,
.app-shell.edit-mode.no-memory {
  grid-template-columns: minmax(420px, 1fr);
}

.app-shell.hide-left .sidebar,
.app-shell:not(.ui-v2).hide-right .memory-pane {
  display: none;
}

.sidebar,
.memory-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - 28px - var(--bottom-nav-height));
  overflow-y: auto;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  scrollbar-gutter: stable;
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--soft-shadow);
}

.sidebar {
  padding: 18px;
}

.memory-pane {
  overflow-x: hidden;
}

.brand {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 18px;
  padding-right: 44px;
}

.pane-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

.pane-close,
.floating-toggle {
  display: inline-grid;
  place-items: center;
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  background: rgba(var(--accent-soft-rgb), 0.78);
  border-color: rgba(var(--accent-rgb), 0.14);
}

.ui-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pane-close:hover,
.floating-toggle:hover {
  background: rgba(var(--accent-hover-rgb), 0.58);
  border-color: rgba(var(--accent-rgb), 0.26);
}

.floating-toggle {
  position: fixed;
  top: 86px;
  z-index: 20;
  width: 42px;
  min-width: 42px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  box-shadow: var(--soft-shadow);
}

.floating-toggle-left {
  left: 0;
  border-left: 0;
  border-radius: 0 16px 16px 0;
}

.floating-toggle-right {
  right: 0;
  border-right: 0;
  border-radius: 16px 0 0 16px;
}

.sidebar > .brand .pane-close {
  position: absolute;
  top: -2px;
  right: 0;
}

.memory-header .pane-close {
  position: absolute;
  top: 14px;
  left: 18px;
}

.floating-toggle[hidden],
.pane-close[hidden],
.mobile-backdrop[hidden] {
  display: none !important;
}

.mobile-backdrop {
  display: none;
}

.brand h1,
.chat-header h2,
.memory-header h2,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
  font-family: var(--font-display);
}

.brand h1 {
  font-size: 23px;
  line-height: 1.05;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(var(--accent-rgb), 0.12);
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: uppercase;
}

#memoryCount,
#secretDiaryCount,
.badge {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  min-height: 24px;
  border-radius: 999px;
  background: rgba(var(--accent-soft-rgb), 0.72);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  padding: 2px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.panel h2 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text);
}

.panel-help {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.conversation-start-row {
  margin: -2px 0 12px;
}

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

.resource-actions,
.creation-actions {
  display: grid;
  gap: 8px;
}

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

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

.management-panel {
  display: grid;
  gap: 12px;
}

.management-panel[hidden] {
  display: none;
}

.management-panel h2 {
  margin-bottom: 0;
}

.edit-navigation-panel {
  display: grid;
  gap: 10px;
}

.edit-navigation-panel h2 {
  margin-bottom: 0;
}

.management-group {
  display: grid;
  gap: 8px;
}

.management-group h3 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.management-group .character-actions,
.management-group .creation-actions {
  margin: 0;
}

.room-list {
  display: grid;
  gap: 8px;
  max-height: min(32dvh, 320px);
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-gutter: stable;
}

.room-list:empty::before {
  content: "まだルームはありません";
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.room-item {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 50px;
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
}

.room-item.active {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-soft-rgb), 0.72);
  box-shadow: var(--cyan-glow);
}

.room-item strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.room-item span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
}

.lorebook-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.lorebook-item {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 58px;
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
}

.lorebook-item strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.lorebook-item span,
.lorebook-item small {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
}

.lorebook-item small {
  color: var(--muted-dim);
}

.compact-empty {
  padding: 10px;
  min-height: 0;
}

.compact-empty strong {
  font-size: 13px;
}

.compact-empty span {
  font-size: 12px;
}

.room-notice {
  margin: 10px 0 0;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.45;
}

.room-notice[hidden] {
  display: none;
}

.secondary-action {
  width: 100%;
  margin: 0;
  background: rgba(var(--accent-soft-rgb), 0.62);
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.14);
}

.logout-button,
.admin-menu-button {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.admin-menu-button {
  margin-bottom: 8px;
}

.account-panel {
  margin-top: 18px;
}

.account-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.account-list div {
  display: grid;
  gap: 4px;
}

.account-list dt {
  color: var(--muted-dim);
  font-size: 11px;
  font-weight: 600;
}

.account-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

.advanced-settings {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.advanced-settings summary {
  cursor: pointer;
  padding: 4px 0 8px;
}

.advanced-settings label {
  margin-bottom: 12px;
}

.advanced-settings label:last-child {
  margin-bottom: 0;
}

#advancedRoomFields:not(:empty) {
  margin-bottom: 12px;
}

.profile-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.selected-profile {
  gap: 8px;
  margin: 0;
}

.selected-resource {
  display: grid;
  gap: 8px;
  margin: -2px 0 14px;
  padding: 0 0 12px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.12);
}

.selected-resource-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.selected-resource h3 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.visibility-pill {
  min-width: 0;
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--accent);
  background: rgba(var(--accent-soft-rgb), 0.62);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.selection-hint {
  margin: -2px 0 0;
  color: var(--muted-dim);
  font-size: 11px;
  line-height: 1.45;
}

.modal-resource-summary {
  display: grid;
  gap: 4px;
  margin: 0 0 12px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.12);
  padding-bottom: 12px;
}

.modal-resource-summary span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.modal-resource-summary strong {
  color: var(--text);
  font-size: 15px;
}

.group-mode-toggle {
  display: flex;
  width: fit-content;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
}

.group-mode-toggle input {
  width: auto;
  accent-color: var(--accent);
}

.participant-picker {
  display: grid;
  gap: 8px;
  margin: 0 0 10px;
}

.participant-picker[hidden] {
  display: none;
}

.participant-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  padding: 8px 10px;
}

.selected-participant {
  display: grid;
  align-items: stretch;
}

.participant-choice-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.participant-addressing-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-left: 52px;
}

.participant-addressing-field {
  display: grid;
  gap: 4px;
}

.participant-addressing-field span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.participant-addressing-field input {
  flex: initial;
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 7px 9px;
  font-size: 12px;
}

.participant-avatar {
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 15px;
  font-weight: 700;
}

.participant-avatar.has-image {
  overflow: hidden;
  padding: 0;
  background: rgba(255, 255, 255, 0.78);
}

.participant-avatar .character-avatar-image {
  object-fit: contain;
  object-position: center center;
}

.participant-choice input {
  flex: 0 0 auto;
  width: auto;
  accent-color: var(--accent);
}

.participant-choice-text {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.participant-choice-text strong,
.participant-choice-text span {
  overflow-wrap: anywhere;
}

.participant-choice-text strong {
  font-size: 13px;
}

.participant-choice-text span {
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 560px) {
  .participant-addressing-fields {
    grid-template-columns: 1fr;
    margin-left: 0;
  }
}

.profile-list div {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
}

.profile-list dt {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.profile-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.center-view,
.chat-pane,
.edit-pane,
.admin-pane {
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - 28px - var(--bottom-nav-height));
  background: rgba(255, 252, 242, 0.82);
  backdrop-filter: var(--glass-blur);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--panel-shadow);
}

.center-view[hidden],
.chat-pane[hidden],
.edit-pane[hidden],
.admin-pane[hidden] {
  display: none;
}

.center-view {
  display: grid;
  place-items: center;
  padding: 22px;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 50% 0%, rgba(var(--accent-soft-rgb), 0.48), transparent 34%),
    linear-gradient(180deg, #fff9ea 0%, #f4ebd8 100%);
}

.center-view-inner {
  width: min(880px, 100%);
}

.welcome-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.welcome-avatar {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.welcome-copy {
  min-width: 0;
}

.center-eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.welcome-copy h2,
.center-section-header h2 {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
}

.welcome-message {
  max-width: 660px;
  margin: 18px 0 0;
  padding: 16px 18px;
  border: 1px solid rgba(var(--accent-rgb), 0.1);
  border-left: 4px solid var(--violet);
  border-radius: 18px;
  background: var(--assistant);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  box-shadow: var(--violet-glow);
}

.center-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.center-actions button {
  min-width: 168px;
}

.launcher-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  height: min(760px, 100%);
  min-height: 0;
}

.launcher-grid .view-notice {
  grid-column: 1 / -1;
}

.view-notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(var(--accent-rgb), 0.16);
  border-radius: 12px;
  background: rgba(var(--accent-soft-rgb), 0.68);
  color: var(--accent);
  font-size: 13px;
  line-height: 1.45;
}

.view-notice.error {
  border-color: rgba(186, 26, 26, 0.22);
  background: rgba(255, 218, 214, 0.58);
  color: var(--danger);
}

.view-notice[hidden] {
  display: none;
}

.app-update-notice {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom) + var(--bottom-nav-height));
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(var(--accent-rgb), 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--soft-shadow);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.app-update-notice[hidden] {
  display: none;
}

.app-update-notice span {
  min-width: 0;
}

.app-update-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.app-update-actions button {
  min-height: 34px;
  border-radius: 8px;
}

#appUpdateReloadButton {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.launcher-character-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.launcher-selection-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 0 0 12px;
}

.launcher-selection-actions button {
  min-width: 168px;
}

.center-section-header {
  margin-bottom: 14px;
}

.center-section-header span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.35;
}

.launcher-character-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.launcher-character-card {
  position: relative;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 142px;
  align-items: start;
  justify-items: start;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.launcher-character-card.has-image {
  grid-template-columns: 96px minmax(0, 1fr);
  min-height: 142px;
}

.launcher-character-card.active {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-soft-rgb), 0.78);
  box-shadow: var(--cyan-glow);
}

.launcher-character-profile-button {
  position: absolute;
  top: 9px;
  right: 9px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border-radius: 999px;
  border-color: rgba(var(--accent-rgb), 0.18);
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent);
  box-shadow: 0 8px 18px rgba(25, 28, 29, 0.08);
  touch-action: manipulation;
  z-index: 2;
}

.launcher-character-profile-button:hover,
.launcher-character-profile-button:focus-visible {
  background: rgba(var(--accent-soft-rgb), 0.96);
  border-color: rgba(var(--accent-rgb), 0.32);
}

.launcher-character-profile-button .ui-icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.4;
}

.launcher-character-avatar {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 22px;
  font-weight: 700;
}

.launcher-character-card.has-image .launcher-character-avatar {
  width: 96px;
  height: 96px;
  border-radius: 16px;
}

.launcher-character-card .character-avatar-image {
  object-fit: contain;
  object-position: center center;
}

.character-avatar-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-image-preview {
  width: 112px;
  height: 112px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
}

.character-image-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-avatar.has-image,
.bubble-avatar.has-image,
.message-meta-avatar.has-image,
.launcher-character-avatar.has-image {
  overflow: hidden;
  padding: 0;
  background: rgba(255, 255, 255, 0.78);
}

.launcher-character-card strong {
  color: var(--text);
  font-size: 14px;
  line-height: 1.25;
}

.launcher-character-text {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding-right: 68px;
}

.launcher-character-meta,
#characterActionMeta,
#characterProfileMeta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
}

.launcher-character-persona {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted-dim);
  font-size: 12px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.group-mode-toggle[hidden] {
  display: none;
}

.private-character-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(var(--accent-soft-rgb), 0.86);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
}

.private-character-icon {
  width: 12px;
  height: 12px;
  stroke-width: 2.2;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.character-action-dialog {
  position: fixed;
  inset: 0;
  width: min(440px, calc(100vw - 28px));
  max-height: min(720px, calc(100dvh - 28px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  backdrop-filter: var(--glass-blur);
}

.character-action-dialog::backdrop {
  background: rgba(63, 72, 74, 0.2);
  backdrop-filter: blur(6px);
}

.character-action-sheet {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: min(720px, calc(100dvh - 28px));
}

.character-action-header {
  align-items: flex-start;
}

.character-action-profile {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  align-items: center;
}

.character-action-profile h2,
#characterActionMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-action-body {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 12px;
}

.character-action-new {
  min-height: 48px;
  background: rgba(var(--accent-soft-rgb), 0.82);
  border-color: rgba(var(--accent-rgb), 0.2);
  color: var(--accent);
  font-size: 14px;
}

.character-action-continue {
  display: grid;
  gap: 8px;
  min-height: 0;
}

.character-action-continue h3 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.character-action-room-list {
  max-height: min(44dvh, 360px);
}

.character-action-room-list[hidden] {
  display: none;
}

.character-action-empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed rgba(127, 141, 143, 0.32);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.dialog-actions.character-action-footer {
  grid-template-columns: 1fr;
}

.character-profile-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(720px, calc(100dvh - 24px));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  backdrop-filter: var(--glass-blur);
}

.character-profile-dialog::backdrop {
  background: rgba(63, 72, 74, 0.18);
  backdrop-filter: blur(6px);
}

.character-profile-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: min(720px, calc(100dvh - 24px));
}

.character-profile-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.character-profile-title h2,
#characterProfileMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-profile-title .launcher-character-avatar.has-image {
  width: 68px;
  height: 68px;
  border-radius: 14px;
}

.character-profile-body {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.exploration-note-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: min(760px, calc(100dvh - 24px));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  backdrop-filter: var(--glass-blur);
}

.exploration-note-dialog::backdrop {
  background: rgba(63, 72, 74, 0.18);
  backdrop-filter: blur(6px);
}

.exploration-note-sheet {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: min(760px, calc(100dvh - 24px));
}

.exploration-note-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 253, 253, 0.78);
}

.exploration-note-tabs button {
  min-height: 36px;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
  font-size: 12px;
}

.exploration-note-tabs button.active {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.24);
  background: rgba(var(--accent-soft-rgb), 0.82);
}

.exploration-note-body {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 18px;
}

.note-section {
  display: grid;
  gap: 8px;
}

.note-section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.note-section-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.25;
}

.note-section-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.note-section-heading span {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  background: rgba(var(--accent-soft-rgb), 0.68);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 7px;
}

.note-entry-grid {
  display: grid;
  gap: 8px;
}

.note-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.note-entry-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.note-entry-title strong {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.note-entry-title span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(127, 141, 143, 0.1);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
}

.note-entry-main small,
.note-entry-main p {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.note-insert-chip {
  min-height: 32px;
  border-radius: 8px;
  padding: 5px 10px;
  color: var(--accent);
  background: rgba(var(--accent-soft-rgb), 0.72);
  box-shadow: none;
  font-size: 12px;
}

.note-empty {
  display: grid;
  gap: 6px;
  place-items: center;
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.note-empty.inline {
  place-items: start;
  padding: 12px;
  border: 1px dashed rgba(127, 141, 143, 0.24);
  border-radius: 8px;
  text-align: left;
}

.note-empty strong {
  color: var(--text);
  font-size: 14px;
}

.note-empty span {
  font-size: 12px;
}

.note-map-section {
  display: grid;
  gap: 12px;
}

.note-map-scroll {
  min-width: 0;
  overflow: auto;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.82)),
    repeating-linear-gradient(
      0deg,
      rgba(127, 141, 143, 0.08) 0,
      rgba(127, 141, 143, 0.08) 1px,
      transparent 1px,
      transparent 32px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(127, 141, 143, 0.08) 0,
      rgba(127, 141, 143, 0.08) 1px,
      transparent 1px,
      transparent 32px
    );
}

.note-map-canvas {
  position: relative;
  min-width: 100%;
}

.note-map-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.note-map-edge {
  stroke: rgba(127, 141, 143, 0.44);
  stroke-linecap: round;
  stroke-width: 5;
}

.note-map-edge.status-current,
.note-map-edge.status-visited {
  stroke: rgba(var(--accent-rgb), 0.56);
}

.note-map-edge.status-available {
  stroke: rgba(var(--accent-dark-rgb), 0.56);
  stroke-dasharray: 8 8;
}

.note-map-node {
  position: absolute;
  z-index: 2;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  width: 118px;
  min-height: 54px;
  padding: 8px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 20px rgba(48, 61, 64, 0.12);
  text-align: left;
  transform: translate(-50%, -50%);
}

.note-map-node:hover,
.note-map-node:focus-visible {
  border-color: var(--border-strong);
  box-shadow: 0 10px 24px rgba(48, 61, 64, 0.15);
  transform: translate(-50%, -50%);
}

.note-map-node strong,
.note-map-node small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-map-node strong {
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}

.note-map-node small {
  grid-column: 2;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.note-map-dot {
  grid-row: 1 / span 2;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(127, 141, 143, 0.7);
}

.note-map-node.status-current {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-soft-rgb), 0.96);
}

.note-map-node.status-current .note-map-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.14);
}

.note-map-node.status-visited .note-map-dot {
  background: rgba(var(--accent-rgb), 0.58);
}

.note-map-node.status-available {
  border-color: rgba(var(--accent-dark-rgb), 0.28);
}

.note-map-node.status-available .note-map-dot {
  background: rgb(var(--accent-dark-rgb));
  box-shadow: 0 0 0 4px rgba(var(--accent-dark-rgb), 0.12);
}

.note-map-node.selected {
  outline: 3px solid rgba(var(--accent-rgb), 0.18);
  outline-offset: 2px;
}

.note-map-node-action {
  position: absolute;
  z-index: 3;
  width: 104px;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

.note-map-node-action:hover,
.note-map-node-action:focus-visible {
  transform: translate(-50%, -50%);
}

.note-map-node-action.status-visited {
  background: rgba(255, 255, 255, 0.94);
}

.note-map-node-action.status-available {
  border-color: rgba(var(--accent-dark-rgb), 0.24);
  background: rgba(255, 247, 235, 0.96);
  color: rgb(120, 72, 10);
}

.note-map-detail {
  display: grid;
  gap: 12px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.12);
  padding-top: 12px;
}

.note-map-detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.note-map-detail-header small,
.note-map-detail-header p {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.note-map-detail-grid {
  display: grid;
  gap: 12px;
}

.note-map-mini-list {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 8px;
  background: rgba(248, 253, 253, 0.68);
}

.note-map-mini-list h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 0 0 8px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.12);
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
}

.note-map-mini-list h4 span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.note-map-mini-list h4 small {
  flex: 0 0 auto;
  min-width: 22px;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  padding: 3px 7px;
  text-align: center;
}

.note-map-mini-list > div {
  display: grid;
  gap: 0;
}

.note-map-mini-list .note-entry {
  min-height: 0;
  border-width: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px 0;
  box-shadow: none;
}

.note-map-mini-list .note-entry + .note-entry {
  border-top: 1px solid rgba(127, 141, 143, 0.14);
}

.note-map-mini-list .note-empty.inline {
  border-color: rgba(127, 141, 143, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.58);
}

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

.character-profile-facts div,
.character-profile-section {
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  padding: 10px;
}

.character-profile-facts dt,
.character-profile-section h3 {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: uppercase;
}

.character-profile-facts dd,
.character-profile-section p,
.character-profile-section ul {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}

.character-profile-section ul {
  padding-left: 18px;
}

.character-profile-section li + li {
  margin-top: 4px;
}

.profile-loading {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.edit-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 22px;
}

.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.edit-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
}

.edit-back-button {
  width: auto;
  min-width: 118px;
}

.edit-resource-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding-top: 16px;
}

.edit-resource-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.edit-resource-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.edit-resource-heading h3 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.edit-resource-heading button {
  min-width: 64px;
  min-height: 34px;
}

.edit-resource-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.edit-resource-item {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 64px;
  justify-items: start;
  padding: 10px;
  text-align: left;
  background: rgba(255, 255, 255, 0.74);
}

.edit-resource-character {
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
}

.edit-resource-item .edit-resource-avatar {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(var(--accent-soft-rgb), 0.72), rgba(var(--secondary-rgb), 0.12));
  border: 1px solid rgba(var(--accent-rgb), 0.22);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.edit-resource-item .edit-resource-avatar.has-image {
  background: rgba(255, 255, 255, 0.82);
}

.edit-resource-text {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.edit-resource-item strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
}

.edit-resource-item span,
.edit-resource-item small {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
}

.edit-resource-item.active {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-soft-rgb), 0.72);
}

.admin-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 22px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
}

.admin-toolbar {
  display: grid;
  grid-template-columns: 120px 84px 118px;
  align-items: end;
  gap: 8px;
}

.admin-toolbar label {
  margin: 0;
}

.admin-toolbar button,
.admin-toolbar select {
  min-height: 38px;
}

.admin-dashboard {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding-top: 16px;
}

.admin-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.admin-meta span,
.admin-meta time {
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 999px;
  background: rgba(var(--accent-soft-rgb), 0.62);
  padding: 4px 8px;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.admin-tab,
.admin-trend-chip {
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.admin-tab {
  min-height: 34px;
  padding: 0 12px;
}

.admin-tab.is-active,
.admin-trend-chip.is-active {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--text);
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.admin-metric {
  min-width: 0;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
}

.admin-metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

.admin-metric strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.1;
}

.admin-section {
  min-width: 0;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.admin-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-section-heading h3 {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.admin-daily-list {
  display: grid;
  gap: 7px;
}

.admin-daily-row {
  display: grid;
  grid-template-columns: 88px minmax(80px, 1fr) 64px 44px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.admin-daily-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.08);
}

.admin-daily-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--violet));
}

.admin-daily-row strong,
.admin-daily-row small {
  text-align: right;
}

.admin-trend-section {
  display: grid;
  gap: 12px;
}

.admin-trend-section .admin-section-heading {
  margin-bottom: 0;
}

.admin-section-heading span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.admin-trend-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-trend-chip {
  min-height: 32px;
  padding: 0 10px;
}

.admin-trend-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.admin-trend-chart {
  display: flex;
  align-items: stretch;
  gap: 4px;
  min-height: 250px;
  overflow-x: auto;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  padding: 12px 10px 8px;
}

.admin-trend-bar {
  flex: 1 0 14px;
  min-width: 10px;
  height: 228px;
  display: grid;
  grid-template-rows: 1fr 16px;
  align-items: end;
  gap: 6px;
}

.admin-trend-fill {
  width: 100%;
  align-self: end;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, var(--accent), var(--violet));
  box-shadow: 0 8px 18px rgba(var(--accent-rgb), 0.12);
}

.admin-trend-label {
  min-height: 16px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

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

.admin-table-section {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.1);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}

.admin-table td {
  max-width: 180px;
  overflow-wrap: anywhere;
}

.admin-table td.admin-identity-cell {
  padding-top: 6px;
  padding-bottom: 6px;
}

.admin-identity {
  display: grid;
  gap: 2px;
  min-width: 0;
  line-height: 1.15;
}

.admin-identity-id {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10px;
}

.admin-identity-name {
  color: var(--muted);
  font-size: 10px;
}

.admin-identity-id,
.admin-identity-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-table td:not(:first-child),
.admin-table th:not(:first-child) {
  text-align: right;
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 25;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: min(360px, calc(100vw - 28px));
  min-height: 56px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(24px);
  box-shadow: var(--soft-shadow);
  transform: translateX(-50%);
}

.bottom-nav-button {
  display: grid;
  grid-template-columns: 18px max-content;
  gap: 7px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
}

.bottom-nav-button.active {
  color: var(--accent);
  background: rgba(var(--accent-soft-rgb), 0.82);
  border-color: rgba(var(--accent-rgb), 0.22);
}

.bottom-nav-button span {
  font-size: 12px;
  line-height: 1;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(var(--deep-navy-rgb), 0.96), rgba(var(--navy-rgb), 0.92));
  backdrop-filter: blur(18px);
  box-shadow: 0 8px 26px rgba(25, 28, 29, 0.1), 0 0 18px rgba(var(--accent-rgb), 0.1);
  padding: 13px 16px;
  min-height: 68px;
}

.chat-header p {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: rgba(var(--accent-soft-rgb), 0.76);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.chat-header h2 {
  min-width: 0;
  overflow: visible;
  font-size: 18px;
  line-height: 1.15;
  color: var(--violet-container);
  text-overflow: clip;
  white-space: normal;
}

.chat-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.chat-title > div:last-child {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 3px;
  max-width: 100%;
}

.chat-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff2b8, #d99c2f);
  color: var(--accent-ink);
  font-weight: 700;
  border: 1px solid rgba(var(--accent-soft-rgb), 0.54);
  box-shadow: 0 0 20px rgba(var(--accent-hover-rgb), 0.32);
}

.group-avatar-stack {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 4px;
}

.group-avatar-stack .group-avatar-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: -5px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
}

.group-avatar-stack .group-avatar-dot:first-child {
  margin-left: 0;
}

.header-icon-button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(var(--accent-soft-rgb), 0.3);
  border-radius: 999px;
  background: rgba(var(--accent-soft-rgb), 0.15);
  color: var(--accent);
  box-shadow: 0 8px 18px rgba(2, 11, 24, 0.18);
}

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

.header-icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.header-icon-button .ui-icon {
  width: 19px;
  height: 19px;
}

.view-controls {
  display: none;
}

.mobile-header-button {
  display: none;
}

.scenario-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  padding: 7px 12px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.1);
  background: rgba(255, 252, 242, 0.82);
  backdrop-filter: blur(18px);
}

.scenario-bar[hidden] {
  display: block;
  min-height: 0;
  height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  visibility: hidden;
}

.scenario-bar[hidden] > * {
  display: none;
}

.crisis-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.12);
  background: rgba(248, 244, 232, 0.94);
  color: var(--text);
  backdrop-filter: blur(18px);
}

.crisis-banner[hidden] {
  display: none;
}

.crisis-banner-text {
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.55;
}

.crisis-banner-text a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.crisis-banner-dismiss {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 999px;
  box-shadow: none;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

/* ===== ST-039 P0 modern shell ===== */

.modern-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  color: var(--modern-text);
  background:
    radial-gradient(540px 360px at 80% -8%, rgba(232, 116, 78, 0.16), transparent 60%),
    radial-gradient(440px 380px at -10% 18%, rgba(116, 182, 191, 0.10), transparent 55%),
    linear-gradient(180deg, var(--ink-2), var(--ink));
  overflow: hidden;
}

.modern-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.modern-screen {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.modern-screen::-webkit-scrollbar,
.modern-scroll::-webkit-scrollbar,
.modern-rail::-webkit-scrollbar {
  display: none;
}

.modern-screen.is-active {
  display: flex;
  animation: modernScreenIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes modernScreenIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modern-scroll {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 20px 20px 120px;
}

.modern-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

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

.modern-mark {
  display: block;
  margin-bottom: 5px;
  color: var(--modern-amber);
  font-family: var(--font-modern-display);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-transform: uppercase;
}

.modern-brand h1 {
  margin: 0;
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: clamp(25px, 7vw, 34px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.12;
}

.modern-brand small {
  display: block;
  margin-top: 6px;
  color: var(--modern-muted);
  font-family: var(--font-modern-body);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}

.modern-avatar-button,
.modern-icon-button {
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--modern-line);
  color: #15110b;
  background: conic-gradient(from 200deg, var(--modern-ember), var(--modern-amber), var(--modern-teal), var(--modern-ember));
  box-shadow: none;
}

.modern-avatar-button {
  width: 46px;
  height: 46px;
  min-height: 46px;
  border-radius: 16px;
  padding: 0;
  font-family: var(--font-modern-display);
  font-size: 18px;
  font-weight: 700;
}

.modern-avatar-button.is-muted,
.modern-icon-button {
  color: var(--modern-text);
  background: var(--modern-surface);
}

.modern-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modern-section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.modern-section-heading h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
}

.modern-section-heading h2::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--modern-amber);
  box-shadow: 0 0 12px var(--modern-glow);
  transform: rotate(45deg);
}

.modern-link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--modern-muted);
  background: transparent;
  box-shadow: none;
  font-family: var(--font-modern-body);
  font-size: 12.5px;
}

.modern-rail {
  display: flex;
  gap: 14px;
  margin: 0 -20px;
  padding: 4px 20px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.modern-room-card {
  position: relative;
  flex: none;
  width: 215px;
  min-height: 174px;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--modern-line);
  border-radius: var(--modern-radius);
  color: var(--modern-text);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  box-shadow: none;
  text-align: left;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.35s;
}

.modern-room-card:hover,
.modern-room-card:focus-visible {
  border-color: rgba(244, 173, 92, 0.45);
  transform: translateY(-4px);
}

.modern-room-face,
.modern-conversation-face,
.modern-profile-face {
  display: grid;
  place-items: center;
  color: #140f08;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  font-family: var(--font-modern-display);
  font-weight: 700;
}

.modern-room-face {
  width: 54px;
  height: 54px;
  margin-bottom: 13px;
  border-radius: 16px;
  font-size: 24px;
}

.modern-room-card strong {
  display: block;
  margin-bottom: 5px;
  overflow: hidden;
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 16.5px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modern-room-card p {
  height: 38px;
  margin: 0;
  overflow: hidden;
  color: var(--modern-muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.modern-room-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
  color: var(--modern-faint);
  font-size: 11px;
}

.modern-room-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 120px;
  padding: 3px 9px;
  overflow: hidden;
  border-radius: 999px;
  color: var(--modern-muted);
  background: var(--modern-surface-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modern-empty-card {
  min-width: min(320px, calc(100vw - 40px));
  padding: 18px;
  border: 1px solid var(--modern-line);
  border-radius: var(--modern-radius);
  color: var(--modern-muted);
  background: var(--modern-surface);
  line-height: 1.6;
}

.modern-cta {
  position: relative;
  display: block;
  min-height: 156px;
  padding: 22px 22px 24px;
  overflow: hidden;
  border: 1px solid rgba(244, 173, 92, 0.3);
  border-radius: 26px;
  color: #1a0f06;
  background: linear-gradient(120deg, var(--modern-ember) 0%, var(--modern-amber) 60%, #f2c879 100%);
  box-shadow: 0 22px 50px -22px var(--modern-ember);
  text-align: left;
}

.modern-cta::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -30px;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.45), transparent 60%);
}

.modern-cta-kicker {
  display: block;
  font-family: var(--font-modern-body);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.3em;
  opacity: 0.7;
}

.modern-cta strong {
  display: block;
  margin: 7px 0 6px;
  font-family: var(--font-modern-display);
  font-size: 25px;
  font-weight: 800;
  line-height: 1.18;
}

.modern-cta > span:not(.modern-cta-kicker):not(.modern-cta-arrow) {
  display: block;
  max-width: 74%;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  opacity: 0.78;
}

.modern-cta-arrow {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--modern-amber);
  background: #1a0f06;
  font-size: 20px;
}

.modern-feature-card {
  min-height: 172px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px;
  overflow: hidden;
  border: 1px solid var(--modern-line);
  border-radius: var(--modern-radius);
  background:
    linear-gradient(180deg, rgba(11, 10, 15, 0.10), rgba(11, 10, 15, 0.86)),
    conic-gradient(from 140deg at 70% 20%, #1d3a44, #3a2740, #5a3326, #1d3a44);
}

.modern-feature-card span {
  align-self: flex-start;
  margin-bottom: auto;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #f4efe7;
  background: rgba(0, 0, 0, 0.45);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.modern-feature-card h3 {
  margin: 0;
  color: #f4efe7;
  font-family: var(--font-modern-display);
  font-size: 21px;
  font-weight: 800;
  line-height: 1.25;
}

.modern-feature-card p {
  margin: 6px 0 0;
  color: #d9d2c8;
  font-size: 12.5px;
  line-height: 1.5;
}

.modern-search,
.modern-segment,
.modern-group,
.modern-profile-card {
  border: 1px solid var(--modern-line);
  background: var(--modern-surface);
}

.modern-search {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 16px;
  border-radius: 16px;
  color: var(--modern-muted);
}

.modern-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--modern-text);
  background: transparent;
  font: inherit;
}

.modern-segment {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 14px;
}

.modern-segment button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 11px;
  color: var(--modern-muted);
  background: transparent;
  box-shadow: none;
  font-family: var(--font-modern-body);
  font-size: 13px;
  font-weight: 700;
}

.modern-segment button.is-active {
  color: #1a0f06;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  box-shadow: 0 8px 20px -10px var(--modern-ember);
}

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

.modern-grid > .modern-empty-card,
.modern-discover-status,
.modern-discover-more {
  grid-column: 1 / -1;
}

.modern-discover-more {
  display: flex;
  justify-content: center;
  padding: 4px 0 12px;
}

.modern-discover-card {
  min-height: 174px;
  padding: 12px;
  border: 1px solid var(--modern-line);
  border-radius: var(--modern-radius);
  color: var(--modern-text);
  background: var(--modern-surface);
  text-align: left;
  box-shadow: none;
}

.modern-discover-art {
  position: relative;
  display: flex;
  align-items: flex-end;
  height: 108px;
  padding: 11px;
  border-radius: 17px;
  background: linear-gradient(160deg, #3a4a54, #1d2a30);
}

.modern-discover-art b {
  position: absolute;
  top: 8px;
  right: 12px;
  color: rgba(255, 255, 255, 0.92);
  font-family: var(--font-modern-display);
  font-size: 42px;
}

.modern-discover-card strong {
  display: block;
  margin-top: 10px;
  overflow: hidden;
  font-family: var(--font-modern-display);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modern-discover-card span {
  display: block;
  margin-top: 4px;
  color: var(--modern-muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.modern-profile-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 18px;
  border-radius: var(--modern-radius);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
}

.modern-profile-face {
  width: 62px;
  height: 62px;
  border-radius: 19px;
  font-size: 26px;
}

.modern-profile-card strong {
  display: block;
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 20px;
}

.modern-profile-card span {
  display: block;
  margin-top: 4px;
  color: var(--modern-amber);
  font-size: 12px;
  font-weight: 700;
}

.modern-group {
  overflow: hidden;
  border-radius: var(--modern-radius);
}

.modern-group h2 {
  margin: 0;
  padding: 14px 18px 8px;
  color: var(--modern-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modern-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 64px;
  padding: 15px 18px;
  border: 0;
  border-top: 1px solid var(--modern-line);
  border-radius: 0;
  color: var(--modern-text);
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.modern-row-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--modern-surface-2);
  font-size: 16px;
}

.modern-row > span:nth-child(2) {
  flex: 1;
  min-width: 0;
}

.modern-row strong,
.modern-row small {
  display: block;
}

.modern-row strong {
  font-family: var(--font-modern-body);
  font-size: 14.5px;
  font-weight: 500;
}

.modern-row small {
  margin-top: 3px;
  color: var(--modern-muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.modern-switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 27px;
  border: 1px solid var(--modern-line);
  border-radius: 999px;
  background: var(--modern-surface-2);
}

.modern-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--modern-muted);
  transition: left 0.3s, background 0.3s;
}

.modern-switch.is-on {
  border-color: transparent;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
}

.modern-switch.is-on::after {
  left: 21px;
  background: #1a0f06;
}

.modern-bottom-nav {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  padding: 12px 18px calc(26px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--modern-line);
  background: linear-gradient(180deg, transparent, var(--ink) 32%);
  backdrop-filter: blur(14px);
}

.modern-nav-button {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 45px;
  padding: 4px 8px;
  border: 0;
  border-radius: 14px;
  color: var(--modern-faint);
  background: transparent;
  box-shadow: none;
  font-family: var(--font-modern-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.modern-nav-button.is-active {
  color: var(--modern-amber);
}

.modern-nav-icon {
  width: 25px;
  height: 25px;
}

.modern-nav-button.is-active .modern-nav-icon {
  filter: drop-shadow(0 0 8px var(--modern-glow));
}

.modern-rail-nav {
  display: none;
}

.modern-fab {
  position: absolute;
  right: 18px;
  bottom: 96px;
  z-index: 20;
  display: none;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  color: #1a0f06;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  box-shadow: 0 18px 36px -14px var(--modern-ember);
  font-family: var(--font-modern-body);
  font-size: 14px;
  font-weight: 900;
}

.modern-fab.is-visible {
  display: inline-flex;
}

.modern-conversation-screen {
  z-index: 50;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
}

.modern-conversation-column {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.modern-conversation-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--modern-line);
}

.modern-icon-button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 13px;
  font-size: 19px;
}

.modern-conversation-face {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 18px;
}

.modern-conversation-title {
  flex: 1;
  min-width: 0;
}

.modern-conversation-title strong,
.modern-conversation-title span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modern-conversation-title strong {
  font-family: var(--font-modern-display);
  font-size: 17px;
}

.modern-conversation-title span {
  margin-top: 3px;
  color: var(--modern-muted);
  font-size: 11.5px;
}

.modern-conversation-placeholder {
  flex: 1;
  padding: 20px 16px 100px;
  overflow-y: auto;
}

.modern-placeholder-card {
  padding: 18px;
  border: 1px solid var(--modern-line);
  border-radius: var(--modern-radius);
  color: var(--modern-muted);
  background: var(--modern-surface);
  line-height: 1.7;
}

.modern-placeholder-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--modern-text);
  font-family: var(--font-modern-display);
  font-size: 18px;
}

.modern-preview-message {
  max-width: 86%;
  margin-bottom: 12px;
  padding: 13px 16px;
  border: 1px solid var(--modern-line);
  border-radius: 20px;
  color: var(--modern-text);
  background: var(--modern-surface-2);
  font-size: 14px;
  line-height: 1.7;
}

.modern-preview-message.is-user {
  margin-left: auto;
  color: #1a0f06;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
}

.modern-note-pane {
  display: none;
}

.modern-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(5, 4, 8, 0.6);
  backdrop-filter: blur(3px);
}

.modern-sheet-backdrop[hidden],
.modern-sheet[hidden] {
  display: none;
}

.modern-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 91;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--modern-line);
  border-bottom: 0;
  border-radius: 30px 30px 0 0;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  color: var(--modern-text);
}

.modern-sheet-grab {
  flex: none;
  width: 42px;
  height: 5px;
  margin: 11px auto 4px;
  border-radius: 999px;
  background: var(--modern-line);
}

.modern-sheet-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  padding: 8px 20px 14px;
}

.modern-sheet-head div {
  flex: 1;
}

.modern-sheet-head span {
  color: var(--modern-amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.modern-sheet-head h2 {
  margin: 3px 0 0;
  font-family: var(--font-modern-display);
  font-size: 21px;
}

.modern-sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 20px 16px;
  color: var(--modern-muted);
  line-height: 1.7;
}

.modern-sheet-foot {
  flex: none;
  padding: 14px 20px calc(26px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--modern-line);
}

.modern-primary-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 15px;
  color: #1a0f06;
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  box-shadow: 0 14px 30px -14px var(--modern-ember);
  font-family: var(--font-modern-body);
  font-size: 14.5px;
  font-weight: 900;
}

.rev {
  opacity: 0;
  transform: translateY(14px);
  animation: modernReveal 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(var(--i, 0) * 70ms + 60ms);
}

@keyframes modernReveal {
  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 900px) {
  .modern-shell {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr) 300px;
  }

  .modern-rail-nav {
    z-index: 45;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px 10px;
    border-right: 1px solid var(--modern-line);
  }

  .modern-rail-brand {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    margin: 0 auto 14px;
    border-radius: 14px;
    color: #1a0f06;
    background: conic-gradient(from 200deg, var(--modern-ember), var(--modern-amber), var(--modern-teal), var(--modern-ember));
    font-family: var(--font-modern-display);
    font-weight: 800;
  }

  .modern-viewport {
    grid-column: 2 / 4;
  }

  .modern-bottom-nav {
    display: none;
  }

  .modern-screen:not(.modern-conversation-screen) {
    right: 300px;
    border-right: 1px solid var(--modern-line);
  }

  .modern-conversation-screen.is-active {
    flex-direction: row;
  }

  .modern-note-pane {
    display: flex;
    flex: 0 0 300px;
    flex-direction: column;
    gap: 16px;
    padding: 22px;
    border-left: 1px solid var(--modern-line);
  }

  .modern-scroll {
    padding: 24px 26px 40px;
  }

  .modern-fab {
    right: 316px;
    bottom: 26px;
  }

  .modern-sheet {
    right: 34px;
    left: auto;
    width: min(420px, calc(100vw - 120px));
    border-radius: 30px 30px 0 0;
  }
}

/* ---- v2: real chat reused inside the modern conversation screen ---- */
#modernConversationBody.modern-conversation-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
#modernConversationBody.modern-conversation-chat > #crisisBanner,
#modernConversationBody.modern-conversation-chat > #scenarioBar {
  flex: none;
}
#modernConversationBody.modern-conversation-chat > #messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px;
}
#modernConversationBody.modern-conversation-chat > #chatForm {
  flex: none;
  border-top: 1px solid var(--modern-line);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--ink-2);
}
.modern-conversation-face.has-image {
  padding: 0;
  overflow: hidden;
}
.modern-conversation-face .character-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* note pane hosts the legacy memory/story pane on PC */
/* Neutralise the base desktop `.memory-pane` rule for the reused pane inside the
   note. The legacy mobile *drawer* rules no longer apply here (they are scoped to
   .app-shell:not(.ui-v2)), so this only has to override the handful of base
   properties: position:relative, fixed height, surface background, border/shadow.
   Each line below maps to one of those. */
.modern-note-pane #memoryPane {
  display: block; /* stack sections vertically; never inherit a flex row layout */
  position: static;
  width: 100%;
  /* Fill the space left by the note head and scroll internally (base sets a fixed
     calc() height; here the pane is a flex child that must size to the note). */
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  border: 0;
  box-shadow: none;
  background: transparent;
}

/* ---- v2: new-conversation sheet character picker ---- */
.modern-sheet-hint {
  color: var(--modern-muted);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 12px;
}
.modern-pick-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.modern-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border: 1px solid var(--modern-line);
  border-radius: 15px;
  background: var(--modern-surface);
  color: var(--modern-text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.modern-pick.is-sel {
  border-color: var(--modern-amber);
  background: rgba(244, 173, 92, 0.12);
}
.modern-pick-face {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  flex: none;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--font-modern-display);
  font-weight: 700;
}
.modern-pick-face .character-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.modern-pick-text {
  flex: 1;
  min-width: 0;
}
.modern-pick-text strong {
  display: block;
  font-family: var(--font-modern-display);
  font-size: 15px;
}
.modern-pick-text small {
  display: block;
  color: var(--modern-muted);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modern-pick-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--modern-line);
  color: transparent;
  font-size: 13px;
}
.modern-pick.is-sel .modern-pick-check {
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  border-color: transparent;
  color: #15110b;
}
.modern-pick-more {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--modern-line);
  border-radius: 14px;
  background: var(--modern-surface);
  color: var(--modern-text);
  font-family: var(--font-modern-body);
  font-weight: 700;
  cursor: pointer;
}

/* ---- v2: discover filters ---- */
.modern-pillswitch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--modern-line);
  border-radius: 999px;
  background: var(--modern-surface);
  align-self: flex-start;
}
.modern-pillswitch button {
  min-height: 34px;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--modern-muted);
  font-family: var(--font-modern-body);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.modern-pillswitch button.is-active {
  background: var(--modern-text);
  color: var(--ink);
}
.modern-sheet-story {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(244, 173, 92, 0.12);
  border: 1px solid rgba(244, 173, 92, 0.28);
  color: var(--modern-text);
  font-size: 13px;
}

/* ---- v2: discover cards are interactive ---- */
.modern-discover-card {
  cursor: pointer;
}
.modern-discover-card.is-static {
  cursor: default;
}

/* ---- v2: create chooser + sheet search ---- */
.modern-create-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modern-create-option {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--modern-line);
  border-radius: 16px;
  background: var(--modern-surface);
  color: var(--modern-text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.modern-create-option:hover {
  border-color: rgba(244, 173, 92, 0.5);
}
.modern-create-ic {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.06);
}
.modern-create-text {
  flex: 1;
  min-width: 0;
}
.modern-create-text strong {
  display: block;
  font-family: var(--font-modern-display);
  font-size: 15.5px;
}
.modern-create-text small {
  display: block;
  color: var(--modern-muted);
  font-size: 12px;
  margin-top: 2px;
}
.modern-create-arrow {
  color: var(--modern-faint);
  font-size: 18px;
  flex: none;
}
.modern-sheet-search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 11px 14px;
  border: 1px solid var(--modern-line);
  border-radius: 14px;
  background: var(--modern-surface);
  color: var(--modern-muted);
}
.modern-sheet-search input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--modern-text);
  font: inherit;
  font-size: 14px;
}
.modern-sheet-search input::placeholder {
  color: var(--modern-faint);
}

/* ---- v2: mobile note slide-over (reachable on phones) ---- */
.modern-row-arrow {
  margin-left: auto;
  color: var(--modern-faint);
  font-size: 18px;
}
/* class rows override the UA [hidden] rule, so restore it explicitly */
.modern-row[hidden] {
  display: none !important;
}
.modern-row.is-disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: default;
}
.modern-row-badge {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  color: var(--modern-faint);
  border: 1px solid var(--modern-line);
  padding: 2px 9px;
  border-radius: 999px;
}
.modern-note-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 4px 14px;
}
.modern-note-head-text {
  flex: 1;
  min-width: 0;
}
.modern-note-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--modern-line);
  border-radius: 10px;
  background: transparent;
  color: var(--modern-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.modern-note-close:hover {
  color: var(--modern-amber);
  border-color: var(--modern-amber);
  background: rgba(255, 255, 255, 0.04);
}
.modern-note-head strong {
  display: block;
  font-family: var(--font-modern-display);
  font-size: 18px;
}
.modern-note-head small {
  display: block;
  margin-top: 3px;
  color: var(--modern-muted);
  font-size: 12px;
}
/* Mobile boundary is 900px everywhere: the JS toggle uses matchMedia(900), the PC
   note column appears at min-width:900, so the slide-over must end just below 900
   (using 980 here created an ambiguous 900–980 zone where both layouts' rules co-existed). */
@media (max-width: 899.98px) {
  #conversationScreen.is-note-open .modern-conversation-head {
    position: relative;
    z-index: 62;
  }
  #conversationScreen.is-note-open .modern-note-pane {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 66px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 16px;
    overflow-y: auto;
    background: linear-gradient(180deg, var(--ink-2), var(--ink));
    border-left: 0;
    animation: noteSlideIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  #conversationScreen.is-note-open #modernConversationNote {
    color: var(--modern-amber);
  }
}
@keyframes noteSlideIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (min-width: 900px) {
  /* PC: note pane shows as a column by default; collapse hides it and lets the
     conversation column reclaim the width (it is flex:1). The 📝 button stays
     visible so the pane can be reopened. */
  #conversationScreen.is-note-collapsed .modern-note-pane {
    display: none;
  }
  #conversationScreen:not(.is-note-collapsed) #modernConversationNote {
    color: var(--modern-amber);
  }
}
.modern-discover-art {
  overflow: hidden;
}
.modern-discover-art .character-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- v2: message bubbles match the dark theme ---- */
body.ui-v2 .message.assistant {
  background: rgba(255, 255, 255, 0.06);
  color: var(--modern-text);
  border: 1px solid var(--modern-line);
  border-left: 4px solid var(--modern-amber);
  box-shadow: 0 14px 30px -20px rgba(0, 0, 0, 0.6);
  backdrop-filter: none;
}
body.ui-v2 .message.user {
  background: linear-gradient(160deg, var(--modern-amber), var(--modern-ember));
  color: #1a0f06;
  border: 1px solid transparent;
  box-shadow: 0 14px 30px -18px var(--modern-ember);
  backdrop-filter: none;
}
body.ui-v2 .message-content {
  color: inherit;
}
body.ui-v2 .narration {
  color: var(--modern-teal);
  background: rgba(116, 182, 191, 0.1);
  border: 1px solid rgba(116, 182, 191, 0.22);
}
body.ui-v2 .message-time {
  color: var(--modern-faint);
}
body.ui-v2 .composer {
  background: var(--ink-2);
  border-top: 1px solid var(--modern-line);
}

@media (max-width: 460px) {
  .modern-scroll {
    padding-top: 16px;
  }

  .modern-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.scenario-location-button {
  display: grid;
  align-items: center;
  min-width: 0;
  min-height: 34px;
  border-radius: 8px;
  box-shadow: none;
  color: var(--accent);
}

.scenario-location-button {
  grid-template-columns: 18px auto minmax(0, 1fr);
  gap: 7px;
  justify-content: start;
  padding: 6px 10px;
  text-align: left;
  background: rgba(var(--accent-soft-rgb), 0.42);
  border-color: rgba(var(--accent-rgb), 0.2);
}

.scenario-location-button span,
.scenario-location-button strong {
  min-width: 0;
}

.scenario-location-button span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
}

.scenario-location-button strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 18px 20px 18px;
}

.empty-state {
  display: grid;
  gap: 7px;
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
  line-height: 1.5;
}

.empty-state strong {
  color: var(--text);
  font-size: 15px;
}

.empty-state span {
  font-size: 13px;
}

.message-loading {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: 48vh;
  color: var(--accent);
  text-align: center;
}

.message-loading .busy-spinner {
  width: 28px;
  height: 28px;
  border-width: 3px;
}

.message-loading strong {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.message-row.thinking {
  opacity: 0.94;
}

.thinking-bubble {
  border-style: dashed;
}

.thinking-content {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.thinking-dots {
  display: inline-flex;
  gap: 4px;
  width: 28px;
  align-items: center;
  justify-content: center;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--violet);
  opacity: 0.32;
  animation: thinking-dot 1.1s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 140ms;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes thinking-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.32;
  }

  40% {
    transform: translateY(-4px);
    opacity: 0.95;
  }
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin: 10px 0;
}

.message-row.message-reveal {
  animation: message-pop-in 220ms ease-out both;
}

@keyframes message-pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message-stack {
  max-width: min(72%, 720px);
  display: grid;
  gap: 5px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
  overflow-wrap: anywhere;
  box-shadow: 0 14px 30px rgba(25, 28, 29, 0.1);
  backdrop-filter: blur(18px);
}

.message.user {
  margin-left: auto;
  border-bottom-right-radius: 6px;
  background: var(--user);
  border: 1px solid rgba(var(--accent-rgb), 0.26);
  color: var(--text);
  box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.08), 0 14px 30px rgba(25, 28, 29, 0.08);
}

.message.assistant {
  margin-right: auto;
  border-bottom-left-radius: 6px;
  background: var(--assistant);
  border: 1px solid rgba(var(--secondary-rgb), 0.15);
  border-left: 4px solid var(--violet);
  box-shadow: -8px 0 24px -16px rgba(var(--secondary-rgb), 0.44), 0 14px 30px rgba(25, 28, 29, 0.1);
}

.message-content {
  min-width: 0;
}

.narration {
  color: #6e4c10;
  font-style: italic;
  background: rgba(var(--accent-soft-rgb), 0.68);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  border-radius: 8px;
  padding: 1px 5px;
}

.term-mention {
  appearance: none;
  display: inline;
  border: 0;
  border-radius: 3px;
  min-width: 0;
  min-height: 0;
  height: auto;
  padding: 0;
  margin: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-decoration: underline dotted rgba(var(--accent-rgb), 0.48) 1px;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
  vertical-align: baseline;
}

.term-mention:hover,
.term-mention:focus-visible {
  background: rgba(var(--accent-rgb), 0.08);
  box-shadow: none;
  outline: none;
  transform: none;
}

.term-popover {
  position: fixed;
  z-index: 5000;
  display: grid;
  gap: 5px;
  max-width: min(300px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid rgba(var(--accent-rgb), 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: 0 18px 40px rgba(25, 28, 29, 0.18);
  backdrop-filter: blur(14px);
  font-size: 13px;
  line-height: 1.45;
}

.term-popover[hidden] {
  display: none !important;
}

.term-popover strong {
  font-size: 13px;
}

.term-popover span {
  color: var(--muted);
}

.bubble-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
  box-shadow: var(--violet-glow);
}

.message-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.message-meta-with-avatar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.message-meta-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--violet-glow);
}

.message-row.user .message-meta {
  display: none;
}

.message-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  margin-bottom: 2px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: rgba(255, 252, 242, 0.88);
  backdrop-filter: blur(28px);
  padding: 14px 16px;
  min-height: 86px;
  box-shadow: 0 -16px 38px rgba(25, 28, 29, 0.08), 0 0 22px rgba(var(--accent-rgb), 0.05);
}

.composer textarea {
  border-color: rgba(var(--navy-rgb), 0.16);
  background: rgba(255, 255, 255, 0.88);
  padding: 12px 14px;
  border-radius: 18px;
  color: var(--text);
}

.composer button {
  align-self: start;
  width: 100%;
}

.composer-buttons {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
}

.composer-buttons button {
  min-height: 42px;
}

.narration-button {
  padding-inline: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--accent);
  background: rgba(var(--accent-soft-rgb), 0.7);
  border-color: rgba(var(--accent-rgb), 0.2);
}

.composer-actions {
  display: grid;
  gap: 5px;
  align-self: start;
}

.composer-actions span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  letter-spacing: 0;
}

.memory-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  padding: 16px 18px 16px 58px;
  min-height: 64px;
}

.memory-header h2 {
  font-size: 17px;
}

.memory-header p {
  margin: 3px 0 0;
  color: var(--muted-dim);
  font-size: 11px;
  line-height: 1.35;
}

.story-state-panel {
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(var(--accent-soft-rgb), 0.72) 0%, rgba(255, 255, 255, 0.92) 100%);
  padding: 0;
}

.story-state-panel[hidden] {
  display: none;
}

.story-state-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px 12px;
  cursor: pointer;
  list-style: none;
}

.story-state-heading::-webkit-details-marker {
  display: none;
}

.story-state-heading h3 {
  margin: 0;
  font-size: 14px;
  font-family: var(--font-display);
}

.story-state-heading span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(var(--secondary-container-rgb), 0.74);
  color: var(--violet);
  border: 1px solid rgba(var(--secondary-rgb), 0.16);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 7px;
}

.story-state-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0 18px 14px;
}

.story-state-list div {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
}

.story-state-list dt {
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.story-state-list dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.story-action-chip {
  display: block;
  width: 100%;
  margin: 0 0 6px;
  padding: 7px 8px;
  border: 1px solid rgba(79, 70, 229, 0.2);
  border-radius: 7px;
  background: rgba(79, 70, 229, 0.08);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.story-action-chip:hover {
  background: rgba(79, 70, 229, 0.13);
}

.story-action-chip span,
.story-action-chip small {
  display: block;
  overflow-wrap: anywhere;
}

.story-action-chip span {
  font-size: 12px;
  font-weight: 700;
}

.story-action-chip small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.context-memory,
.memory-list,
.secret-diary-list {
  padding: 12px 18px;
}

.context-memory {
  display: none;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(255, 225, 115, 0.18) 0%, rgba(255, 255, 255, 0.86) 100%);
}

.context-memory.active {
  display: block;
}

.context-memory h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text);
}

.context-memory h3::before {
  content: "現実";
  display: inline-block;
  margin-right: 8px;
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  font-family: var(--font-mono);
  font-size: 10px;
}

.diary-panel {
  border-bottom: 1px solid var(--border);
}

.diary-panel:last-child {
  border-bottom: 0;
}

.memory-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px 0;
}

.memory-section-heading h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 13px;
}

.secret-diary-list .empty-state,
.memory-list .empty-state {
  margin-top: 4px;
}

.secret-diary-item {
  border: 1px solid rgba(var(--secondary-rgb), 0.16);
  border-radius: 16px;
  margin-bottom: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(var(--secondary-container-rgb), 0.34));
  box-shadow: 0 14px 30px rgba(25, 28, 29, 0.08);
  overflow: hidden;
}

.secret-diary-item:last-child {
  margin-bottom: 0;
}

.secret-diary-item summary {
  display: grid;
  gap: 5px;
  padding: 12px 34px 12px 12px;
  cursor: pointer;
  list-style: none;
  position: relative;
}

.secret-diary-item summary::-webkit-details-marker {
  display: none;
}

.secret-diary-item summary::after {
  content: "";
  position: absolute;
  top: 18px;
  right: 14px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--violet);
  border-bottom: 2px solid var(--violet);
  transform: rotate(45deg);
  transition: transform 140ms ease;
}

.secret-diary-item[open] summary::after {
  transform: rotate(225deg);
}

.secret-diary-body {
  display: grid;
  gap: 9px;
  border-top: 1px solid rgba(var(--secondary-rgb), 0.12);
  padding: 11px 12px 12px;
}

.diary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.diary-meta span,
.diary-meta time {
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(var(--secondary-rgb), 0.16);
  border-radius: 999px;
  background: rgba(var(--secondary-container-rgb), 0.72);
  color: var(--violet);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  padding: 3px 7px;
  overflow-wrap: anywhere;
}

.diary-meta time {
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
}

.secret-diary-item h4 {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.35;
}

.diary-summary,
.diary-entry {
  margin: 0;
  overflow-wrap: anywhere;
}

.diary-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.diary-entry {
  color: var(--text);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.diary-feelings {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.diary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.diary-tags span {
  border-radius: 999px;
  background: rgba(var(--accent-soft-rgb), 0.66);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  padding: 3px 7px;
}

.memory-item {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 11px 12px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(14px);
}

.memory-item:last-child {
  margin-bottom: 0;
}

.memory-item p {
  margin: 0;
  line-height: 1.45;
  font-size: 13px;
}

.memory-owner {
  display: inline-block;
  font-size: 11px;
  color: var(--muted, #888);
  margin-bottom: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
}

.memory-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.error {
  color: var(--danger);
}

.character-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(820px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  backdrop-filter: var(--glass-blur);
}

.character-dialog::backdrop {
  background: rgba(63, 72, 74, 0.18);
  backdrop-filter: blur(6px);
}

.character-form {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  max-height: min(820px, calc(100dvh - 28px));
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.72);
}

.dialog-header h2,
.character-form h3 {
  margin: 0;
  letter-spacing: 0;
}

.dialog-header h2 {
  font-size: 18px;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.character-form-body {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 4px;
}

.character-form section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.draft-section {
  background: rgba(var(--accent-soft-rgb), 0.46);
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 18px;
  padding: 14px;
}

.draft-section .secondary-action {
  min-height: 42px;
}

.draft-review {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid rgba(var(--secondary-rgb), 0.16);
  border-radius: 14px;
  background: rgba(var(--secondary-container-rgb), 0.52);
  padding: 12px;
}

.draft-review[hidden] {
  display: none;
}

.draft-review h3,
.draft-review h4 {
  margin: 0;
  letter-spacing: 0;
}

.draft-review h3 {
  color: var(--violet);
  font-size: 13px;
}

.draft-review h4 {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.draft-review ul {
  margin: 5px 0 0;
  padding-left: 18px;
}

.draft-review li {
  margin: 3px 0;
  font-size: 12px;
  line-height: 1.45;
}

.draft-review-meta {
  margin: 0;
  color: var(--muted-dim);
  font-family: var(--font-mono);
  font-size: 10px;
}

.character-form section:last-child {
  border-bottom: 0;
}

.character-form h3 {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--accent);
  font-family: var(--font-display);
}

.character-form textarea {
  height: auto;
  min-height: 0;
  max-height: none;
  resize: vertical;
}

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

.radio-group {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 12px;
}

.radio-group label {
  display: inline-flex;
  width: auto;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
}

.radio-group input {
  width: auto;
  accent-color: var(--accent);
}

.visibility-choice-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.visibility-choice-icon {
  width: 15px;
  height: 15px;
  color: var(--accent);
  stroke-width: 2;
}

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-family: var(--font-body);
  letter-spacing: 0;
  text-transform: none;
}

.checkbox-row input {
  width: auto;
  min-height: 0;
}

.form-error {
  margin: 0;
  padding: 0 18px 12px;
  color: var(--danger);
  font-size: 13px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px 18px 16px;
  background: rgba(255, 255, 255, 0.72);
}

.dialog-actions button {
  min-height: 42px;
  width: 100%;
}

@media (max-width: 980px) {
  .auth-view {
    align-items: stretch;
    padding: 14px;
  }

  .auth-card {
    display: grid;
    align-content: center;
    min-height: calc(100dvh - 28px);
    padding: 20px;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  body {
    background:
      radial-gradient(circle at 18% 0%, rgba(var(--accent-soft-rgb), 0.86), transparent 30%),
      linear-gradient(rgba(var(--accent-rgb), 0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(var(--accent-rgb), 0.03) 1px, transparent 1px),
      var(--bg);
    background-size: auto, 40px 40px, 40px 40px;
  }

  .app-shell {
    display: block;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 0;
  }

  .app-shell.hide-left,
  .app-shell.hide-right,
  .app-shell.hide-left.hide-right {
    grid-template-columns: 1fr;
  }

  .app-shell.hide-left .sidebar,
  .app-shell:not(.ui-v2).hide-right .memory-pane {
    display: block;
  }

  .floating-toggle {
    display: none;
  }

  .app-shell.compact.no-memory.hide-left .floating-toggle-left {
    display: inline-grid;
  }

  /* Legacy mobile drawer. Scoped to :not(.ui-v2) so these drawer styles (fixed
     position, translateX hide, pointer-events:none) never leak into the v2 note,
     which reuses #memoryPane — that leakage caused the blank/no-scroll/no-touch bugs. */
  .sidebar,
  .app-shell:not(.ui-v2) .memory-pane {
    position: fixed;
    top: 0;
    bottom: 0;
    display: block;
    width: min(86vw, 380px);
    max-width: 100vw;
    height: 100dvh;
    z-index: 40;
    border: 0;
    border-radius: 0;
    box-shadow: var(--panel-shadow);
    transition: transform 180ms ease;
    scrollbar-gutter: auto;
    overscroll-behavior: contain;
  }

  .sidebar {
    left: 0;
    padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
    border-right: 1px solid var(--border);
  }

  .app-shell:not(.ui-v2) .memory-pane {
    right: 0;
    border-left: 1px solid var(--border);
  }

  .app-shell.hide-left .sidebar {
    transform: translateX(-104%);
    pointer-events: none;
  }

  .app-shell:not(.hide-left) .sidebar {
    transform: translateX(0);
  }

  .app-shell:not(.ui-v2).hide-right .memory-pane {
    transform: translateX(104%);
    pointer-events: none;
  }

  .app-shell:not(.ui-v2):not(.hide-right) .memory-pane {
    transform: translateX(0);
  }

  .chat-pane {
    width: 100vw;
    height: calc(100dvh - var(--bottom-nav-height));
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.72);
  }

  .center-view,
  .edit-pane,
  .admin-pane {
    width: 100vw;
    height: calc(100dvh - var(--bottom-nav-height));
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  }

  .center-view-inner {
    width: 100%;
  }

  .welcome-card {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .welcome-avatar {
    width: 52px;
    height: 52px;
    font-size: 20px;
  }

  .welcome-copy h2,
  .center-section-header h2 {
    font-size: 20px;
  }

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

  .center-actions button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  .launcher-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    max-height: calc(100dvh - var(--bottom-nav-height) - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .launcher-character-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-y: auto;
  }

  .launcher-character-card,
  .launcher-character-card.has-image {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    min-height: 218px;
    padding: 12px;
  }

  .launcher-character-card.has-image .launcher-character-avatar,
  .launcher-character-card .launcher-character-avatar {
    justify-self: center;
    width: min(100%, 104px);
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .launcher-character-text {
    padding-right: 0;
  }

  .launcher-character-card strong {
    font-size: 13px;
  }

  .launcher-character-persona {
    font-size: 11px;
    line-height: 1.35;
    -webkit-line-clamp: 2;
  }

  .character-action-dialog {
    inset: auto 0 0;
    width: 100vw;
    max-width: 100vw;
    max-height: min(82dvh, calc(100dvh - env(safe-area-inset-top) - 10px));
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 24px 24px 0 0;
  }

  .character-action-sheet {
    max-height: min(82dvh, calc(100dvh - env(safe-area-inset-top) - 10px));
  }

  .character-action-header {
    padding: 14px 14px 12px;
  }

  .character-action-body {
    padding: 14px;
  }

  .character-profile-dialog {
    width: min(560px, calc(100vw - 18px));
    max-height: min(84dvh, calc(100dvh - var(--bottom-nav-height) - 18px));
    border-radius: 18px;
  }

  .character-profile-card {
    max-height: min(84dvh, calc(100dvh - var(--bottom-nav-height) - 18px));
  }

  .exploration-note-dialog {
    inset: auto 0 0;
    width: 100vw;
    max-width: 100vw;
    max-height: min(82dvh, calc(100dvh - var(--bottom-nav-height) - env(safe-area-inset-top) - 10px));
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
  }

  .exploration-note-sheet {
    max-height: min(82dvh, calc(100dvh - var(--bottom-nav-height) - env(safe-area-inset-top) - 10px));
  }

  .exploration-note-body {
    padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
  }

  .note-entry {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .note-insert-chip {
    justify-self: start;
  }

  .character-profile-facts {
    grid-template-columns: 1fr;
  }

  .character-action-new {
    min-height: 50px;
  }

  .character-action-room-list {
    max-height: none;
  }

  .dialog-actions.character-action-footer {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }

  .edit-pane,
  .admin-pane {
    padding: calc(14px + env(safe-area-inset-top)) 12px 12px;
  }

  .edit-resource-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .admin-header {
    display: grid;
    gap: 12px;
  }

  .admin-toolbar {
    grid-template-columns: minmax(0, 1fr) 76px minmax(0, 1fr);
  }

  .admin-metrics,
  .admin-trend-summary,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-trend-chart {
    min-height: 220px;
  }

  .admin-trend-bar {
    height: 198px;
  }

  .admin-daily-row {
    grid-template-columns: 78px minmax(60px, 1fr) 54px 38px;
    gap: 6px;
  }

  .edit-resource-panel {
    min-height: 220px;
  }

  .bottom-nav {
    width: min(340px, calc(100vw - 20px));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .chat-header {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    min-height: calc(56px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }

  #mobileOpenSidebarButton {
    grid-column: 1;
  }

  .chat-title {
    grid-column: 2;
    min-width: 0;
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .chat-header .header-icon-button {
    grid-column: 3;
  }

  #mobileOpenMemoryButton {
    grid-column: 4;
  }

  .chat-title > div:last-child {
    min-width: 0;
    max-width: 100%;
  }

  .chat-avatar {
    display: none;
  }

  .chat-header h2 {
    overflow: visible;
    font-size: 16px;
    line-height: 1.2;
    text-overflow: clip;
    white-space: normal;
  }

  .chat-header p {
    overflow: hidden;
    font-size: 11px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-button {
    display: grid;
    place-items: center;
    width: 44px;
    min-width: 44px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 14px;
    color: var(--accent);
    font-weight: 700;
    line-height: 1;
    background: rgba(var(--accent-soft-rgb), 0.72);
  }

  .scenario-bar {
    min-height: 42px;
    padding: 6px 8px;
  }

  .scenario-location-button {
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 6px;
    padding: 6px 8px;
  }

  .scenario-location-button span {
    display: none;
  }

  .pane-close {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(63, 72, 74, 0.2);
    backdrop-filter: blur(4px);
    cursor: default;
    transform: none;
  }

  .mobile-backdrop:hover {
    border-color: transparent;
    transform: none;
  }

  .messages {
    min-height: 0;
    padding: 12px 10px;
    scrollbar-gutter: auto;
  }

  .message-stack {
    max-width: min(86%, 640px);
  }

  .message-time {
    display: none;
  }

  .message {
    font-size: 14px;
    line-height: 1.45;
    padding: 12px 13px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 94px;
    align-items: center;
    gap: 6px;
    min-height: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    height: 44px;
    min-height: 44px;
    max-height: 96px;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 16px;
  }

  .composer-actions span {
    display: none;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    align-self: center;
  }

  .composer-buttons {
    grid-template-columns: 34px 54px;
    gap: 6px;
  }

  .composer-buttons button {
    min-height: 44px;
    height: 44px;
    padding-inline: 0;
    border-radius: 14px;
    white-space: nowrap;
  }

  .narration-button {
    border-radius: 999px;
    font-size: 18px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .brand {
    align-items: start;
    margin-bottom: 14px;
    padding-right: 48px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .panel {
    margin-top: 14px;
    padding-top: 14px;
  }

  input,
  select,
  .character-form textarea {
    min-height: 42px;
    font-size: 16px;
  }

  .character-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .character-form {
    height: 100dvh;
    max-height: 100dvh;
  }

  .dialog-header {
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  }

  .character-form-body {
    padding: 14px 14px 4px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .dialog-actions {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 640px) {
  .app-update-notice {
    right: 10px;
    left: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom) + var(--bottom-nav-height));
    max-width: none;
    align-items: stretch;
  }

  .app-update-actions {
    justify-content: flex-end;
  }

  .chat-header h2 {
    font-size: 15px;
  }

  .message-stack {
    max-width: 90%;
  }

  .message-row {
    margin: 4px 0;
  }
}

@media (max-width: 980px) and (max-height: 520px) {
  .chat-header {
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .messages {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 94px;
    gap: 6px;
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
  }

  .composer-buttons {
    grid-template-columns: 34px 54px;
    gap: 6px;
  }

  .composer-buttons button {
    min-height: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button.is-loading::before,
  .busy-spinner {
    animation-duration: 1400ms;
  }

  .boot-splash {
    transition-duration: 180ms;
  }

  .boot-copy,
  .boot-rule span {
    animation: none;
  }

  .message-row.message-reveal {
    animation: none;
  }
}

/* ---- toast notifications (memory / secret diary added) — global ---- */
.toast-container {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 18, 28, 0.96);
  color: #f4efe7;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.6);
  font-size: 13.5px;
  line-height: 1.5;
  cursor: pointer;
  opacity: 0;
  transform: translateX(10px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.toast.is-visible {
  opacity: 1;
  transform: none;
}
.toast.is-leaving {
  opacity: 0;
  transform: translateX(10px);
}
.toast-icon {
  flex: none;
  font-size: 17px;
  line-height: 1;
}
.toast-text {
  min-width: 0;
}
@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: opacity 0.01s;
  }
}

/* ---- v2: "memory recorded" sparkle that flies from the message area to the
   note (📝) button, so a new memory/diary is noticed even if the toast is missed ---- */
.note-fly-star {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10001;
  pointer-events: none;
  font-size: 18px;
  line-height: 1;
  will-change: transform, opacity;
  filter: drop-shadow(0 0 6px rgba(255, 209, 122, 0.85));
}
/* The note button reacts when the sparkles land. */
#modernConversationNote.is-note-arrive {
  animation: noteArrivePulse 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes noteArrivePulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.4); filter: drop-shadow(0 0 10px var(--modern-amber)); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  #modernConversationNote.is-note-arrive {
    animation: none;
  }
}

/* ---- v2: conversation share dialog (✂️ clip → X) ---- */
.modern-share-dialog {
  border: 1px solid var(--modern-line);
  border-radius: 20px;
  padding: 20px;
  max-width: 460px;
  width: calc(100vw - 40px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  color: var(--modern-text);
}
.modern-share-dialog::backdrop {
  background: rgba(5, 4, 8, 0.6);
  backdrop-filter: blur(3px);
}
.modern-share-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.modern-share-head strong {
  flex: 1;
  font-family: var(--font-modern-display);
  font-size: 18px;
}
.modern-share-hint {
  color: var(--modern-muted);
  font-size: 12.5px;
  line-height: 1.6;
  margin-bottom: 14px;
}
.modern-share-preview {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--modern-line);
  background: #000;
  margin-bottom: 14px;
}
.modern-share-preview canvas {
  display: block;
  width: 100%;
  height: auto;
}
.modern-share-field {
  display: block;
  margin-bottom: 12px;
}
.modern-share-field > span {
  display: block;
  font-size: 12px;
  color: var(--modern-muted);
  margin-bottom: 5px;
}
.modern-share-field textarea,
.modern-share-field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--modern-line);
  background: var(--modern-surface);
  color: var(--modern-text);
  font: inherit;
  resize: vertical;
}
.modern-share-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
/* The share-card preview is a square quote card. */
.modern-share-preview canvas {
  aspect-ratio: 1 / 1;
}

/* Per-message share button — v2 only (gated so it never appears in legacy UI). */
.message-share {
  display: none;
}
.ui-v2 .message-row {
  position: relative;
}
.ui-v2 .message-row.assistant .message-share {
  display: inline-grid;
  place-items: center;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--modern-line);
  border-radius: 9px;
  background: rgba(20, 18, 28, 0.66);
  color: var(--modern-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.ui-v2 .message-row.assistant:hover .message-share {
  opacity: 1;
}
.ui-v2 .message-share:hover {
  color: var(--modern-amber);
  border-color: var(--modern-amber);
}
.ui-v2 .message-share svg {
  display: block;
}
/* Touch devices have no hover — keep the button faintly visible. */
@media (hover: none) {
  .ui-v2 .message-row.assistant .message-share {
    opacity: 0.55;
  }
}
