:root {
  color-scheme: light;
  --bg: #f3f2f8;
  --bg-elevated: rgba(255, 255, 255, 0.78);
  --surface: #ffffff;
  --surface-2: #f8f7fc;
  --surface-3: #efedf8;
  --text: #1d1b2d;
  --text-soft: #625f74;
  --text-faint: #817e91;
  --primary: #5b50c7;
  --primary-strong: #4438ad;
  --primary-soft: #ece9ff;
  --accent: #a84568;
  --accent-soft: #f9e8ef;
  --success: #16785c;
  --success-soft: #e2f5ee;
  --warning: #9b5d13;
  --warning-soft: #fff1d9;
  --danger: #b4233a;
  --danger-soft: #fde9ed;
  --border: #dfdce9;
  --border-strong: #c8c3da;
  --focus: #786de0;
  --shadow-sm: 0 2px 10px rgba(38, 30, 77, 0.06);
  --shadow-md: 0 14px 40px rgba(38, 30, 77, 0.1);
  --shadow-lg: 0 28px 80px rgba(28, 21, 62, 0.18);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --topbar-height: 72px;
  --mobile-tabs-height: 0px;
  --ease: 220ms cubic-bezier(.2, .8, .2, 1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111019;
  --bg-elevated: rgba(23, 21, 34, 0.84);
  --surface: #1b1927;
  --surface-2: #222031;
  --surface-3: #2b283d;
  --text: #f6f3ff;
  --text-soft: #b9b5c8;
  --text-faint: #9490a5;
  --primary: #a69eff;
  --primary-strong: #c0baff;
  --primary-soft: #322e55;
  --accent: #ee93b3;
  --accent-soft: #49293a;
  --success: #69d6b2;
  --success-soft: #173d33;
  --warning: #f2bc70;
  --warning-soft: #48351d;
  --danger: #ff91a2;
  --danger-soft: #4b2530;
  --border: #3a374b;
  --border-strong: #504b67;
  --focus: #b3abff;
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 16px 44px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.42);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, rgba(91, 80, 199, 0.14), transparent 32rem),
    radial-gradient(circle at 98% 105%, rgba(168, 69, 104, 0.1), transparent 30rem),
    var(--bg);
  font-size: 16px;
  line-height: 1.55;
  transition: color var(--ease), background-color var(--ease);
}

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

button,
label,
summary,
input[type="file"] {
  touch-action: manipulation;
}

button {
  border: 0;
}

button:not(:disabled),
summary,
.file-field {
  cursor: pointer;
}

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

button,
input,
select,
textarea,
summary,
a {
  outline: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

svg {
  display: block;
}

.icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

.skip-link {
  position: fixed;
  z-index: 2000;
  top: 10px;
  left: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  color: white;
  background: var(--primary-strong);
  transform: translateY(-150%);
  transition: transform var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(240px, 420px) minmax(220px, 1fr);
  align-items: center;
  height: var(--topbar-height);
  padding: 0 24px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  background: var(--bg-elevated);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}

.brand {
  display: inline-flex;
  width: max-content;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  overflow: visible;
  fill: var(--primary-soft);
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  filter: drop-shadow(0 5px 10px rgba(91, 80, 199, 0.16));
}

.brand-copy {
  display: grid;
  line-height: 1.1;
}

.brand-copy strong {
  font-family: ui-serif, "Songti SC", "STSong", Georgia, serif;
  font-size: 20px;
  letter-spacing: 0.12em;
}

.brand-copy small {
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.story-switcher {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 12px 7px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}

.story-switcher:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.story-switcher-copy {
  min-width: 0;
  text-align: left;
}

.story-switcher-copy small,
.story-switcher-copy strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-switcher-copy small {
  color: var(--text-faint);
  font-size: 11px;
}

.story-switcher-copy strong {
  max-width: 300px;
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.connection-pill,
.date-chip,
.chapter-chip,
.trend-chip,
.feature-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.connection-pill {
  min-height: 36px;
  padding: 0 12px;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.identity-pill {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text-soft);
  background: var(--surface);
  text-align: left;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.identity-pill:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.identity-pill .icon {
  width: 20px;
  height: 20px;
}

.identity-pill span,
.identity-pill small,
.identity-pill strong {
  display: block;
}

.identity-pill small {
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.2;
}

.identity-pill strong {
  margin-top: 2px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

body[data-identity-state="loading"] .connection-pill .status-dot {
  background: var(--warning);
  animation: identity-pulse 1.2s ease-in-out infinite;
}

body[data-identity-state="fallback"] .identity-pill .icon {
  color: var(--warning);
}

.connection-pill.error .status-dot {
  background: var(--danger);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 13%, transparent);
}

.status-dot.small {
  width: 6px;
  height: 6px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 13%, transparent);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text-soft);
  background: var(--surface);
  transition: color var(--ease), border-color var(--ease), background var(--ease), transform var(--ease);
}

.icon-button:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--primary);
  background: var(--primary-soft);
}

.icon-button:active:not(:disabled),
.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.send-button:active:not(:disabled) {
  transform: scale(0.97);
}

.icon-button.subtle {
  background: transparent;
  box-shadow: none;
}

.icon-button.compact {
  width: 40px;
  height: 40px;
  border-radius: 12px;
}

.theme-icon-dark,
html[data-theme="dark"] .theme-icon-light {
  display: none;
}

html[data-theme="dark"] .theme-icon-dark {
  display: block;
}

.mobile-tabs {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 294px) minmax(420px, 1fr) minmax(290px, 336px);
  gap: 1px;
  height: calc(100dvh - var(--topbar-height) - var(--mobile-tabs-height));
  min-height: 0;
  background: var(--border);
}

.panel {
  min-width: 0;
  min-height: 0;
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
}

.panel-scroll {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.story-panel .panel-scroll,
.insight-panel .panel-scroll {
  padding: 22px;
}

.character-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.cover-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background:
    radial-gradient(circle at 68% 28%, rgba(255,255,255,.56), transparent 23%),
    linear-gradient(135deg, #5b50c7, #8c5ea9 55%, #bd6c82);
}

.cover-frame::after {
  position: absolute;
  inset: auto 0 0;
  height: 42%;
  content: "";
  background: linear-gradient(transparent, rgba(20, 15, 40, 0.44));
  pointer-events: none;
}

.cover-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
}

.cover-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.9);
}

.cover-fallback span {
  position: absolute;
  z-index: 2;
  font-family: ui-serif, "Songti SC", serif;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 700;
  text-shadow: 0 8px 28px rgba(29, 20, 62, 0.32);
}

.cover-fallback svg {
  position: absolute;
  right: -13%;
  bottom: -25%;
  width: 84%;
  fill: rgba(255, 255, 255, 0.08);
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 2;
}

.chapter-chip {
  position: absolute;
  z-index: 2;
  top: 14px;
  left: 14px;
  min-height: 30px;
  padding: 0 11px;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(22, 17, 42, 0.45);
  backdrop-filter: blur(10px);
}

.character-copy {
  padding: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.character-copy h1,
.section-heading h2,
.section-heading h3,
.modal-header h2,
.confirm-shell h2,
.empty-chat h2,
.creation-card h4 {
  margin: 0;
  color: var(--text);
  line-height: 1.25;
}

.character-copy h1 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 24px;
}

.character-copy > p:last-child {
  display: -webkit-box;
  margin: 9px 0 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.context-card {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, var(--surface), var(--surface-2));
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading.compact {
  align-items: center;
}

.section-heading h2,
.section-heading h3 {
  font-size: 17px;
}

.date-chip {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text-soft);
  background: var(--surface-3);
}

.story-goal {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.65;
}

.journey-section,
.insight-section {
  margin-top: 24px;
}

.text-button {
  min-height: 36px;
  padding: 0 6px;
  color: var(--primary);
  background: transparent;
  font-size: 13px;
  font-weight: 700;
}

.text-button:hover {
  color: var(--primary-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.stage-rail,
.full-stage-map {
  padding: 0;
  margin: 0;
  list-style: none;
}

.stage-rail li {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  min-height: 58px;
  padding-bottom: 12px;
}

.stage-rail li::before {
  position: absolute;
  top: 24px;
  bottom: -2px;
  left: 13px;
  width: 2px;
  content: "";
  background: var(--border);
}

.stage-rail li:last-child::before {
  display: none;
}

.stage-node {
  position: relative;
  z-index: 1;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-faint);
  background: var(--surface);
}

.stage-node .icon {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}

.stage-rail li.completed::before {
  background: var(--success);
}

.stage-rail li.completed .stage-node {
  border-color: var(--success);
  color: white;
  background: var(--success);
}

.stage-rail li.current .stage-node {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 11%, transparent);
}

.stage-item-copy strong,
.stage-item-copy span {
  display: block;
}

.stage-item-copy strong {
  padding-top: 2px;
  font-size: 13px;
  line-height: 1.35;
}

.stage-item-copy span {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface-2);
}

.chat-header {
  display: flex;
  min-height: 70px;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.avatar,
.message-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
  border-radius: 50%;
  color: var(--primary-strong);
  background: linear-gradient(145deg, var(--primary-soft), var(--surface));
  font-family: ui-serif, "Songti SC", serif;
  font-weight: 700;
}

.avatar {
  width: 44px;
  height: 44px;
  font-size: 17px;
}

.chat-identity {
  min-width: 0;
  flex: 1;
}

.chat-identity h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-identity p {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 3px 0 0;
  color: var(--text-faint);
  font-size: 12px;
}

.chat-feed {
  position: relative;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.message-list {
  width: min(100%, 820px);
  min-height: 100%;
  padding: 24px clamp(18px, 4vw, 54px) 12px;
  margin: 0 auto;
}

.empty-chat {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  max-width: 520px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 32px;
  margin: auto;
  text-align: center;
}

.empty-chat[hidden] {
  display: none;
}

.empty-orbit {
  position: relative;
  display: grid;
  width: 112px;
  height: 112px;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--surface), var(--primary-soft));
  box-shadow: var(--shadow-md);
}

.empty-orbit::before,
.empty-orbit::after {
  position: absolute;
  inset: -12px;
  content: "";
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  border-radius: 50%;
}

.empty-orbit::after {
  inset: -23px;
  border-style: dashed;
  animation: orbit 18s linear infinite;
}

.empty-orbit > span {
  position: absolute;
  z-index: 2;
  width: 8px;
  height: 8px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
}

.empty-orbit > span:nth-child(1) { top: -16px; left: 49px; }
.empty-orbit > span:nth-child(2) { right: -8px; bottom: 13px; background: var(--primary); }
.empty-orbit > span:nth-child(3) { bottom: -19px; left: 22px; background: var(--success); }

.empty-orbit svg {
  width: 48px;
  color: var(--primary);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.empty-chat h2 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 28px;
}

.empty-chat > p:not(.eyebrow) {
  max-width: 420px;
  margin: 10px 0 22px;
  color: var(--text-soft);
  line-height: 1.7;
}

.message-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  max-width: 82%;
  margin-bottom: 18px;
  animation: message-in 260ms cubic-bezier(.2, .8, .2, 1) both;
}

.message-row.user {
  grid-template-columns: minmax(0, 1fr);
  margin-left: auto;
}

.message-avatar {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

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

.message-name {
  display: block;
  margin: 0 0 5px 3px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 650;
}

.message-bubble {
  width: fit-content;
  max-width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 7px 17px 17px 17px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.user .message-bubble {
  margin-left: auto;
  border-color: transparent;
  border-radius: 17px 7px 17px 17px;
  color: white;
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--primary) 20%, transparent);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 3px 0;
  color: var(--text-faint);
  font-size: 10px;
}

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

.turn-result-card {
  grid-column: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 10px;
  margin-top: -9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-soft);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  font-size: 11px;
}

.turn-result-card .delta {
  color: var(--success);
  font-weight: 800;
}

.turn-result-card .delta.negative {
  color: var(--danger);
}

.typing-row {
  display: grid;
  grid-template-columns: 34px auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(100%, 820px);
  padding: 4px clamp(18px, 4vw, 54px) 24px;
  margin: 0 auto;
}

.typing-row[hidden] {
  display: none;
}

.typing-row p {
  margin: 0;
  color: var(--text-faint);
  font-size: 11px;
}

.typing-bubble {
  display: flex;
  min-width: 60px;
  height: 38px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 6px 16px 16px;
  background: var(--surface);
}

.typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing 1.15s ease-in-out infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 120ms; }
.typing-bubble span:nth-child(3) { animation-delay: 240ms; }

.composer-wrap {
  padding: 10px clamp(14px, 3vw, 28px) 16px;
  border-top: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}

.quick-prompts {
  display: flex;
  width: min(100%, 800px);
  gap: 7px;
  padding: 0 2px 9px;
  margin: auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-prompts::-webkit-scrollbar {
  display: none;
}

.quick-prompts button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: var(--surface);
  font-size: 11px;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.quick-prompts button:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  width: min(100%, 800px);
  gap: 2px 10px;
  padding: 9px 9px 7px 14px;
  margin: auto;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.composer:focus-within {
  border-color: var(--focus);
  box-shadow: var(--shadow-md), 0 0 0 3px color-mix(in srgb, var(--focus) 14%, transparent);
}

.composer textarea {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  min-height: 42px;
  max-height: 150px;
  padding: 9px 0 2px;
  resize: none;
  overflow-y: auto;
  border: 0;
  color: var(--text);
  background: transparent;
  font-size: 15px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: var(--text-faint);
}

.composer textarea:focus-visible {
  box-shadow: none;
}

.composer-meta {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-faint);
  font-size: 10px;
}

