/* ===========================================================
   Sedna — stylesheet
   Aesthetic: black thangka + ancient porcelain
   Black ground. Deep iridescent blue. Antique gold. Coral.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;1,400&family=Manrope:wght@300;400;500;600;700&display=swap');

/* ----- design tokens ----- */
:root {
  /* ground */
  --ink:            #06070a;            /* near-black, very slightly cool */
  --ink-deep:       #02030580;          /* deeper black for wells */
  --ink-raise:      #0d0f15;            /* raised surfaces */
  --ink-edge:       #161922;            /* borders, dividers */

  /* iridescent blue (lapis under candlelight) */
  --lapis:          #1a3470;            /* base */
  --lapis-deep:     #0e1d44;
  --lapis-bright:   #4566c4;
  --lapis-violet:   #2a2270;            /* the violet shift */
  --lapis-glow:     #5a7adfcc;          /* with alpha for glow */

  /* antique gold (gilt, not bright) */
  --gold:           #c9a961;
  --gold-deep:      #8a6f3a;
  --gold-pale:      #e9d49a;
  --gold-leaf:      #b08d40;            /* the matte leaf tone */

  /* coral (cinnabar seal — used sparingly) */
  --coral:          #d96c5b;
  --coral-deep:     #a84939;
  --coral-glow:     #e89384;

  /* type colors */
  --text:           #e8e3d6;            /* warm parchment-ish for body */
  --text-soft:      #b6ad97;            /* secondary */
  --text-faint:     #6f6953;            /* tertiary, captions */
  --text-on-gold:   #1a1408;

  /* iridescent surface gradients */
  --iri-surface:    linear-gradient(135deg,
                      #0e1d44 0%,
                      #1a3470 35%,
                      #2a2270 65%,
                      #14224d 100%);
  --iri-edge:       linear-gradient(90deg,
                      transparent 0%,
                      var(--gold-leaf) 50%,
                      transparent 100%);

  /* type */
  --display:        'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --body:           'Manrope', 'Helvetica Neue', system-ui, sans-serif;

  /* rhythm */
  --pad-1: 0.4rem;
  --pad-2: 0.75rem;
  --pad-3: 1.1rem;
  --pad-4: 1.6rem;
  --pad-5: 2.4rem;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 14px;

  /* motion */
  --ease:        cubic-bezier(.22, .61, .36, 1);
  --ease-soft:   cubic-bezier(.45, .05, .35, 1);
  --t-fast:      160ms;
  --t-med:       280ms;
  --t-slow:      520ms;
}

/* ----- reset-ish ----- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

/* ----- base ----- */
html {
  background: var(--ink);
  color-scheme: dark;
}
body {
  font-family: var(--body);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(42, 34, 112, 0.18), transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(26, 52, 112, 0.12), transparent 55%),
    var(--ink);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* the porcelain texture — extremely subtle noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.8  0 0 0 0 0.7  0 0 0 0 0.5  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: screen;
}

/* ----- typographic helpers ----- */
.display {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 0.005em;
  line-height: 1.15;
}
.display-italic {
  font-family: var(--display);
  font-weight: 400;
  font-style: italic;
}
.eyebrow {
  font-family: var(--body);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}
h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 500;
  line-height: 1.2;
  margin: 0;
}
h1 { font-size: 2.4rem; letter-spacing: -0.005em; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.25rem; }

/* ----- the gold-leaf hairline (used on dividers, edges) ----- */
.gilt-line {
  height: 1px;
  background: var(--iri-edge);
  opacity: 0.6;
}

/* ----- app shell ----- */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ----- side navigation ----- */
.nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--pad-4) var(--pad-3);
  background: linear-gradient(180deg, rgba(13, 15, 21, 0.6), rgba(6, 7, 10, 0.9));
  border-right: 1px solid var(--ink-edge);
  display: flex;
  flex-direction: column;
  gap: var(--pad-3);
  overflow-y: auto;
}
.nav__brand {
  padding: var(--pad-2) var(--pad-2) var(--pad-3);
  border-bottom: 1px solid var(--ink-edge);
  margin-bottom: var(--pad-2);
}
.nav__name {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
  background: linear-gradient(110deg, var(--gold-pale) 0%, var(--gold) 35%, var(--gold-deep) 70%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.nav__tagline {
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
}
.nav__group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav__group-label {
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: var(--pad-2) var(--pad-2) var(--pad-1);
}
.nav__item {
  display: flex;
  align-items: center;
  gap: var(--pad-2);
  padding: var(--pad-2) var(--pad-2);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text-soft);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  position: relative;
}
.nav__item:hover {
  color: var(--text);
  background: rgba(26, 52, 112, 0.18);
}
.nav__item.is-active {
  color: var(--gold-pale);
  background: linear-gradient(90deg, rgba(26, 52, 112, 0.35), rgba(42, 34, 112, 0.18));
}
.nav__item.is-active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 25%;
  bottom: 25%;
  width: 2px;
  background: var(--gold);
  border-radius: 1px;
}
.nav__icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  opacity: 0.85;
}

/* ----- main content area ----- */
.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}
.pane {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: var(--pad-5) var(--pad-5) var(--pad-4);
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}
.pane.is-active {
  display: flex;
  animation: paneIn var(--t-med) var(--ease) both;
}
@keyframes paneIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.pane__header {
  margin-bottom: var(--pad-4);
}
.pane__title {
  font-family: var(--display);
  font-size: 2.4rem;
  font-weight: 400;
  letter-spacing: -0.005em;
}
.pane__intro {
  color: var(--text-soft);
  margin-top: var(--pad-1);
  max-width: 60ch;
}

/* ----- chat surface ----- */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat__scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad-2) var(--pad-1);
  display: flex;
  flex-direction: column;
  gap: var(--pad-3);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-edge) transparent;
}
.chat__scroll::-webkit-scrollbar { width: 6px; }
.chat__scroll::-webkit-scrollbar-thumb { background: var(--ink-edge); border-radius: 3px; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
  animation: msgIn var(--t-med) var(--ease) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.msg--user { align-self: flex-end; }
.msg--sedna { align-self: flex-start; }
.msg__role {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 var(--pad-2);
}
.msg--sedna .msg__role { color: var(--gold); }
.msg__bubble {
  padding: var(--pad-2) var(--pad-3);
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 0.98rem;
  position: relative;
}
.msg--user .msg__bubble {
  background: linear-gradient(135deg, rgba(26, 52, 112, 0.5), rgba(14, 29, 68, 0.7));
  border: 1px solid rgba(69, 102, 196, 0.25);
  color: var(--text);
}
.msg--sedna .msg__bubble {
  background: rgba(13, 15, 21, 0.7);
  border: 1px solid var(--ink-edge);
  border-left: 2px solid var(--gold-leaf);
  color: var(--text);
}

/* ----- composer ----- */
.composer {
  margin-top: var(--pad-3);
  display: flex;
  align-items: flex-end;
  gap: var(--pad-2);
  padding: var(--pad-2);
  background: var(--ink-raise);
  border: 1px solid var(--ink-edge);
  border-radius: var(--radius-lg);
  transition: border-color var(--t-fast) var(--ease);
}
.composer:focus-within {
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 1px rgba(201, 169, 97, 0.15);
}
.composer__input {
  flex: 1;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  padding: var(--pad-2);
  min-height: 1.5em;
  max-height: 12rem;
  font-family: var(--body);
}
.composer__input::placeholder {
  color: var(--text-faint);
  font-style: italic;
}
.composer__send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--coral), var(--coral-deep));
  color: var(--ink);
  transition: transform var(--t-fast) var(--ease), filter var(--t-fast) var(--ease);
}
.composer__send:hover { transform: translateY(-1px); filter: brightness(1.1); }
.composer__send:disabled {
  background: var(--ink-edge);
  color: var(--text-faint);
  cursor: not-allowed;
}

