/* ── Reset & Tokens ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette: Washi paper + ink stone */
  --ink:        #1a1a2e;
  --ink-soft:   #2d2d44;
  --ink-muted:  #6b7280;
  --paper:      #f8f6f1;
  --paper-warm: #f0ece3;
  --paper-line: #e5e0d5;
  --accent:     #c0392b;       /* Cinnabar — son môi thư họa */
  --accent-soft:#e8d5d0;
  --gold:       #b5882a;
  --gold-soft:  #f0e4c0;
  --teal:       #2d6a6a;
  --teal-soft:  #d0e8e8;

  /* Typography */
  --font-ui:    'Be Vietnam Pro', sans-serif;
  --font-serif: 'Noto Serif', serif;

  /* Layout */
  --sidebar-w:  220px;
  --detail-w:   320px;
  --toolbar-h:  52px;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 2px 12px rgba(26,26,46,.08);
  --shadow-md:  0 4px 24px rgba(26,26,46,.13);
}

html, body { height: 100%; font-family: var(--font-ui); background: var(--paper); color: var(--ink); }

/* ── Screens ──────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; height: 100vh; }

/* ── STARTUP ──────────────────────────────────────────── */
#screen-startup {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  position: relative;
  overflow: hidden;
}

.startup-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(192,57,43,.07) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 10% 80%, rgba(45,106,106,.06) 0%, transparent 60%);
  pointer-events: none;
}

/* Signature element: vertical brushstroke rule on the left */
#screen-startup::before {
  content: '';
  position: absolute;
  left: 10%;
  top: 15%;
  width: 2px;
  height: 70%;
  background: linear-gradient(to bottom, transparent, var(--accent), transparent);
  opacity: .25;
}

.startup-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  width: 100%;
  max-width: 520px;
  padding: 32px 24px;
}

.startup-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-stone { font-size: 48px; line-height: 1; }

.logo-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
}

.logo-sub {
  font-size: .8rem;
  color: var(--ink-muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-top: 2px;
}

.startup-card {
  background: #fff;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.startup-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
}

.startup-desc {
  font-size: .875rem;
  color: var(--ink-muted);
  margin-top: -10px;
  line-height: 1.6;
}

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--ink); letter-spacing: .03em; }
.label-hint { font-weight: 400; color: var(--ink-muted); }

input[type="text"] {
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: .9rem;
  color: var(--ink);
  background: var(--paper);
  transition: border-color .15s;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); background: #fff; }

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

.chip {
  border: 1.5px solid var(--paper-line);
  background: #fff;
  border-radius: 100px;
  padding: 6px 14px;
  font-size: .8rem;
  font-family: var(--font-ui);
  color: var(--ink-muted);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.chip-loading { font-size: .8rem; color: var(--ink-muted); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: var(--font-ui);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 4px;
}
.btn-primary:hover { opacity: .88; }

.startup-divider {
  text-align: center;
  font-size: .8rem;
  color: var(--ink-muted);
  position: relative;
}
.startup-divider::before, .startup-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--paper-line);
}
.startup-divider::before { left: 0; }
.startup-divider::after { right: 0; }

.recent-label { font-size: .75rem; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .08em; }

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
  border: 1px solid var(--paper-line);
  margin-top: 8px;
}
.recent-item:hover { background: var(--paper-warm); }
.recent-item-title { font-size: .875rem; font-weight: 500; }
.recent-item-meta { font-size: .75rem; color: var(--ink-muted); }

/* ── WORKSPACE ────────────────────────────────────────── */
#screen-workspace {
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo { font-size: 22px; }
.sidebar-project-name {
  font-size: .8rem;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.55);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: .85rem;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 16px; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-ghost {
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.45);
  font-family: var(--font-ui);
  font-size: .78rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: all .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.8); }

/* Main workspace */
.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}

.workspace-toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--paper-line);
  flex-shrink: 0;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }

.toolbar-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.toolbar-genre-badge {
  background: var(--gold-soft);
  color: var(--gold);
  border-radius: 100px;
  padding: 3px 10px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
}

.toolbar-right { display: flex; gap: 8px; }

.btn-sm {
  border: 1.5px solid var(--paper-line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Graph */
.graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#relationship-graph {
  width: 100%;
  height: 100%;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}
.empty-icon { font-size: 48px; opacity: .4; }
.graph-empty p { font-size: .9rem; color: var(--ink-muted); text-align: center; line-height: 1.7; }

/* Detail panel */
.detail-panel {
  width: var(--detail-w);
  background: #fff;
  border-left: 1px solid var(--paper-line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transform: translateX(100%);
  transition: transform .25s ease;
}
.detail-panel.open { transform: translateX(0); }

.detail-header {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--paper-line);
  font-weight: 600;
  font-size: .9rem;
  flex-shrink: 0;
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.detail-placeholder { font-size: .875rem; color: var(--ink-muted); }

.btn-icon {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all .12s;
}
.btn-icon:hover { background: var(--paper-warm); color: var(--ink); }

/* Detail content */
.detail-char-name {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.detail-char-role {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  border-radius: 100px;
  padding: 3px 10px;
  margin-bottom: 16px;
}
.role-main    { background: var(--gold-soft); color: var(--gold); }
.role-villain { background: #fde8e8; color: #c0392b; }
.role-sub     { background: var(--teal-soft); color: var(--teal); }

.detail-section { margin-bottom: 18px; }
.detail-section-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 8px;
}

.skill-badge {
  display: inline-block;
  background: var(--paper-warm);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: .8rem;
  font-weight: 500;
  margin: 3px;
  color: var(--ink);
}
.skill-badge.tier-4, .skill-badge.tier-5 {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

.relation-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--paper-line);
  font-size: .85rem;
}
.relation-type {
  font-size: .72rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.detail-btn {
  width: 100%;
  padding: 9px;
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-family: var(--font-ui);
  font-size: .82rem;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s;
  margin-top: 6px;
  text-align: center;
}
.detail-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── MODAL ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,46,.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--paper-line);
  font-weight: 600;
  font-size: .95rem;
  position: sticky;
  top: 0;
  background: #fff;
}

.modal-body { padding: 24px; }

.modal-body .form-group { margin-bottom: 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--paper-line);
}

/* Select */
select {
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: .9rem;
  color: var(--ink);
  background: var(--paper);
  width: 100%;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
select:focus { border-color: var(--accent); background: #fff; }

textarea {
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: .875rem;
  color: var(--ink);
  background: var(--paper);
  width: 100%;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); background: #fff; }

/* Graph node styles */
.node-circle {
  cursor: pointer;
  transition: r .15s;
}
.node-label {
  font-family: var(--font-ui);
  font-size: 12px;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
}
.link-line {
  stroke: var(--paper-line);
  stroke-width: 2;
}
.link-line.enemy   { stroke: #e74c3c; }
.link-line.ally    { stroke: var(--teal); }
.link-line.love    { stroke: #e91e8c; }
.link-line.master  { stroke: var(--gold); }
.link-line.rival   { stroke: #9b59b6; }
.link-line.mystery { stroke: var(--ink-muted); stroke-dasharray: 5,3; }

/* Generated name display */
.generated-names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.gen-name-chip {
  background: var(--paper-warm);
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-serif);
  font-size: .95rem;
  cursor: pointer;
  transition: all .15s;
  color: var(--ink);
}
.gen-name-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.gen-name-chip.selected { border-color: var(--accent); background: var(--accent); color: #fff; }

/* Template viewer */
.template-card {
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--paper-warm);
  cursor: pointer;
  transition: all .15s;
}
.template-card:hover { border-color: var(--accent); }
.template-card-label { font-size: .75rem; font-weight: 700; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.template-card-text { font-family: var(--font-serif); font-size: .875rem; line-height: 1.8; color: var(--ink); white-space: pre-wrap; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--paper-line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }
