* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: dark;
  --bg: oklch(17% 0.018 276);
  --bg-gradient: linear-gradient(135deg, oklch(17% 0.018 276), oklch(20% 0.022 282) 56%, oklch(17% 0.016 270));
  --surface-1: oklch(20% 0.018 276);
  --surface-2: oklch(24% 0.02 276);
  --surface-3: oklch(28% 0.022 276);
  --field: oklch(16% 0.014 276);
  --field-focus: oklch(18% 0.016 276);
  --line: oklch(34% 0.024 276);
  --line-strong: oklch(44% 0.034 276);
  --text: oklch(92% 0.011 276);
  --text-muted: oklch(70% 0.014 276);
  --text-soft: oklch(55% 0.014 276);
  --accent: oklch(72% 0.17 18);
  --accent-hover: oklch(66% 0.18 18);
  --accent-contrast: oklch(98% 0.01 18);
  --accent-soft: oklch(31% 0.065 18);
  --blue: oklch(73% 0.095 222);
  --blue-soft: oklch(27% 0.04 222);
  --blue-text: oklch(88% 0.034 222);
  --violet: oklch(75% 0.095 292);
  --violet-soft: oklch(27% 0.042 292);
  --violet-text: oklch(88% 0.036 292);
  --green: oklch(73% 0.13 151);
  --amber: oklch(78% 0.13 78);
  --danger: oklch(68% 0.16 18);
  --nav-bg: oklch(19% 0.018 276 / 0.96);
  --sidebar-bg: oklch(19% 0.018 276 / 0.92);
  --panel-bg: oklch(20% 0.018 276 / 0.9);
  --panel-solid: oklch(17% 0.016 276);
  --header-bg: oklch(20% 0.018 276 / 0.92);
  --composer-bg: oklch(20% 0.018 276 / 0.96);
  --chat-bg: oklch(18% 0.015 276);
  --character-bubble-bg: oklch(24% 0.018 252);
  --character-bubble-border: oklch(39% 0.04 252);
  --character-bubble-text: oklch(88% 0.018 252);
  --narrator-bubble-bg: oklch(20% 0.014 276);
  --narrator-bubble-border: oklch(42% 0.02 276);
  --narrator-bubble-text: oklch(73% 0.012 276);
  --image-preview-bg: linear-gradient(135deg, var(--surface-2), var(--field));
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-panel: 0 18px 60px oklch(10% 0.012 276 / 0.34);
  --shadow-bubble: 0 10px 32px oklch(12% 0.014 276 / 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(96% 0.012 86);
  --bg-gradient: linear-gradient(135deg, oklch(98% 0.01 86), oklch(95% 0.014 118) 58%, oklch(96% 0.012 58));
  --surface-1: oklch(99% 0.006 86);
  --surface-2: oklch(94% 0.011 86);
  --surface-3: oklch(89% 0.014 86);
  --field: oklch(99% 0.005 86);
  --field-focus: oklch(100% 0.004 86);
  --line: oklch(82% 0.018 86);
  --line-strong: oklch(72% 0.026 86);
  --text: oklch(25% 0.026 110);
  --text-muted: oklch(46% 0.026 110);
  --text-soft: oklch(61% 0.025 100);
  --accent: oklch(62% 0.17 18);
  --accent-hover: oklch(56% 0.18 18);
  --accent-contrast: oklch(99% 0.008 18);
  --accent-soft: oklch(94% 0.04 18);
  --blue: oklch(50% 0.095 222);
  --blue-soft: oklch(94% 0.03 222);
  --blue-text: oklch(34% 0.074 222);
  --violet: oklch(51% 0.095 292);
  --violet-soft: oklch(94% 0.03 292);
  --violet-text: oklch(34% 0.074 292);
  --green: oklch(58% 0.13 151);
  --amber: oklch(64% 0.13 78);
  --danger: oklch(56% 0.16 18);
  --nav-bg: oklch(99% 0.006 86 / 0.96);
  --sidebar-bg: oklch(97% 0.009 86 / 0.96);
  --panel-bg: oklch(99% 0.006 86 / 0.94);
  --panel-solid: oklch(96% 0.011 86);
  --header-bg: oklch(99% 0.006 86 / 0.94);
  --composer-bg: oklch(99% 0.006 86 / 0.96);
  --chat-bg: oklch(97% 0.006 86);
  --character-bubble-bg: oklch(99% 0.006 86);
  --character-bubble-border: oklch(76% 0.018 100);
  --character-bubble-text: oklch(29% 0.024 110);
  --narrator-bubble-bg: oklch(95% 0.008 86);
  --narrator-bubble-border: oklch(78% 0.018 86);
  --narrator-bubble-text: oklch(48% 0.022 100);
  --image-preview-bg: linear-gradient(135deg, oklch(95% 0.014 86), oklch(99% 0.005 86));
  --shadow-panel: 0 16px 42px oklch(48% 0.025 86 / 0.14);
  --shadow-bubble: 0 8px 24px oklch(48% 0.025 86 / 0.12);
}