/* ----- buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pad-1);
  padding: var(--pad-2) var(--pad-3);
  border-radius: var(--radius);
  font-family: var(--body);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  transition: all var(--t-fast) var(--ease);
}
.btn--primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--text-on-gold);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 6px 22px rgba(176, 141, 64, 0.22);
}
.btn--primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.btn--ghost {
  border: 1px solid var(--ink-edge);
  color: var(--text-soft);
}
.btn--ghost:hover {
  border-color: var(--gold-deep);
  color: var(--text);
}
.btn--coral {
  background: linear-gradient(135deg, var(--coral), var(--coral-deep));
  color: var(--ink);
}
.btn--quiet {
  color: var(--text-soft);
  padding: var(--pad-1) var(--pad-2);
}
.btn--quiet:hover { color: var(--gold-pale); }

/* ----- inputs ----- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--pad-3);
}
.field__label {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 500;
}
.field__hint {
  font-size: 0.82rem;
  color: var(--text-faint);
  line-height: 1.5;
}
.field__input,
.field__textarea {
  background: var(--ink-raise);
  border: 1px solid var(--ink-edge);
  border-radius: var(--radius);
  padding: var(--pad-2) var(--pad-3);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.field__input:focus,
.field__textarea:focus {
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 1px rgba(201, 169, 97, 0.15);
}
.field__textarea { resize: vertical; min-height: 6rem; font-family: var(--body); }

/* ----- first-run overlay ----- */
.firstrun {
  position: fixed;
  inset: 0;
  z-index: 100;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(26, 52, 112, 0.4), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(42, 34, 112, 0.3), transparent 60%),
    rgba(2, 3, 5, 0.96);
  display: grid;
  place-items: center;
  padding: var(--pad-4);
  animation: fadeIn var(--t-slow) var(--ease) both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.firstrun__card {
  width: 100%;
  max-width: 520px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(42, 34, 112, 0.35), transparent 60%),
    linear-gradient(160deg, #11162b 0%, #0a0d1a 60%, #060710 100%);
  border: 1px solid var(--gold-deep);
  border-radius: var(--radius-lg);
  padding: var(--pad-5);
  position: relative;
  overflow: hidden;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.6),
    0 2px 0 rgba(201, 169, 97, 0.15) inset,
    0 -1px 0 rgba(26, 52, 112, 0.3) inset;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.firstrun__step {
  display: none;
}
.firstrun__step.is-active {
  display: block;
  animation: stepIn var(--t-med) var(--ease) both;
}
@keyframes stepIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.firstrun__title {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 400;
  margin-bottom: var(--pad-1);
}
.firstrun__sub {
  color: var(--text-soft);
  margin-bottom: var(--pad-4);
  line-height: 1.6;
}
.firstrun__nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--pad-4);
  gap: var(--pad-2);
}
.firstrun__progress {
  display: flex;
  gap: 6px;
}
.firstrun__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-edge);
  transition: background var(--t-fast) var(--ease);
}
.firstrun__dot.is-current { background: var(--gold); }
.firstrun__dot.is-done { background: var(--gold-deep); }

/* ----- error display ----- */
.error-toast {
  position: fixed;
  bottom: var(--pad-4);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 12, 8, 0.95);
  border: 1px solid var(--coral-deep);
  border-radius: var(--radius);
  padding: var(--pad-3);
  max-width: 480px;
  z-index: 200;
  animation: toastIn var(--t-med) var(--ease) both;
  display: none;
}
.error-toast.is-visible { display: block; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.error-toast__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--pad-1);
}
.error-toast__title {
  font-weight: 600;
  color: var(--coral-glow);
}
.error-toast__code {
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: var(--pad-1);
  user-select: all;
}

/* ----- mobile ----- */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
  }
  .nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: var(--pad-2);
    border-right: none;
    border-top: 1px solid var(--ink-edge);
    background: rgba(6, 7, 10, 0.96);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 50;
  }
  .nav__brand,
  .nav__group-label { display: none; }
  .nav__group { flex-direction: row; }
  .nav__item {
    flex-direction: column;
    gap: 2px;
    padding: 6px 8px;
    font-size: 0.7rem;
    white-space: nowrap;
    border-radius: var(--radius-sm);
  }
  .nav__item.is-active::before { display: none; }
  .nav__item.is-active {
    background: rgba(26, 52, 112, 0.4);
    color: var(--gold-pale);
  }
  .pane {
    padding: var(--pad-3) var(--pad-3) calc(var(--pad-5) + 60px);
  }
  .pane__title { font-size: 1.9rem; }
  h1 { font-size: 1.9rem; }
}