.composer-status {
  width: min(100%, 800px);
  margin: 8px auto 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.send-button {
  grid-column: 2;
  grid-row: 1 / 3;
  display: inline-flex;
  min-width: 88px;
  min-height: 48px;
  align-items: center;
  align-self: end;
  justify-content: center;
  gap: 7px;
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  box-shadow: 0 8px 18px color-mix(in srgb, var(--primary) 24%, transparent);
  font-size: 13px;
  font-weight: 750;
  transition: transform var(--ease), box-shadow var(--ease), filter var(--ease);
}

.send-button:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 11px 24px color-mix(in srgb, var(--primary) 30%, transparent);
}

.send-button.loading .icon {
  animation: spin 900ms linear infinite;
}

.relationship-hero {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(155deg, var(--surface), color-mix(in srgb, var(--primary-soft) 42%, var(--surface)));
  box-shadow: var(--shadow-sm);
}

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

.trend-chip.positive {
  color: var(--success);
  background: var(--success-soft);
}

.trend-chip.negative {
  color: var(--danger);
  background: var(--danger-soft);
}

.trend-chip.neutral {
  color: var(--text-soft);
  background: var(--surface-3);
}

.affinity-gauge {
  position: relative;
  display: grid;
  width: 158px;
  height: 158px;
  place-items: center;
  margin: 18px auto;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--progress) * 1%), var(--surface-3) 0);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent), 0 12px 30px rgba(51, 39, 111, 0.1);
}

.affinity-gauge::before {
  position: absolute;
  inset: 12px;
  content: "";
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}

.gauge-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  width: 110px;
  text-align: center;
}

.gauge-inner strong {
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.gauge-inner > span {
  margin-left: 3px;
  color: var(--text-faint);
  font-size: 11px;
}

.gauge-inner small {
  flex-basis: 100%;
  margin-top: 7px;
  color: var(--text-soft);
  font-size: 11px;
}

.stage-progress-copy {
  display: flex;
  justify-content: space-between;
  color: var(--text-soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.linear-progress {
  position: relative;
  height: 6px;
  overflow: hidden;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--surface-3);
}

.linear-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 400ms cubic-bezier(.2, .8, .2, 1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.stats-grid article {
  min-width: 0;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  text-align: center;
}

.stats-grid span,
.stats-grid strong {
  display: block;
}

.stats-grid span {
  color: var(--text-faint);
  font-size: 10px;
}

.stats-grid strong {
  margin-top: 3px;
  overflow: hidden;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}

.gate-list,
.thread-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.gate-list li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  color: var(--text-soft);
  font-size: 12px;
}

.gate-list li:last-child {
  border-bottom: 0;
}

.gate-status {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-faint);
  background: var(--surface);
}

.gate-status .icon {
  width: 12px;
  height: 12px;
  stroke-width: 2.2;
}

.gate-list li.complete .gate-status {
  border-color: var(--success);
  color: white;
  background: var(--success);
}

.plot-control-entry {
  display: grid;
  gap: 10px;
  padding: 13px;
  margin-top: 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary-soft) 42%, var(--surface));
}

.plot-control-entry strong,
.plot-control-entry p {
  display: block;
  margin: 0;
}

.plot-control-entry strong {
  font-size: 12px;
}

.plot-control-entry p {
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.55;
}

.plot-control-entry .secondary-button {
  width: 100%;
}

.memory-card {
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.memory-card summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  list-style: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.memory-card summary::-webkit-details-marker {
  display: none;
}

.memory-card summary > span {
  display: flex;
  align-items: center;
  gap: 9px;
}

.memory-card summary > span .icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.memory-card .chevron {
  width: 17px;
  height: 17px;
  transition: transform var(--ease);
}

.memory-card[open] .chevron {
  transform: rotate(180deg);
}

.memory-content {
  padding: 0 14px 14px;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.memory-content > p {
  margin: 12px 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.65;
}

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

.memory-tags span {
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 10px;
}

.thread-list {
  padding: 0 14px 14px;
}

.thread-list li {
  position: relative;
  padding: 9px 0 9px 15px;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  color: var(--text-soft);
  font-size: 12px;
}

.thread-list li::before {
  position: absolute;
  top: 16px;
  left: 0;
  width: 6px;
  height: 6px;
  content: "";
  border: 2px solid var(--accent);
  border-radius: 50%;
}

.modal {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

.modal::backdrop {
  background: rgba(10, 8, 20, 0.62);
  backdrop-filter: blur(8px);
}

.modal[open] {
  display: grid;
  place-items: center;
  animation: modal-backdrop-in 180ms ease-out both;
}

.modal-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, calc(100vw - 40px));
  max-height: min(850px, calc(100dvh - 40px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 240ms cubic-bezier(.2, .8, .2, 1) both;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--primary-soft) 38%, var(--surface)));
}

.modal-header > div:first-child {
  min-width: 0;
}

.modal-header h2 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 26px;
}

.modal-header p:last-child {
  max-width: 640px;
  margin: 7px 0 0;
  color: var(--text-soft);
  font-size: 13px;
}

.modal-close {
  flex: 0 0 auto;
}

.modal-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 26px 34px;
  overscroll-behavior: contain;
}

.library-section,
.create-section {
  margin-bottom: 30px;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.story-grid-empty {
  grid-column: 1 / -1;
  padding: 30px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-soft);
  background: var(--surface-2);
  text-align: center;
}

.story-tile {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 12px;
  min-height: 82px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--surface-2);
  text-align: left;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}

.story-tile:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-2px);
}

.story-tile.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 14%, transparent);
}

.story-tile-cover {
  display: grid;
  width: 58px;
  height: 58px;
  overflow: hidden;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-family: ui-serif, "Songti SC", serif;
  font-size: 22px;
  font-weight: 700;
}

.story-tile-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-tile-copy {
  min-width: 0;
}

.story-tile-copy strong,
.story-tile-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-tile-copy strong {
  font-size: 13px;
}

.story-tile-copy span {
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 11px;
}

.story-tile > .icon {
  width: 18px;
  height: 18px;
  color: var(--text-faint);
}

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