body {
  min-height: 100vh;
  height: 100vh;
  background: var(--bg-gradient);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Apple SD Gothic Neo",
    "Noto Sans KR",
    system-ui,
    sans-serif;
  letter-spacing: 0;
}

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

button {
  letter-spacing: 0;
}

.app-nav {
  min-height: 58px;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 30px;
  padding: 9px 22px;
  backdrop-filter: blur(12px);
  z-index: 20;
}

.app-nav-main {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: max-content;
}

.app-nav-brand {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.app-nav-product {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.app-nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
  list-style: none;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav-links::-webkit-scrollbar {
  display: none;
}

.app-nav-link {
  position: relative;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 750;
  display: block;
  white-space: nowrap;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app-nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.app-nav-link.active {
  color: var(--text);
  background: var(--accent-soft);
  font-weight: 830;
}

.app-nav-link.active:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.app-nav-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.theme-toggle {
  position: relative;
  width: 112px;
  height: 34px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 3px;
  overflow: hidden;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-toggle:hover {
  background: var(--surface-1);
  border-color: var(--line-strong);
  color: var(--text);
}

.theme-toggle-option {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  height: 28px;
  border-radius: 999px;
  transition: color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-toggle-thumb {
  position: absolute;
  z-index: 1;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: 28px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: 0 1px 5px oklch(10% 0.01 276 / 0.2);
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-toggle[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(100%);
}

.theme-toggle[data-theme="dark"] [data-theme-label="dark"],
.theme-toggle[data-theme="light"] [data-theme-label="light"] {
  color: var(--text);
}

.app-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
}

#sidebar {
  min-width: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line);
}

#sidebar-header h2 {
  color: var(--text);
  font-size: 18px;
  font-weight: 780;
  line-height: 1.25;
  margin-bottom: 14px;
}

#user-id-row {
  display: grid;
  gap: 7px;
}

#user-id-row label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 720;
}

#user-id-input,
#user-input {
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--text);
  outline: none;
  transition:
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    background 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

#user-id-input {
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 13px;
}

#user-id-input:focus,
#user-input:focus {
  border-color: var(--accent);
  background: var(--field-focus);
}

#character-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

#character-list::-webkit-scrollbar,
#messages::-webkit-scrollbar {
  width: 8px;
}

#character-list::-webkit-scrollbar-track,
#messages::-webkit-scrollbar-track {
  background: transparent;
}

#character-list::-webkit-scrollbar-thumb,
#messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.char-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 5px;
  border: 1px solid transparent;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.char-card:hover {
  background: var(--surface-2);
}

.char-card.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.char-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  object-fit: cover;
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--line);
}

.char-info {
  min-width: 0;
}

.char-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
}

.char-intro {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

#main {
  min-width: 0;
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 14px 22px;
}

#header-avatar {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  object-fit: cover;
  background: var(--surface-3);
  display: none;
}

#header-info {
  flex: 1;
}

#header-name {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

#header-status {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--text-soft);
  display: inline-block;
}

.dot.connected {
  background: var(--green);
}

.dot.connecting {
  background: var(--amber);
}

#empty-hint {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-soft);
  gap: 6px;
}

#empty-hint .big {
  display: none;
}

