/* Buddy PWA — Droplet & Nib */
:root {
  --teal: #2C95B0;
  --teal-soft: rgba(44, 149, 176, 0.16);
  --teal-glow: rgba(44, 149, 176, 0.35);
  --bronze: #B08A47;
  --bg: #0b1015;
  --bg-elev: #131a21;
  --bg-elev-2: #1a232b;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8edf2;
  --text-dim: #8a96a2;
  --text-faint: #5a6571;
  --droplet: #6cc9d6;
  --nib: #d8b25e;
  --danger: #d97757;
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 12% 8%, rgba(44, 149, 176, 0.08), transparent 45%),
    radial-gradient(circle at 88% 92%, rgba(176, 138, 71, 0.05), transparent 45%),
    var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  position: relative;
}

/* --- TOP BAR --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px calc(8px + env(safe-area-inset-top, 0)) 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0));
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 21, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand .nib {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 8px var(--teal-glow));
}

.brand .wordmark {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:hover, .icon-btn:active {
  color: var(--text);
  background: var(--border);
}

/* --- MODE BAR --- */
.mode-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-btn.active[data-mode="droplet"] {
  background: rgba(108, 201, 214, 0.14);
  border-color: var(--droplet);
  color: var(--droplet);
  box-shadow: 0 0 16px rgba(108, 201, 214, 0.2);
}

.mode-btn.active[data-mode="nib"] {
  background: rgba(216, 178, 94, 0.12);
  border-color: var(--nib);
  color: var(--nib);
  box-shadow: 0 0 16px rgba(216, 178, 94, 0.18);
}

.mode-tag {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}

/* --- CHAT --- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 16px 16px;
  scroll-behavior: smooth;
}

.empty-state {
  text-align: center;
  padding: 12vh 24px 0 24px;
  color: var(--text-dim);
}

.empty-state .empty-nib {
  width: 64px;
  height: 64px;
  opacity: 0.9;
  filter: drop-shadow(0 0 24px var(--teal-glow));
  margin-bottom: 24px;
}

.empty-title {
  font-family: 'Fraunces', serif;
  font-size: 42px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 12px 0;
}

.empty-sub {
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 8px 0;
  line-height: 1.5;
}

.empty-hint {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 28px;
}

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin: 0 4px 0 8px;
}
.dot.droplet { background: var(--droplet); }
.dot.nib { background: var(--nib); }

.msg {
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: fadeUp 0.3s ease;
}

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

.msg.user {
  align-items: flex-end;
}

.msg .bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 15px;
  max-width: 88%;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.user .bubble {
  background: var(--teal);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg .meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.msg.assistant .meta::before {
  content: '◊ ';
  color: var(--droplet);
}

.msg.assistant.nib-mode .meta::before {
  content: '✒ ';
  color: var(--nib);
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* --- COMPOSER --- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0)) 12px;
  border-top: 1px solid var(--border);
  background: rgba(11, 16, 21, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#composer-input {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  outline: none;
  transition: border-color 0.18s;
}

#composer-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.send-btn, .stop-btn {
  background: var(--teal);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, transform 0.1s;
}

.send-btn:hover { background: #348fab; }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--bg-elev-2); color: var(--text-faint); cursor: not-allowed; }

.stop-btn {
  background: var(--danger);
}

.hidden { display: none !important; }

/* --- DRAWERS --- */
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(420px, 88vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  z-index: 50;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.16, 1);
}

.drawer-right {
  right: 0;
  transform: translateX(100%);
  border-left: 1px solid var(--border);
}
.drawer-right.open { transform: translateX(0); }

.drawer-left {
  left: 0;
  transform: translateX(-100%);
  border-right: 1px solid var(--border);
}
.drawer-left.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-head h2 {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 500;
  margin: 0;
}

.drawer-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

.memory-editor {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 12px;
  outline: none;
  resize: none;
}

.memory-editor:focus { border-color: var(--teal); }

.drawer-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--teal);
  color: white;
}
.btn-primary:hover { background: #348fab; }

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }

.new-conv {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
}

.conv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}

.conv-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  border: 1px solid transparent;
  transition: background 0.15s;
}

.conv-item:hover { background: var(--bg-elev-2); }
.conv-item.active { background: var(--bg-elev-2); border-color: var(--teal); }

.conv-item .conv-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item .conv-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* --- SCRIM --- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.25s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* --- MOBILE --- */
@media (max-width: 600px) {
  .empty-title { font-size: 36px; }
  .empty-state { padding-top: 8vh; }
}

