@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;600;700&family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap");

:root {
  --bg: #f2ead3;
  --surface: #fffdf7;
  --soft: #f4e8cd;
  --border: #c6ae84;
  --border-light: #dcc8a5;

  --text: #3b2f20;
  --text-secondary: #5f4d36;
  --text-muted: #867359;
  --text-faint: #a39276;

  --accent: #9b7c4d;
  --accent-bg: rgba(194, 166, 118, 0.3);
  --accent-border: #a78a5c;

  --green: #2f6b4e;
  --green-bg: rgba(47, 107, 78, 0.16);
  --green-border: #2f6b4e;

  --amber: #9b7c4d;
  --amber-bg: rgba(194, 166, 118, 0.3);
  --grid-line: rgba(59, 47, 32, 0.08);
  --card-shadow: rgba(59, 47, 32, 0.2);

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --serif: "Fraunces", "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 30px 30px;
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:hover { opacity: 1; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(181,149,77,0.28); border-radius: 4px; }

/* ── Landing ── */
.page {
  width: 100%;
  min-height: 100vh;
  padding: 34px 24px 42px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.page-inner {
  width: 100%;
  max-width: 680px;
  text-align: center;
  background: var(--surface);
  border: 3px solid var(--accent-border);
  border-radius: 10px;
  box-shadow: 10px 10px 0 var(--card-shadow);
  padding: 22px 20px;
}

.glow { display: none; }

.icon {
  width: 58px;
  height: 58px;
  border: 2px solid var(--text);
  background: #f8efdd;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 16px;
}

.brand-logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  margin: 0 auto 16px;
}

.brand-logo-sm {
  width: 120px;
}

.brand-logo-md {
  width: 160px;
}

.brand-logo-lg {
  width: 220px;
}

.brand-logo-chip {
  width: 28px;
  margin: 0;
}

.h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  color: var(--text);
  letter-spacing: -0.025em;
  margin: 0 0 8px 0;
  line-height: 1.2;
}

