:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --panel: #161b28;
  --panel-2: #1b2132;
  --border: #262d40;
  --text: #e8ebf4;
  --text-dim: #9aa3b8;
  --accent: #7c6cff;
  --accent-2: #46d5b3;
  --accent-grad: linear-gradient(135deg, #7c6cff 0%, #46d5b3 100%);
  --danger: #ff6b7a;
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent-grad);
  color: #0b0e14;
}
.btn-primary:hover { opacity: 0.9; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-lg { padding: 15px 34px; font-size: 1.05rem; border-radius: 12px; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: wait; }

/* ---------- landing ---------- */
.nav { position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); background: rgba(11,14,20,0.8); border-bottom: 1px solid var(--border); }
.nav-inner {
  max-width: 1080px; margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em; }
.logo-accent {
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-left: 6px; font-weight: 700;
}
.logo-sm { font-size: 1.05rem; }
.nav-actions { display: flex; gap: 10px; }

.hero { max-width: 880px; margin: 0 auto; padding: 96px 24px 64px; text-align: center; }
.hero-badge {
  display: inline-block; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--accent-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 16px;
  margin-bottom: 28px; background: var(--bg-soft);
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 6.5vw, 4.4rem);
  line-height: 1.06; font-weight: 700; letter-spacing: -0.02em;
}
.hero h1 em {
  font-style: italic;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  margin: 28px auto 0; max-width: 640px;
  font-size: 1.15rem; line-height: 1.65; color: var(--text-dim);
}
.hero-sub strong { color: var(--text); }
.hero-cta { margin-top: 40px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hero-note { font-size: 0.85rem; color: var(--text-dim); }

.features {
  max-width: 1080px; margin: 0 auto; padding: 40px 24px 72px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px;
}
.feature {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px;
}
.feature-icon { font-size: 1.4rem; color: var(--accent-2); margin-bottom: 14px; }
.feature h3 { font-size: 1.1rem; margin-bottom: 10px; }
.feature p { color: var(--text-dim); line-height: 1.6; font-size: 0.95rem; }

.how { max-width: 720px; margin: 0 auto; padding: 24px 24px 80px; text-align: center; }
.how h2 { font-family: var(--font-display); font-size: 2rem; margin-bottom: 28px; }
.how-steps { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.step {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; color: var(--text-dim); font-size: 1rem; line-height: 1.5;
  display: flex; gap: 16px; align-items: center;
}
.step em { color: var(--text); }
.step-n {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-grad); color: #0b0e14; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 0.9rem;
}
.how-punch { margin-top: 26px; font-size: 1.2rem; font-weight: 600; }

.footer {
  border-top: 1px solid var(--border); padding: 32px 24px; text-align: center;
  color: var(--text-dim); font-size: 0.9rem;
}
.footer-fine { margin-top: 8px; font-size: 0.78rem; opacity: 0.7; }
.yours-link { color: var(--accent); text-decoration: none; letter-spacing: 0.12em; font-weight: 600; }
.yours-link:hover { text-decoration: underline; }

/* ---------- YOURS page ---------- */
.yours-page {
  max-width: 560px; margin: 0 auto; padding: 96px 24px; text-align: center;
}
.yours-page h1 { letter-spacing: 0.18em; margin-bottom: 8px; }
.yours-sub { color: var(--text-dim); margin-bottom: 36px; }
.yours-list { list-style: none; padding: 0; margin: 0 0 36px; }
.yours-list li {
  padding: 14px 0; border-bottom: 1px solid var(--border);
  font-size: 1.05rem; font-weight: 500;
}
.yours-list li:first-child { border-top: 1px solid var(--border); }
.yours-close { color: var(--text-dim); margin-bottom: 40px; }

/* ---------- modal ---------- */
[hidden] { display: none !important; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,7,12,0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  position: relative; width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 34px;
}
.modal h2 { font-size: 1.4rem; margin-bottom: 22px; }
.modal-close {
  position: absolute; top: 14px; right: 18px; background: none; border: none;
  color: var(--text-dim); font-size: 1.6rem; cursor: pointer;
}
.modal label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-dim); margin-bottom: 16px; }
.modal input {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 1rem; font-family: var(--font);
}
.modal input:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 0.88rem; margin-bottom: 14px; }
.modal-switch { margin-top: 18px; text-align: center; font-size: 0.9rem; color: var(--text-dim); }
.modal-switch a { color: var(--accent-2); text-decoration: none; }