.creation-card {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.creation-card.featured {
  grid-column: 1 / -1;
  background:
    linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
    linear-gradient(120deg, var(--primary), var(--accent)) border-box;
  border: 1px solid transparent;
}

.creation-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  margin-bottom: 13px;
  border-radius: 13px;
  color: var(--primary);
  background: var(--primary-soft);
}

.creation-icon.accent {
  color: var(--accent);
  background: var(--accent-soft);
}

.creation-icon.warm {
  color: var(--warning);
  background: var(--warning-soft);
}

.feature-label {
  position: absolute;
  top: 20px;
  right: 20px;
  min-height: 26px;
  padding: 0 9px;
  color: var(--accent);
  background: var(--accent-soft);
}

.creation-card h4 {
  font-size: 17px;
}

.creation-card > p {
  min-height: 44px;
  margin: 7px 0 16px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.creation-card label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
}

.creation-card label b {
  color: var(--danger);
}

.creation-card input,
.creation-card textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface);
  font-size: 13px;
}

.creation-card textarea {
  min-height: 76px;
  line-height: 1.5;
}

.file-field {
  display: flex !important;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 11px;
  color: var(--primary) !important;
  background: var(--surface);
  text-align: center;
}

.file-field:has(input:focus-visible) {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

.file-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.creation-card > small {
  display: block;
  margin-top: 9px;
  color: var(--text-faint);
  font-size: 10px;
}

.creation-card > .file-hint {
  min-height: 0;
  margin: -4px 0 12px;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
}

.creation-card > .file-hint.error {
  color: var(--danger);
  font-weight: 650;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 750;
  transition: transform var(--ease), border-color var(--ease), background var(--ease), filter var(--ease);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 20%, transparent);
}

.secondary-button {
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.danger-button {
  color: white;
  background: var(--danger);
}

.job-section {
  position: sticky;
  z-index: 3;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 18px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.job-section[data-status="problem"] {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--border));
}

.job-section[hidden] {
  display: none;
}