.sub {
  margin: 0 auto 36px auto;
  max-width: 440px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.steps {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.card {
  flex: 1 1 180px;
  max-width: 200px;
  background: var(--surface);
  border: 2px solid var(--accent-border);
  border-radius: 8px;
  box-shadow: 5px 5px 0 var(--card-shadow);
  padding: 20px 16px;
  text-align: left;
}

.num {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.card-title {
  margin: 0 0 6px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-desc {
  margin: 0 0 14px 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

.foot {
  margin-top: 40px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid var(--text);
  background: #f7ecd5;
  color: var(--text-secondary);
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

.btn:hover {
  background: #efe2c4;
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f2e6ca;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-primary {
  background: var(--accent-bg);
  color: var(--text);
  border-color: var(--accent-border);
}

.btn-amber {
  background: var(--accent-bg);
  color: var(--text);
  border-color: var(--accent-border);
}

.btn-green {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green-border);
}

.btn-violet {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent-border);
}

.btn-done {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green-border);
}

.back { margin-top: 16px; }

/* ── Naming ── */
.naming { max-width: 480px; }

.naming-input {
  width: 100%;
  border-radius: 4px;
  padding: 16px 18px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.01em;
}

.naming-input::placeholder {
  color: var(--text-faint);
  font-weight: 400;
}

.naming-input:focus {
  outline: none;
  border-color: var(--accent);
  outline: 2px solid rgba(232, 194, 109, 0.28);
  outline-offset: 1px;
}

/* ── Signup ── */
.signup { max-width: 400px; }

.auth-form {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.step-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: #fffef9;
}

.step-title {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.step-help {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.email {
  width: 100%;
  border-radius: 4px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  text-align: center;
}

.auth-form .email {
  text-align: left;
}

.auth-form .email[readonly] {
  background: #f5ebd5;
  color: var(--text-muted);
  cursor: default;
}

.email:focus {
  outline: none;
  border-color: var(--accent);
  outline: 2px solid rgba(232, 194, 109, 0.28);
  outline-offset: 1px;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(165, 38, 26, 0.25);
  border-radius: 4px;
  background: rgba(165, 38, 26, 0.08);
  color: #a5261a;
  font-size: 13px;
  line-height: 1.4;
}

/* ── MCP Connected ── */
.mcp-box {
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--accent-border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 6px 6px 0 var(--card-shadow);
}

.mcp-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 4px 0;
}

.mcp-code {
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--soft);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
  line-height: 1.5;
}

.guide {
  margin-top: 18px;
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--accent-border);
  border-radius: 8px;
  box-shadow: 6px 6px 0 var(--card-shadow);
  padding: 14px;
}

.guide-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 10px 0;
}

.guide-row {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.guide-row > .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.guide-row > .text {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Demo layout ── */
.demo {
  width: min(1140px, calc(100% - 44px));
  height: calc(100vh - 48px);
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 3px solid var(--accent-border);
  border-radius: 10px;
  box-shadow: 10px 10px 0 var(--card-shadow);
  overflow: hidden;
}

.demo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.demo-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.demo-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 2px 7px;
  border-radius: 4px;
}

.api-pill {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--soft);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
}

.api-pill.ok {
  color: var(--green);
  background: var(--green-bg);
  border-color: var(--green-border);
}

.api-pill.bad {
  color: #a5261a;
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.15);
}

.hbtn {
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border: 2px solid var(--text);
  background: #f7ecd5;
  color: var(--text-secondary);
}

.demo-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

/* ── Chat ── */
.chat {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  border-radius: 18px 18px 4px 18px;
  background: rgba(236, 202, 129, 0.42);
  color: var(--text);
  border: 1px solid rgba(182, 123, 18, 0.22);
}

.bubble.assistant {
  align-self: flex-start;
  border-radius: 18px 18px 18px 4px;
  background: #fffdf8;
  color: var(--text);
  border: 1px solid var(--border-light);
}

.chat-inputbar {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 10px;
  background: var(--surface);
}

.chat-input {
  flex: 1;
  border-radius: 4px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  outline: 2px solid rgba(232, 194, 109, 0.28);
  outline-offset: 1px;
}

.send {
  width: 44px;
  height: 44px;
  border-radius: 4px;
  background: rgba(236, 202, 129, 0.52);
  border: 2px solid var(--accent-border);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

/* ── Memory panel ── */
.mem {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.mem-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mem-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.keep {
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: 8px;
  padding: 5px 10px;
}

.mem-list {
  padding: 12px;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.piece {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 12px;
  background: var(--surface);
}

@keyframes memFlash {
  from {
    border-color: var(--accent-border);
    background: var(--accent-bg);
  }
  to {
    border-color: var(--border);
    background: var(--surface);
  }
}

.piece.flash {
  animation: memFlash 600ms ease-out both;
}

.piece-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.piece-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.emo-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.emo {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: lowercase;
  flex: 0 0 auto;
}

.topic {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--soft);
  border: 1px solid var(--border-light);
  padding: 1px 6px;
  border-radius: 999px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.time {
  font-size: 11px;
  color: var(--text-faint);
}

.what {
  margin: 0 0 4px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thus {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.mem-bot {
  padding: 14px;
  border-top: 1px solid var(--border-light);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.mono { font-family: var(--mono); }

/* ── Source badge ── */
.source-badge {
  font-size: 9px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
}

/* ── Dream section ── */
.dream-section {
  padding: 12px 14px;
  border-top: 1px solid var(--border-light);
}

.dream-btn {
  width: 100%;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid var(--accent-border);
  background: var(--accent-bg);
  color: var(--accent);
  cursor: pointer;
  transition: opacity 0.15s;
}

.dream-btn:hover { opacity: 0.85; }
.dream-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.dream-report {
  margin-top: 10px;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid var(--accent-border);
  background: var(--accent-bg);
}

.dream-narrative {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  font-style: italic;
  margin: 0 0 8px 0;
}

.dream-meta {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Memory toast ── */
.mem-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
  animation: toastIn 180ms ease-out;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Responsive ── */
@media (max-width: 940px) {
  .page {
    padding: 16px 10px 22px;
  }
  .page-inner {
    padding: 16px 14px;
    border-width: 2px;
    box-shadow: 6px 6px 0 var(--card-shadow);
  }
  .card {
    box-shadow: 3px 3px 0 var(--card-shadow);
  }
  .mcp-box,
  .guide {
    box-shadow: 4px 4px 0 var(--card-shadow);
  }
  .demo {
    width: calc(100% - 20px);
    height: calc(100vh - 24px);
    margin: 10px auto;
    border-width: 2px;
    box-shadow: 6px 6px 0 var(--card-shadow);
  }
  .demo-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .chat { border-right: none; }
  .mem {
    border-top: 1px solid var(--border-light);
    height: 280px;
  }
  .bubble { max-width: 88%; }
}

/* ── Migrate page (#199) ── */
.migrate { max-width: 520px; }
.migrate-upload {
  width: 100%;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 14px;
}
.migrate-upload:hover { border-color: var(--accent); }
.migrate-progress {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--soft);
  overflow: hidden;
  margin: 12px 0;
}
.migrate-progress-bar {
  height: 100%;
  background: #ca9230;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.migrate-stat {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.migrate-chunk {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 8px;
}
.migrate-chunk-copied {
  border-color: var(--accent);
  opacity: 0.6;
}