/* simple markdown bits */
.bubble code {
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 0.92em;
}
.bubble pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}
.bubble strong { color: #fff; font-weight: 600; }
.msg.user .bubble code, .msg.user .bubble pre { background: rgba(0,0,0,0.25); color: #fff; }

/* =========================================================================
   ARTIFACTS — Phase 1 styling
   Cream parchment field, teal nib accent, Fraunces titles, Inter body.
   ========================================================================= */

:root {
  --parchment: #f8f2e4;
  --parchment-edge: #ede2c8;
  --parchment-deep: #f0e7d2;
  --ink-dark: #1a1410;
  --ink-soft: #4a3f33;
  --teal-nib: #1f7a6f;
  --teal-nib-soft: #2d9a8c;
  --gold-thread: #b88a3e;
}

/* Artifacts drawer specifics */
.drawer.drawer-artifacts {
  background: linear-gradient(180deg, #14191e 0%, #0e1418 100%);
}

.artifact-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px 0;
  padding: 0 16px;
}

.filter-chip {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.filter-chip.active {
  background: var(--teal-nib);
  color: #fff;
  border-color: var(--teal-nib-soft);
}

.artifact-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 24px 16px;
  overflow-y: auto;
  flex: 1;
}

.artifact-empty {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.5);
}
.artifact-empty .kind-glyph {
  font-size: 40px;
  color: var(--teal-nib-soft);
  display: block;
  margin-bottom: 12px;
}
.artifact-empty .muted {
  color: rgba(255, 255, 255, 0.35);
  font-size: 13px;
}

/* Mini cards in the drawer grid */
.artifact-card-mini {
  background: var(--parchment);
  color: var(--ink-dark);
  border: 1px solid var(--parchment-edge);
  border-left: 3px solid var(--teal-nib);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), inset 0 0 30px rgba(184, 138, 62, 0.04);
}
.artifact-card-mini:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), inset 0 0 30px rgba(184, 138, 62, 0.08);
}

.kind-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(31, 122, 111, 0.12);
  color: var(--teal-nib);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kind-glyph {
  font-size: 11px;
  line-height: 1;
}

.art-title {
  font-family: "Fraunces", "Times New Roman", serif;
  font-weight: 600;
  font-size: 16px;
  margin-top: 8px;
  color: var(--ink-dark);
  line-height: 1.25;
}
.art-thought {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 6px;
  line-height: 1.4;
}
.art-meta {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
  color: rgba(74, 63, 51, 0.6);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

/* Full view inside the drawer */
.artifact-full {
  background: var(--parchment);
  color: var(--ink-dark);
  border: 1px solid var(--parchment-edge);
  border-radius: 10px;
  padding: 18px 18px 22px;
}
.btn-back {
  background: transparent;
  border: none;
  color: var(--teal-nib);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  margin-bottom: 12px;
}
.art-full-title {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--ink-dark);
  margin: 8px 0 16px;
  line-height: 1.2;
}
.art-section { margin-bottom: 18px; }
.art-section-label {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--teal-nib);
  margin-bottom: 8px;
}
.art-section-body {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.art-section-body code {
  background: rgba(31, 122, 111, 0.08);
  color: var(--ink-dark);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
.art-section-body pre {
  background: var(--parchment-deep);
  border: 1px solid var(--parchment-edge);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
}
.proof-body strong { color: var(--ink-dark); }

.art-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.btn-danger {
  background: rgba(180, 50, 50, 0.1);
  color: #b43232;
  border: 1px solid rgba(180, 50, 50, 0.3);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-danger:hover {
  background: rgba(180, 50, 50, 0.15);
}
.art-meta-full {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
  color: rgba(74, 63, 51, 0.55);
  margin-top: 14px;
  border-top: 1px solid var(--parchment-edge);
  padding-top: 10px;
}

/* Inline artifact card in chat (Thought / Proof flip card) */
.msg.artifact-inline {
  display: flex;
  margin: 6px 0;
}
.artifact-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  min-height: 96px;
  perspective: 1000px;
  cursor: pointer;
}
.art-card-face {
  background: var(--parchment);
  color: var(--ink-dark);
  border: 1px solid var(--parchment-edge);
  border-left: 3px solid var(--teal-nib);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), inset 0 0 40px rgba(184, 138, 62, 0.05);
  transition: transform 0.5s cubic-bezier(0.5, 0, 0.2, 1), opacity 0.3s;
  backface-visibility: hidden;
}
.art-face-thought { display: block; }
.art-face-proof {
  display: none;
}
.artifact-card.flipped .art-face-thought {
  display: none;
}
.artifact-card.flipped .art-face-proof {
  display: block;
  border-left-color: var(--gold-thread);
}
.art-card-title {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--ink-dark);
  margin: 8px 0 6px;
  line-height: 1.25;
}
.art-card-hint {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
  color: rgba(74, 63, 51, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.art-open-full {
  margin-top: 10px;
}