.job-copy {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.job-copy strong,
.job-copy p {
  display: block;
  margin: 0;
}

.job-copy p {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.job-spinner {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.job-section[data-status="problem"] .job-spinner {
  border-color: color-mix(in srgb, var(--danger) 22%, var(--border));
  border-top-color: var(--danger);
  animation-duration: 1.4s;
}

.job-metrics {
  display: flex;
  min-width: 108px;
  align-self: center;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.job-metrics span:first-child {
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.job-section[data-status="problem"] .job-metrics span:first-child {
  color: var(--danger);
}

.job-metrics span:last-child {
  color: var(--text-faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.job-section .linear-progress {
  grid-column: 1 / -1;
  margin-top: 0;
}

.job-actions {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 8px;
  margin-top: -4px;
}

.job-actions:empty,
.job-actions:not(:has(button:not([hidden]))) {
  display: none;
}

.job-actions .text-button {
  min-height: 44px;
  padding-inline: 10px;
}

.map-modal .modal-shell {
  width: min(1180px, calc(100vw - 40px));
}

.map-scroll {
  background: var(--surface-2);
}

.map-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.map-summary article {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.map-summary span,
.map-summary strong {
  display: block;
}

.map-summary span {
  color: var(--text-faint);
  font-size: 10px;
}

.map-summary strong {
  margin-top: 4px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.map-guide,
.map-route,
.map-detail-card,
.map-simulator {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.map-guide {
  margin-bottom: 18px;
  overflow: hidden;
}

.map-guide summary {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 16px;
  list-style: none;
}

.map-guide summary::-webkit-details-marker {
  display: none;
}

.map-guide summary span,
.map-guide summary strong,
.map-guide summary small {
  display: block;
}

.map-guide summary strong {
  font-size: 14px;
}

.map-guide summary small {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 11px;
}

.map-guide summary .chevron {
  transition: transform var(--ease);
}

.map-guide[open] summary .chevron {
  transform: rotate(180deg);
}

.map-guide-content {
  padding: 2px 16px 16px;
  border-top: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.commit-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr auto 1fr;
  align-items: stretch;
  gap: 8px;
  padding-top: 14px;
}

.commit-flow article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
}

.commit-flow article > span {
  color: var(--primary);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.commit-flow strong,
.commit-flow p {
  display: block;
  margin: 0;
}

.commit-flow strong {
  margin-top: 4px;
  font-size: 12px;
}

.commit-flow p {
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.55;
}

.commit-flow .dual-flow {
  border-color: color-mix(in srgb, var(--primary) 38%, var(--border));
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
}

.flow-arrow {
  align-self: center;
  color: var(--text-faint);
}

.score-rule-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.score-rule-grid article {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 11px;
  background: var(--surface-3);
}

.score-rule-grid strong,
.score-rule-grid span {
  display: block;
}

.score-rule-grid strong {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.score-rule-grid span {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 9px;
  line-height: 1.45;
}

.score-rule-grid .negative {
  color: var(--danger);
  background: var(--danger-soft);
}

.score-rule-grid .positive {
  color: var(--success);
  background: var(--success-soft);
}

.score-rule-grid .soft {
  opacity: 0.9;
}

.map-route,
.map-simulator {
  padding: 17px;
}

.map-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}

.map-section-heading h3,
.map-section-heading p {
  margin: 0;
}

.map-section-heading h3 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 18px;
}

.map-section-heading > p {
  color: var(--text-faint);
  font-size: 10px;
  text-align: right;
}

.map-stage-viewport {
  overflow-x: auto;
  padding: 3px 3px 11px;
  overscroll-behavior-inline: contain;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}

.full-stage-map {
  display: flex;
  width: max-content;
  align-items: stretch;
  gap: 24px;
}

.full-stage-map li {
  position: relative;
  width: 238px;
  flex: 0 0 238px;
}

.full-stage-map li:not(:last-child)::after {
  position: absolute;
  z-index: 0;
  top: 31px;
  left: calc(100% + 5px);
  width: 15px;
  height: 2px;
  content: "";
  background: var(--border-strong);
}

.full-stage-map li.completed:not(:last-child)::after {
  background: var(--success);
}

.map-stage-button {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  min-height: 218px;
  flex-direction: column;
  align-items: stretch;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  color: var(--text);
  background: var(--surface-2);
  text-align: left;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease), transform var(--ease);
}

.map-stage-button:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.full-stage-map li.current .map-stage-button {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface));
}

.full-stage-map li.completed .map-stage-button {
  border-color: color-mix(in srgb, var(--success) 48%, var(--border));
}

.full-stage-map li.selected .map-stage-button {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent), var(--shadow-sm);
}

.map-stage-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.full-stage-number {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  margin-bottom: 0;
  border-radius: 9px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 800;
}

.full-stage-map li.completed .full-stage-number {
  color: var(--success);
  background: var(--success-soft);
}

.map-stage-status {
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.04em;
}

.map-stage-name {
  margin-top: 11px;
  font-size: 14px;
}

.map-stage-cap,
.map-stage-reason,
.map-stage-overlay {
  display: block;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.5;
}

.map-stage-cap {
  margin-top: 3px;
  color: var(--primary);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.map-stage-reason {
  margin-top: 12px;
}

.map-stage-overlay {
  display: -webkit-box;
  margin-top: 7px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.map-detail-grid {
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  gap: 14px;
  margin-top: 14px;
}

.map-detail-card {
  min-width: 0;
  padding: 18px;
}

.map-detail-card > h3 {
  margin: 3px 0 0;
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 21px;
}

.map-detail-block {
  margin-top: 17px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.map-detail-block h4,
.map-detail-block p {
  margin: 0;
}

.map-detail-block h4 {
  margin-bottom: 7px;
  font-size: 11px;
}

.map-detail-block > p,
.map-helper {
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.65;
}

.map-gate-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.map-gate-chips span {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px;
}

.map-gate-chips .met {
  border-color: color-mix(in srgb, var(--success) 42%, var(--border));
  color: var(--success);
  background: var(--success-soft);
}

.map-gate-chips .missing {
  border-color: color-mix(in srgb, var(--warning) 42%, var(--border));
  color: var(--warning);
  background: var(--warning-soft);
}

.map-event-list {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.map-event-list article {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}

.map-event-state {
  align-self: start;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--warning);
  background: var(--warning-soft);
  font-size: 9px;
  font-weight: 750;
}

.map-event-list article.complete .map-event-state {
  color: var(--success);
  background: var(--success-soft);
}

.map-event-list strong,
.map-event-list small,
.map-event-list p {
  display: block;
  margin: 0;
}

.map-event-list strong {
  font-size: 11px;
}

.map-event-list small,
.map-event-list p,
.map-empty {
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.5;
}

.map-event-list p {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.prompt-diff-card .map-helper {
  margin: 7px 0 0;
}

.map-prompt-change {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  margin-top: 14px;
}

.map-prompt-box {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.map-prompt-box.current {
  border-color: color-mix(in srgb, var(--primary) 42%, var(--border));
  background: var(--primary-soft);
}

.map-prompt-box small,
.map-prompt-box p {
  display: block;
  margin: 0;
}

.map-prompt-box small {
  color: var(--text-faint);
  font-size: 9px;
}

.map-prompt-box p {
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.65;
}

.map-change-arrow {
  align-self: center;
  color: var(--primary);
}

.map-simulator {
  margin-top: 14px;
}

.map-simulator-fields {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, minmax(110px, .7fr));
  gap: 9px;
}

.map-simulator-fields label,
.map-simulator-fields label > span {
  display: block;
}

.map-simulator-fields label > span,
.map-sim-events legend {
  margin-bottom: 5px;
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 700;
}

.map-simulator-fields input,
.map-simulator-fields select {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-2);
  font: inherit;
  font-size: 11px;
}

.map-sim-events {
  min-width: 0;
  padding: 0;
  margin: 13px 0 0;
  border: 0;
}

.map-sim-events > div {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 7px;
}

.map-sim-event {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 8px;
  min-height: 50px;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.map-sim-event input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.map-sim-event strong,
.map-sim-event small {
  display: block;
}

.map-sim-event strong {
  font-size: 10px;
}

.map-sim-event small {
  color: var(--text-faint);
  font-size: 9px;
}

.map-sim-result {
  padding: 12px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.map-sim-result.pass {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
  background: var(--success-soft);
}

.map-sim-result.blocked {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--border));
  background: var(--warning-soft);
}

.map-sim-result strong,
.map-sim-result p {
  display: block;
  margin: 0;
}

.map-sim-result strong {
  font-size: 12px;
}

.map-sim-result p {
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.55;
}

.map-header-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.map-customization-status {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  background: var(--surface);
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.map-customization-status.customized {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  color: var(--primary);
  background: var(--primary-soft);
}

.map-edit-button {
  flex: 0 0 auto;
}

.map-progress-button {
  flex: 0 0 auto;
}

.progress-control-modal[open] {
  z-index: 90;
}

.progress-control-shell {
  grid-template-rows: auto minmax(0, 1fr);
  width: min(940px, calc(100vw - 40px));
}

.progress-control-form {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
}

.progress-control-scroll {
  display: grid;
  align-content: start;
  gap: 16px;
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--primary-soft) 30%, transparent), transparent 26rem),
    var(--surface-2);
}

.progress-control-warning {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 11px;
  padding: 14px 15px;
  border: 1px solid color-mix(in srgb, var(--warning) 48%, var(--border));
  border-radius: 14px;
  color: var(--warning);
  background: var(--warning-soft);
}

.progress-control-warning .icon {
  width: 24px;
  height: 24px;
}

.progress-control-warning strong,
.progress-control-warning p {
  display: block;
  margin: 0;
}

.progress-control-warning strong {
  font-size: 12px;
}

.progress-control-warning p {
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.55;
}

.progress-control-current,
.progress-control-editor {
  min-width: 0;
  padding: 19px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.progress-control-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.progress-control-section-heading h3,
.progress-control-section-heading p {
  margin: 0;
}

.progress-control-section-heading h3 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 19px;
}

.progress-control-section-heading > p {
  color: var(--text-faint);
  font-size: 10px;
  text-align: right;
}

.progress-current-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.progress-current-grid article {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}

.progress-current-grid span,
.progress-current-grid strong {
  display: block;
}

.progress-current-grid span {
  color: var(--text-faint);
  font-size: 9px;
}

.progress-current-grid strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.progress-control-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.progress-control-fields label {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 6px;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
}

.progress-control-fields b {
  color: var(--danger);
}

.progress-control-fields input,
.progress-control-fields select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.progress-control-fields label > small:not(.field-error) {
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 500;
  line-height: 1.5;
}

.progress-control-fields input[aria-invalid="true"],
.progress-control-fields select[aria-invalid="true"],
#progressEventOptions[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 13%, transparent);
}

.progress-event-options {
  min-width: 0;
  padding: 14px;
  margin: 16px 0 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
}

.progress-event-options legend {
  padding: 0 5px;
  font-size: 10px;
  font-weight: 750;
}

.progress-event-options > p,
.progress-events-empty {
  margin: 0 0 9px;
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.5;
}

#progressEventOptions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  border-radius: 11px;
}

.progress-event-option {
  display: grid;
  min-width: 0;
  min-height: 52px;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.progress-event-option:has(input:checked) {
  border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
  background: var(--primary-soft);
}

.progress-event-option:has(input:focus-visible) {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

.progress-event-option input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}

.progress-event-option strong,
.progress-event-option small {
  display: block;
  overflow-wrap: anywhere;
}

.progress-event-option strong {
  font-size: 10px;
}

.progress-event-option small {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 8px;
}

.progress-event-pagination {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
}

.progress-event-pagination p {
  margin: 0;
  color: var(--text-faint);
  font-size: 9px;
}

.progress-route-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
}

.progress-route-link .icon {
  width: 18px;
  height: 18px;
}

.progress-control-error-summary {
  padding: 13px 15px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--border));
  border-radius: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 11px;
}

.progress-control-error-summary p {
  margin: 4px 0 0;
}

.progress-control-error-summary ul {
  padding-left: 18px;
  margin: 6px 0 0;
}

.progress-control-actions {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 26px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -8px 30px color-mix(in srgb, var(--text) 5%, transparent);
}

.progress-control-actions > div:last-child {
  display: flex;
  gap: 9px;
}

.progress-control-save-state {
  color: var(--success);
  font-size: 10px;
  font-weight: 700;
}

.progress-control-save-state.dirty {
  color: var(--warning);
}

#reviewProgressControlButton.loading .icon {
  opacity: 0.45;
}

.progress-warning-icon {
  color: var(--warning);
  background: var(--warning-soft);
}

.progress-confirm-shell {
  width: min(500px, calc(100vw - 32px)) !important;
}

.progress-confirm-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px 12px;
  padding: 12px;
  margin: -9px 0 20px;
  border-radius: 12px;
  background: var(--surface-2);
  text-align: left;
}