#empty-hint p {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 680;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px min(5vw, 58px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(70ch, 72%);
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.character,
.msg.narrator {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.narrator {
  max-width: min(78ch, 76%);
}

.msg-label {
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 760;
  margin-bottom: 5px;
}

.msg-bubble {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px 15px;
  line-height: 1.68;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-bubble);
}

.msg.user .msg-bubble {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  border-bottom-right-radius: 6px;
}

.msg.character .msg-bubble {
  background: var(--character-bubble-bg);
  color: var(--character-bubble-text);
  border-color: var(--character-bubble-border);
  border-bottom-left-radius: 6px;
}

.msg.narrator .msg-bubble {
  background: var(--narrator-bubble-bg);
  border-color: var(--narrator-bubble-border);
  border-style: dashed;
  color: var(--narrator-bubble-text);
  border-radius: var(--radius-md);
  box-shadow: none;
  font-size: 13px;
  line-height: 1.62;
}

.msg.narrator .msg-label {
  color: var(--narrator-bubble-text);
}

.streaming-cursor::after {
  content: '▋';
  animation: blink 0.7s infinite;
  font-size: 12px;
  color: var(--text-muted);
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

#input-area {
  background: var(--composer-bg);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 22px;
}

#user-input {
  flex: 1;
  border-radius: var(--radius-lg);
  padding: 12px 15px;
  font-size: 14px;
  resize: none;
  max-height: 130px;
  line-height: 1.5;
}

#user-input::placeholder {
  color: var(--text-soft);
}

#send-btn {
  width: 46px;
  height: 46px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: var(--accent-contrast);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 800;
  flex-shrink: 0;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

#send-btn:disabled {
  background: var(--surface-3);
  color: var(--text-soft);
  cursor: not-allowed;
}

@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
  }

  .app-nav {
    height: auto;
    min-height: 60px;
    align-items: flex-start;
    grid-template-columns: 1fr auto;
    padding: 12px;
  }

  .app-nav-main {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .app-nav-links {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    overflow-x: auto;
  }

  .app-nav-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .app-nav-link {
    text-align: center;
  }

  .app-shell {
    min-height: calc(100vh - 108px);
    grid-template-columns: 1fr;
  }

  #sidebar {
    max-height: 270px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  #main {
    min-height: 430px;
  }

  #messages {
    min-height: 230px;
    padding: 22px 14px;
  }

  .msg {
    max-width: 92%;
  }
}

.docs-page {
  height: auto;
  min-height: 100vh;
  overflow-y: auto;
}

.docs-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 46px 0 64px;
}

.docs-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(280px, 0.55fr);
  gap: 44px;
  align-items: end;
  padding: 18px 0 34px;
  border-bottom: 1px solid var(--line);
}

.docs-kicker,
.docs-label {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.docs-hero h1 {
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(36px, 6vw, 72px);
  line-height: 1.02;
  letter-spacing: 0;
}

.docs-hero p {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.7;
}

.docs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 24px;
}

.docs-panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 22px;
  box-shadow: var(--shadow-panel);
}

.docs-panel-priority {
  background: linear-gradient(135deg, var(--panel-bg), var(--surface-1));
}

.docs-panel-header {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
}

.docs-panel-header strong,
.docs-section-title h2 {
  color: var(--text);
  font-size: 22px;
  line-height: 1.25;
}

.docs-checklist {
  display: grid;
  gap: 14px;
  list-style: none;
}

.docs-checklist li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.docs-check {
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--accent-soft);
}

.docs-checklist strong,
.docs-timeline strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
}

.docs-checklist p,
.docs-timeline p {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.docs-roadmap {
  margin-top: 34px;
}

.docs-section-title {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.docs-timeline {
  display: grid;
  gap: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.docs-timeline li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.docs-timeline li > span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 840px) {
  .docs-hero,
  .docs-grid {
    grid-template-columns: 1fr;
  }

  .docs-hero {
    gap: 18px;
  }
}

@media (max-width: 520px) {
  .docs-shell {
    width: min(100% - 24px, 1120px);
    padding-top: 28px;
  }

  .docs-panel {
    padding: 18px;
  }
}