/* ---------- chat ---------- */
.chatpage { height: 100vh; overflow: hidden; }
.chat-layout { display: flex; height: 100vh; }

.memory-panel {
  width: 300px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-soft); border-right: 1px solid var(--border); padding: 22px;
}
.memory-head { margin-bottom: 30px; }
.memory-title { font-family: var(--font-display); font-size: 1.25rem; line-height: 1.3; margin-bottom: 18px; }
.memory-list { list-style: none; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.memory-list li {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-size: 0.9rem; animation: factIn .35s ease;
}
.memory-list li .fact-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent-2); font-weight: 700; margin-bottom: 2px; }
.memory-empty { color: var(--text-dim); font-style: italic; border-style: dashed !important; }
@keyframes factIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.memory-foot { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.memory-hint { font-size: 0.78rem; color: var(--text-dim); line-height: 1.5; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-messages { max-width: 760px; margin: 0 auto; padding: 32px 24px 12px; display: flex; flex-direction: column; gap: 16px; }

.msg { max-width: 78%; padding: 13px 18px; border-radius: 16px; line-height: 1.55; font-size: 0.98rem; white-space: pre-wrap; animation: factIn .25s ease; }
.msg-user { align-self: flex-end; background: var(--accent); color: #0e0a2a; border-bottom-right-radius: 4px; font-weight: 500; }
.msg-ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-ai.thinking { color: var(--text-dim); font-style: italic; }
.msg-note {
  align-self: center; font-size: 0.78rem; color: var(--accent-2);
  background: rgba(70,213,179,0.08); border: 1px solid rgba(70,213,179,0.25);
  border-radius: 999px; padding: 5px 14px;
}

.suggestions { max-width: 760px; margin: 0 auto; padding: 6px 24px; display: flex; gap: 8px; flex-wrap: wrap; width: 100%; }
.chip {
  background: var(--bg-soft); color: var(--text-dim); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-size: 0.82rem; cursor: pointer; font-family: var(--font);
}
.chip:hover { color: var(--text); border-color: var(--accent); }

.composer {
  max-width: 760px; margin: 0 auto; width: 100%;
  display: flex; gap: 10px; padding: 12px 24px 6px;
}
.composer input {
  flex: 1; padding: 14px 18px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-size: 1rem; font-family: var(--font);
}
.composer input:focus { outline: none; border-color: var(--accent); }
.chat-fine { text-align: center; font-size: 0.72rem; color: var(--text-dim); opacity: 0.6; padding: 8px 24px 14px; }

/* ---------- landing templates teaser ---------- */
.templates-teaser { max-width: 880px; }
.teaser-sub { color: var(--text-dim); line-height: 1.6; margin-bottom: 26px; }
.teaser-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.teaser-pill {
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 9px 18px; font-size: 0.9rem; color: var(--text);
}

/* ---------- companions sidebar ---------- */
.companions-block { margin-bottom: 26px; }
.side-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-dim); font-weight: 700; margin-bottom: 10px;
}
.companion-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 220px; overflow-y: auto; }
.companion-item { display: flex; align-items: center; border-radius: 10px; border: 1px solid transparent; }
.companion-item.active { background: var(--panel); border-color: var(--accent); }
.companion-item:hover:not(.active) { background: var(--panel); }
.companion-btn {
  flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: none;
  padding: 8px 10px; cursor: pointer; text-align: left; color: var(--text); font-family: var(--font);
  min-width: 0;
}
.companion-icon { font-size: 1.2rem; flex-shrink: 0; }
.companion-txt { display: flex; flex-direction: column; min-width: 0; }
.companion-name { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.companion-tpl { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.companion-del {
  background: none; border: none; color: var(--text-dim); font-size: 1.1rem;
  cursor: pointer; padding: 0 10px; opacity: 0; transition: opacity .12s ease;
}
.companion-item:hover .companion-del { opacity: 1; }
.companion-del:hover { color: var(--danger); }

/* ---------- chat topbar ---------- */
.chat-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--bg-soft);
}
.topbar-icon { font-size: 1.5rem; }
.topbar-name { font-weight: 700; font-size: 1.02rem; }
.topbar-sub { font-size: 0.78rem; color: var(--text-dim); }
.topbar-disclaimer {
  margin-left: auto; font-size: 0.74rem; color: #ffce6b;
  background: rgba(255,206,107,0.08); border: 1px solid rgba(255,206,107,0.3);
  border-radius: 999px; padding: 5px 12px;
}
.topbar-disclaimer:empty, .topbar-disclaimer[hidden] { display: none; }