.progress-confirm-summary dt,
.progress-confirm-summary dd {
  margin: 0;
  font-size: 10px;
}

.progress-confirm-summary dt {
  color: var(--text-faint);
}

.progress-confirm-summary dd {
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 700;
}

.relationship-editor-modal[open] {
  z-index: 90;
}

.relationship-editor-shell {
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, calc(100vw - 40px));
}

.relationship-editor-form {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
}

.relationship-editor-scroll {
  display: grid;
  align-content: start;
  gap: 18px;
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--primary-soft) 32%, transparent), transparent 28rem),
    var(--surface-2);
}

.relationship-style-section,
.relationship-stage-section {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.relationship-editor-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 15px;
}

.relationship-editor-section-heading h3,
.relationship-editor-section-heading p {
  margin: 0;
}

.relationship-editor-section-heading h3 {
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 19px;
}

.relationship-editor-section-heading > p {
  max-width: 480px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.55;
  text-align: right;
}

.relationship-style-options {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 9px;
  padding: 0;
  margin: 0;
  border: 0;
}

.relationship-style-options label {
  display: grid;
  min-width: 0;
  min-height: 72px;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease), transform var(--ease);
}

.relationship-style-options label:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.relationship-style-options label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 12%, transparent);
}

.relationship-style-options label:has(input:focus-visible) {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

.relationship-style-options input,
.relationship-event-option input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}

.relationship-style-options strong,
.relationship-style-options small,
.relationship-event-option strong,
.relationship-event-option small {
  display: block;
}

.relationship-style-options strong {
  font-size: 12px;
}

.relationship-style-options small {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.45;
}

.relationship-custom-guidance {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  padding: 15px;
  border: 1px solid color-mix(in srgb, var(--primary) 32%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary-soft) 40%, var(--surface));
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.relationship-custom-guidance b,
.relationship-stage-fields b {
  color: var(--danger);
}

.relationship-custom-guidance textarea,
.relationship-stage-fields input,
.relationship-stage-fields textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface);
  font-size: 12px;
  line-height: 1.55;
}

.relationship-custom-guidance textarea,
.relationship-stage-fields textarea {
  min-height: 88px;
  resize: vertical;
}

.relationship-custom-guidance > small:not(.field-error),
.relationship-stage-fields label > small:not(.field-error) {
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 500;
}

.relationship-stage-tabs-viewport {
  max-width: 100%;
  overflow-x: auto;
  padding: 3px 3px 10px;
  overscroll-behavior-inline: contain;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}

.relationship-stage-tabs {
  display: flex;
  width: max-content;
  gap: 9px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.relationship-stage-tabs li {
  width: 205px;
  flex: 0 0 205px;
}

.relationship-stage-tab {
  display: grid;
  width: 100%;
  min-height: 58px;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-soft);
  background: var(--surface-2);
  text-align: left;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease), transform var(--ease);
}

.relationship-stage-tab:hover:not(:disabled) {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.relationship-stage-tab[aria-pressed="true"] {
  border-color: var(--primary);
  color: var(--text);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 13%, transparent);
}

.relationship-stage-tab > span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  color: var(--primary);
  background: var(--surface);
  font-size: 10px;
  font-weight: 800;
}

.relationship-stage-tab strong {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relationship-stage-editor {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
}

.relationship-stage-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.relationship-stage-editor-header h4 {
  margin: 3px 0 0;
  font-family: ui-serif, "Songti SC", Georgia, serif;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.relationship-stage-nav {
  display: flex;
  gap: 7px;
}

.relationship-stage-nav .icon-button {
  width: 44px;
  height: 44px;
}

.relationship-readonly-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.relationship-readonly-grid > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.relationship-readonly-grid span,
.relationship-readonly-grid code,
.relationship-readonly-grid strong {
  display: block;
}

.relationship-readonly-grid span {
  color: var(--text-faint);
  font-size: 8px;
  font-weight: 700;
}

.relationship-readonly-grid code,
.relationship-readonly-grid strong {
  margin-top: 3px;
  overflow-wrap: anywhere;
  color: var(--text-soft);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.relationship-stage-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  margin-top: 15px;
}

.relationship-stage-fields label {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 6px;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
}

.relationship-stage-fields .wide {
  grid-column: 1 / -1;
}

.relationship-stage-fields input[aria-invalid="true"],
.relationship-stage-fields textarea[aria-invalid="true"],
.relationship-custom-guidance textarea[aria-invalid="true"],
.relationship-event-options div[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 13%, transparent);
}

.field-error {
  color: var(--danger) !important;
  font-size: 9px !important;
  font-weight: 650 !important;
}

.relationship-event-options {
  min-width: 0;
  padding: 14px;
  margin: 15px 0 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
}

.relationship-event-options legend {
  padding: 0 5px;
  font-size: 10px;
  font-weight: 750;
}

.relationship-event-options > p,
.relationship-events-note,
.relationship-events-empty {
  margin: 0 0 9px;
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.5;
}

#relationshipStageEvents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  border-radius: 11px;
}

.relationship-event-option {
  display: grid;
  min-width: 0;
  min-height: 52px;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.relationship-event-option:has(input:checked) {
  border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
  background: var(--primary-soft);
}

.relationship-event-option:has(input:focus-visible) {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

.relationship-event-option strong {
  overflow-wrap: anywhere;
  font-size: 10px;
}

.relationship-event-option small {
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--text-faint);
  font-size: 8px;
}

.relationship-event-pagination {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
}

.relationship-event-pagination p {
  margin: 0;
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.5;
}

.relationship-event-pagination button {
  flex: 0 0 auto;
}

.relationship-editor-error-summary {
  padding: 13px 15px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--border));
  border-radius: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 11px;
}

.relationship-editor-error-summary p {
  margin: 4px 0 0;
}

.relationship-editor-error-summary ul {
  padding-left: 18px;
  margin: 6px 0 0;
}

.relationship-editor-actions {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 26px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -8px 30px color-mix(in srgb, var(--text) 5%, transparent);
}

.relationship-editor-actions > div:last-child {
  display: flex;
  gap: 9px;
}

.relationship-editor-save-state {
  color: var(--success);
  font-size: 10px;
  font-weight: 700;
}

.relationship-editor-save-state.dirty {
  color: var(--warning);
}

#saveRelationshipMapButton.loading .icon {
  opacity: 0.45;
}

.relationship-reset-icon {
  color: var(--warning);
  background: var(--warning-soft);
}

.identity-modal[open] {
  z-index: 80;
}

.identity-shell {
  width: min(560px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 220ms cubic-bezier(.2, .8, .2, 1) both;
}

.identity-content {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  padding: 22px 24px 25px;
}

.identity-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  color: var(--primary);
  background: var(--primary-soft);
}

.identity-mark .icon {
  width: 26px;
  height: 26px;
}

.identity-content strong,
.identity-content p {
  display: block;
  margin: 0;
}

.identity-content > div:nth-child(2) > strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.identity-content p,
.identity-content li {
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.65;
}

.identity-content p {
  margin-top: 5px;
}

.identity-content ul {
  grid-column: 1 / -1;
  padding: 13px 13px 13px 31px;
  margin: 3px 0 0;
  border-radius: 12px;
  background: var(--surface-2);
}

.export-modal[open] {
  z-index: 85;
}

.export-shell {
  width: min(620px, calc(100vw - 32px));
  grid-template-rows: auto minmax(0, 1fr);
}

.export-form {
  display: grid;
  overflow-x: hidden;
  overflow-y: auto;
  gap: 18px;
  padding: 22px 24px 24px;
  overscroll-behavior: contain;
}

.export-format-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0;
  margin: 0;
  border: 0;
}

.export-format-options legend {
  grid-column: 1 / -1;
  padding: 0;
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 750;
}

.export-format-card {
  display: grid;
  min-width: 0;
  min-height: 126px;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease), transform var(--ease);
}

.export-format-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.export-format-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 12%, transparent);
}

.export-format-card:has(input:focus-visible) {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 42%, transparent);
}

.export-format-card input,
.export-affection-option input {
  width: 19px;
  height: 19px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.export-format-badge {
  grid-column: 2;
  width: max-content;
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--primary);
  background: var(--surface);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
}

.export-format-card > span:last-child {
  grid-column: 2;
}

.export-format-card strong,
.export-format-card small,
.export-affection-option strong,
.export-affection-option small {
  display: block;
}

.export-format-card strong,
.export-affection-option strong {
  font-size: 13px;
}

.export-format-card small,
.export-affection-option small {
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.55;
}

.export-affection-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 11px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent-soft) 46%, var(--surface));
  cursor: pointer;
}

.export-summary {
  padding: 10px 12px;
  margin: 0;
  border-radius: 11px;
  color: var(--text-soft);
  background: var(--surface-2);
  font-size: 11px;
  line-height: 1.55;
}

.export-feedback {
  padding: 10px 12px;
  margin: -8px 0 0;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
  border-radius: 11px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 11px;
  line-height: 1.55;
}

.export-feedback.error {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--border));
  color: var(--danger);
  background: var(--danger-soft);
}

.export-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px;
}

#confirmExportButton.loading .icon {
  animation: identity-pulse 900ms ease-in-out infinite;
}

@keyframes identity-pulse {
  0%, 100% { opacity: .45; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1); }
}

.confirm-modal .confirm-shell {
  width: min(440px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modal-in 220ms cubic-bezier(.2, .8, .2, 1) both;
}

.danger-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  margin: 0 auto 15px;
  border-radius: 16px;
  color: var(--danger);
  background: var(--danger-soft);
}

.confirm-shell h2 {
  font-size: 20px;
}

.confirm-shell > p {
  margin: 10px 0 22px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.65;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast-region {
  position: fixed;
  z-index: 3000;
  top: 84px;
  right: 18px;
  display: grid;
  width: min(380px, calc(100vw - 36px));
  gap: 9px;
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 8px 8px 8px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in 240ms cubic-bezier(.2, .8, .2, 1) both;
}

.toast .icon {
  width: 20px;
  height: 20px;
  color: var(--success);
}

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

.toast p {
  margin: 0;
  font-size: 12px;
}

.toast button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 9px;
  color: var(--text-faint);
  background: transparent;
}

.toast button:hover {
  background: var(--surface-3);
}

.toast button .icon {
  width: 16px;
  height: 16px;
  color: currentColor;
}

