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

:root {
  --bg: #0b0b11;
  --surface: #12121c;
  --card: #181826;
  --border: #262640;
  --text: #e4e4f0;
  --text-secondary: #8585a0;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-subtle: rgba(139, 92, 246, 0.12);
  --green: #34d399;
  --radius: 8px;
  --radius-lg: 12px;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: var(--card);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ── Header ── */

.site-header {
  position: relative;
  z-index: 110;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.logo:hover {
  color: var(--text);
}

.logo-accent {
  color: var(--accent);
}

nav {
  display: flex;
  gap: 1.5rem;
}

nav a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s;
}

nav a:hover,
nav a.active {
  color: var(--text);
}

nav a.nav-live-demo {
  margin-left: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

nav a.nav-live-demo:hover {
  color: var(--accent-hover);
}

nav a.nav-live-demo.active {
  color: var(--accent);
}

/* ── Buttons ── */

.btn {
  display: inline-block;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

.btn-danger {
  background: #7f1d1d;
  color: #fecaca;
  border: 1px solid #991b1b;
}

.btn-danger:hover {
  background: #991b1b;
  color: #fff;
}

/* ── Hero ── */

.hero {
  padding: 6rem 0 4rem;
  text-align: center;
}

.hero h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 1.25rem;
}

.hero-sub {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 2rem;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.hero-skip {
  margin-top: 1rem;
  font-size: 0.9rem;
}

.hero-skip a {
  color: var(--text-secondary);
  font-weight: 500;
}

.hero-skip a:hover {
  color: var(--accent);
}

.hero-version {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Features ── */

.features {
  padding: 4rem 0;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
}

.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}

.feature-icon {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
}

.feature-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.feature-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── Code Section ── */

.code-section {
  padding: 4rem 0;
}

.code-section h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
}

.code-section pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.7;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.code-section pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.code-section .kw { color: #c084fc; }
.code-section .str { color: #34d399; }
.code-section .lit { color: #f59e0b; }

.code-caption {
  margin-top: 1.25rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* ── CTA ── */

.cta-section {
  padding: 4rem 0 5rem;
  text-align: center;
}

.cta-section h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.cta-section p {
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto 1.5rem;
  font-size: 0.95rem;
  line-height: 1.7;
}

/* ── Footer ── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: auto;
  text-align: center;
}

.site-footer p {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ── Demo Page ── */

.demo-page {
  flex: 1;
  padding: 2rem 0;
}

.demo-header {
  text-align: center;
  margin-bottom: 2rem;
}

.demo-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.demo-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.7;
}

.character-tabs {
  display: flex;
  gap: 0.5rem;
  max-width: 640px;
  margin: 0 auto 0.75rem;
  padding: 0 0.25rem;
  overflow-x: auto;
}

.char-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.char-tab:hover {
  background: var(--border);
  color: var(--text);
}

.char-tab.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.chat-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-npc-info {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.npc-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.npc-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
}

.npc-prompt-link {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.npc-prompt-link:hover {
  color: var(--text);
}

.npc-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.npc-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.chat-messages {
  flex: 1;
  min-height: 320px;
  max-height: 420px;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.system-message {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 2rem 0;
}

.message {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.npc {
  background: var(--card);
  border: 1px solid var(--border);
  align-self: flex-start;
}

.message.npc .message-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

.message.player {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
}

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input-area input:focus {
  border-color: var(--accent);
}

.chat-input-area input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-input-area button {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-input-area button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat-input-area button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.chat-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.chat-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 0 1.25rem 0.6rem;
}

.summary-notice {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 0.8rem;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
  align-self: center;
  max-width: 95%;
}

.summary-notice-title {
  font-weight: 700;
  color: #f59e0b;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-notice-body {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ── Welcome Overlay ── */

.welcome-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2rem;
}

.welcome-card,
.welcome-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 460px;
  width: 90%;
  text-align: center;
}

.welcome-card h1,
.welcome-dialog h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.welcome-card p,
.welcome-dialog p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.welcome-input-row {
  display: flex;
  gap: 0.5rem;
}

.welcome-input-row input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.welcome-input-row input:focus {
  border-color: var(--accent);
}

.welcome-status {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-height: 1.2em;
}

.welcome-disclaimer {
  margin-top: 1.25rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

.welcome-dialog-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Create-Character Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2.25rem;
  max-width: 480px;
  width: 92%;
  animation: fadeIn 0.2s ease;
}

.modal-card-wide {
  max-width: 540px;
}

.modal-system-prompt-card {
  max-width: min(640px, 96vw);
}

.system-prompt-pre {
  margin: 0;
  padding: 1rem 1.1rem;
  max-height: min(60vh, 28rem);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
}

.modal-step-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin-bottom: 0.2rem !important;
  font-weight: 600;
}

.modal-intro {
  margin-bottom: 1.25rem !important;
}

.modal-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.modal-card > p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  margin-top: 0.9rem;
}

.modal-label:first-of-type {
  margin-top: 0;
}

.modal-optional {
  font-weight: 400;
  color: var(--text-secondary);
}

.modal-input,
.modal-textarea {
  display: block;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus,
.modal-textarea:focus {
  border-color: var(--accent);
}

select.modal-input {
  cursor: pointer;
}

.modal-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
}

.modal-actions-end {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-left: auto;
}

/* `.btn { display: inline-block }` otherwise wins over the [hidden] attribute */
.modal-actions .btn[hidden] {
  display: none !important;
}

.modal-status {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: right;
  min-height: 1.2em;
}

/* add-character tab */
.char-tab-add {
  border-style: dashed;
  color: var(--text-secondary);
}

.char-tab-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.char-tab-plus {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  border: 1px dashed currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Responsive ── */

/* ── Docs page ── */

.docs-page {
  flex: 1;
  padding: 2rem 0 3rem;
}

.docs-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
  max-width: 1000px;
}

.docs-toc {
  position: sticky;
  top: 1rem;
  padding: 0.25rem 0;
}

.docs-toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.docs-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.docs-toc li {
  margin-bottom: 0.35rem;
}

.docs-toc a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.docs-toc a:hover {
  color: var(--accent);
}

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

.docs-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  line-height: 1.15;
}

.docs-lead {
  font-size: 1.05rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 2.5rem;
  max-width: 42rem;
}

.docs-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: 1.25rem;
}

.docs-section h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.docs-section p,
.docs-section li {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 42rem;
}

.docs-section p {
  margin-bottom: 0.85rem;
}

.docs-section ul,
.docs-section ol {
  margin: 0.5rem 0 1rem 1.25rem;
}

.docs-section li {
  margin-bottom: 0.45rem;
}

.docs-steps {
  counter-reset: step;
  list-style: none;
  margin-left: 0 !important;
  padding-left: 0;
}

.docs-steps li {
  position: relative;
  padding-left: 2rem;
  margin-bottom: 0.65rem;
}

.docs-steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.1rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.docs-pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.65;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  margin: 0.75rem 0 1rem;
  max-width: 100%;
}

.docs-pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: var(--text);
}

.docs-muted {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem !important;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.75rem 0 1rem;
}

.docs-table th,
.docs-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

.docs-table th {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
}

.docs-table td {
  color: var(--text-secondary);
}

.docs-table code {
  font-size: 0.85em;
}

.docs-table-ref td:first-child {
  white-space: nowrap;
  font-size: 0.8rem;
}

@media (max-width: 768px) {
  .docs-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .docs-toc {
    position: static;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    background: var(--surface);
    columns: 2;
    column-gap: 1.5rem;
  }

  .docs-toc ul {
    break-inside: avoid;
  }

  .docs-table-ref td:first-child {
    white-space: normal;
  }
}

/* ── Developer license page ── */

.license-page .docs-content {
  max-width: 44rem;
}

.license-callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.35rem;
  margin-bottom: 2rem;
}

.license-callout-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.65rem;
}

.license-callout-list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.65;
}

.license-callout-list li {
  margin-bottom: 0.4rem;
}

.license-form {
  margin-top: 1rem;
  max-width: 28rem;
}

.license-email-input {
  width: 100%;
  max-width: 100%;
  margin-bottom: 0.75rem;
}

.license-form-actions {
  margin-top: 0.5rem;
}

.license-form-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 1rem;
  line-height: 1.55;
}

.license-status {
  margin-top: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 1.5em;
}

.license-status--success {
  color: var(--green);
}

.license-status--error {
  color: #f87171;
}

.license-status--pending {
  color: var(--text-secondary);
}

@media (max-width: 600px) {
  .hero h1 {
    font-size: 2rem;
  }

  .hero-sub {
    font-size: 1rem;
  }

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

  .code-section pre {
    font-size: 0.75rem;
    padding: 1rem;
  }

  .docs-toc {
    columns: 1;
  }

  .docs-title {
    font-size: 1.6rem;
  }
}