/* ---------- template picker ---------- */
.picker-backdrop { overflow-y: auto; align-items: flex-start; }
.modal.picker { max-width: 880px; margin: 40px auto; }
.picker-sub { color: var(--text-dim); font-size: 0.92rem; margin: -12px 0 22px; line-height: 1.5; }
.template-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px;
}
.tpl-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; cursor: pointer; text-align: left; color: var(--text); font-family: var(--font);
  transition: border-color .12s ease, transform .12s ease;
}
.tpl-card:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.tpl-card.used { opacity: 0.45; cursor: not-allowed; }
.tpl-icon { font-size: 1.5rem; }
.tpl-title { font-weight: 700; font-size: 0.98rem; }
.tpl-cat {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-2); font-weight: 700;
}
.tpl-tag { font-size: 0.82rem; color: var(--text-dim); line-height: 1.4; }
.tpl-disclaimer { font-size: 0.7rem; color: #ffce6b; line-height: 1.35; }

/* ---------- settings modal ---------- */
.settings-modal { max-width: 520px; max-height: 90vh; overflow-y: auto; }
.topbar-settings { margin-left: 12px; flex-shrink: 0; }
.topbar-disclaimer + .topbar-settings { margin-left: 12px; }
#trait-fields label, .settings-modal label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-dim); margin-bottom: 14px; }
#trait-fields select, .settings-modal input, .settings-modal textarea {
  width: 100%; margin-top: 6px; padding: 11px 13px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 0.98rem; font-family: var(--font); resize: vertical;
}
#trait-fields select:focus, .settings-modal input:focus, .settings-modal textarea:focus { outline: none; border-color: var(--accent); }
#trait-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.label-hint { font-weight: 400; opacity: 0.7; }
.word-count { font-size: 0.8rem; opacity: 0.6; text-align: right; margin: -8px 0 12px; }
.word-count.warn { color: var(--danger); opacity: 1; }

/* ---------- editable memory ---------- */
.fact-item { position: relative; padding-right: 52px !important; }
.fact-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s ease; }
.fact-item:hover .fact-actions { opacity: 1; }
.fact-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 0.95rem; padding: 2px 5px; border-radius: 6px;
}
.fact-btn:hover { color: var(--text); background: var(--panel-2); }
.fact-add { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.fact-add-row { display: flex; gap: 8px; }
.fact-add input {
  width: 100%; min-width: 0; padding: 8px 10px; font-size: 0.82rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: var(--font);
}
.fact-add input:focus { outline: none; border-color: var(--accent); }

.custom-title { font-size: 1.1rem; margin-bottom: 16px; }
#custom-form label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-dim); margin-bottom: 16px; }
#custom-form input, #custom-form textarea {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 1rem; font-family: var(--font); resize: vertical;
}
#custom-form input:focus, #custom-form textarea:focus { outline: none; border-color: var(--accent); }
.custom-actions { display: flex; justify-content: space-between; gap: 12px; }

@media (max-width: 760px) {
  .memory-panel { display: none; }
  .msg { max-width: 88%; }
  .modal.picker { margin: 12px auto; }
}

/* Facts inside AI Knowledge modal */
.know-facts { max-height: 180px; overflow-y: auto; margin-bottom: 10px; }
.know-fact-row { margin-bottom: 16px; }
.know-fact-row input { flex: 1; min-width: 0; }