@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes message-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes modal-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 1180px) {
  :root {
    --mobile-tabs-height: 58px;
  }

  .topbar {
    grid-template-columns: 1fr minmax(220px, 380px) 1fr;
  }

  .identity-pill small {
    display: none;
  }

  .identity-pill strong {
    margin-top: 0;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    height: var(--mobile-tabs-height);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .mobile-tabs button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 48px;
    color: var(--text-faint);
    background: transparent;
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-tabs button::after {
    position: absolute;
    right: 30%;
    bottom: 0;
    left: 30%;
    height: 3px;
    content: "";
    border-radius: 3px 3px 0 0;
    background: transparent;
  }

  .mobile-tabs button[aria-pressed="true"] {
    color: var(--primary);
  }

  .mobile-tabs button[aria-pressed="true"]::after {
    background: var(--primary);
  }

  .workspace {
    display: block;
    background: var(--surface);
  }

  .panel {
    display: none;
    height: 100%;
  }

  body[data-view="story"] .story-panel,
  body[data-view="chat"] .chat-panel,
  body[data-view="insight"] .insight-panel {
    display: grid;
  }

  body[data-view="story"] .story-panel,
  body[data-view="insight"] .insight-panel {
    grid-template-columns: minmax(0, 760px);
    justify-content: center;
  }

  .story-panel .panel-scroll,
  .insight-panel .panel-scroll {
    width: 100%;
  }

  .character-card .cover-frame {
    max-height: 300px;
  }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: 62px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    padding: 0 12px;
  }

  .brand-copy,
  .connection-pill,
  #openMapButton {
    display: none;
  }

  .identity-pill {
    width: 44px;
    height: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 0;
  }

  .identity-pill > span {
    display: none;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .story-switcher {
    min-width: 0;
    min-height: 44px;
    padding: 5px 9px 5px 12px;
  }

  .story-switcher-copy strong {
    max-width: none;
  }

  .topbar-actions {
    min-width: 98px;
  }

  .mobile-tabs {
    height: 54px;
  }

  :root {
    --mobile-tabs-height: 54px;
  }

  .mobile-tabs .icon {
    width: 19px;
    height: 19px;
  }

  .story-panel .panel-scroll,
  .insight-panel .panel-scroll {
    padding: 16px;
  }

  .chat-header {
    min-height: 60px;
    padding: 8px 12px;
  }

  .avatar {
    width: 40px;
    height: 40px;
  }

  .message-list {
    padding: 18px 12px 8px;
  }

  .message-row {
    max-width: 93%;
  }

  .typing-row {
    padding: 4px 12px 18px;
  }

  .typing-row p {
    display: none;
  }

  .composer-wrap {
    padding: 8px 8px max(9px, env(safe-area-inset-bottom));
  }

  .composer {
    padding-left: 12px;
  }

  .composer-meta span:last-child {
    display: none;
  }

  .send-button {
    min-width: 48px;
    width: 48px;
    padding: 0;
  }

  .send-button span {
    display: none;
  }

  .empty-chat {
    padding: 24px;
  }

  .empty-orbit {
    width: 94px;
    height: 94px;
  }

  .empty-chat h2 {
    font-size: 24px;
  }

  .modal-shell,
  .map-modal .modal-shell {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .modal-header {
    padding: 18px 16px 15px;
  }

  .modal-header h2 {
    font-size: 21px;
  }

  .modal-header p:last-child {
    display: none;
  }

  .export-form {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .map-header-actions {
    gap: 7px;
  }

  .map-customization-status {
    display: none;
  }

  .map-edit-button {
    width: 44px;
    padding: 0;
  }

  .map-progress-button {
    width: 44px;
    padding: 0;
  }

  .map-edit-button span,
  .map-progress-button span {
    display: none;
  }

  .modal-scroll {
    padding: 18px 16px max(30px, env(safe-area-inset-bottom));
  }

  .creation-grid,
  .field-row {
    grid-template-columns: 1fr;
  }

  .creation-card.featured {
    grid-column: auto;
  }

  .job-section {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .job-metrics {
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .job-section .linear-progress,
  .job-actions {
    grid-column: 1;
  }

  .map-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .commit-flow {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    justify-self: center;
    transform: rotate(90deg);
  }

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

  .score-rule-grid article:last-child {
    grid-column: 1 / -1;
  }

  .map-route,
  .map-detail-card,
  .map-simulator {
    border-radius: 14px;
  }

  .full-stage-map li {
    width: min(78vw, 270px);
    flex-basis: min(78vw, 270px);
  }

  .map-detail-grid,
  .map-prompt-change {
    grid-template-columns: 1fr;
  }

  .map-change-arrow {
    justify-self: center;
    transform: rotate(90deg);
  }

  .map-simulator-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map-section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .map-section-heading > p {
    text-align: left;
  }

  .progress-control-scroll {
    gap: 13px;
    padding: 14px 14px 22px;
  }

  .progress-control-current,
  .progress-control-editor {
    padding: 14px;
    border-radius: 15px;
  }

  .progress-control-section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .progress-control-section-heading > p {
    text-align: left;
  }

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

  .progress-control-fields {
    grid-template-columns: 1fr;
  }

  #progressEventOptions {
    grid-template-columns: 1fr;
  }

  .progress-event-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-event-pagination button {
    width: 100%;
  }

  .progress-control-actions {
    display: grid;
    min-height: 0;
    gap: 8px;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  }

  .progress-control-actions > div:last-child {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .progress-control-actions button {
    width: 100%;
    padding-inline: 10px;
  }

  .relationship-editor-scroll {
    gap: 13px;
    padding: 14px 14px 22px;
  }

  .relationship-style-section,
  .relationship-stage-section {
    padding: 14px;
    border-radius: 15px;
  }

  .relationship-editor-section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .relationship-editor-section-heading > p {
    text-align: left;
  }

  .relationship-style-options {
    grid-template-columns: 1fr;
  }

  .relationship-style-options label {
    min-height: 64px;
  }

  .relationship-stage-tabs li {
    width: min(68vw, 215px);
    flex-basis: min(68vw, 215px);
  }

  .relationship-stage-editor {
    padding: 14px;
  }

  #relationshipStageEvents {
    grid-template-columns: 1fr;
  }

  .relationship-editor-actions {
    display: grid;
    min-height: 0;
    gap: 8px;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  }

  .relationship-editor-actions > div:last-child {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .relationship-editor-actions button {
    width: 100%;
    padding-inline: 10px;
  }

  .relationship-event-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .relationship-event-pagination button {
    width: 100%;
  }

  .identity-shell {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
  }

  .toast-region {
    top: 70px;
    right: 10px;
    width: calc(100vw - 20px);
  }
}

@media (max-width: 390px) {
  .quick-prompts button {
    min-height: 32px;
    padding-inline: 10px;
  }

  .composer-meta {
    display: none;
  }

  .composer {
    grid-template-rows: auto;
    padding-bottom: 9px;
  }

  .send-button {
    grid-row: 1;
  }

  .stats-grid article {
    padding-inline: 4px;
  }

  .map-simulator-fields,
  .score-rule-grid {
    grid-template-columns: 1fr;
  }

  .relationship-readonly-grid,
  .relationship-stage-fields {
    grid-template-columns: 1fr;
  }

  .relationship-stage-fields .wide {
    grid-column: auto;
  }

  .relationship-stage-editor-header {
    align-items: flex-start;
  }

  .progress-current-grid {
    grid-template-columns: 1fr;
  }

  .score-rule-grid article:last-child {
    grid-column: auto;
  }

  .identity-content {
    grid-template-columns: 1fr;
    padding-inline: 18px;
  }

  .identity-content ul {
    grid-column: auto;
  }

  .export-format-options,
  .export-actions {
    grid-template-columns: 1fr;
  }

  .export-format-card {
    min-height: 0;
  }
}

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