/* Unstuck Conversation Lab — standalone playground. Calm app-adjacent look:
   cream surface, ink text, coral accents. One file, no framework. */

:root {
  --coral: #E89077;
  --coral-deep: #C96F55;
  --cream: #FAF6F1;
  --surface: #FFFFFF;
  --ink: #2B2622;
  --ink-soft: #6E655D;
  --line: #E9E1D8;
  --green: #7BA05B;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--sans); color: var(--ink);
  background: var(--cream); display: flex; flex-direction: column;
}

/* ── header ── */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.tag {
  font-size: 11px; font-weight: 500; color: var(--ink-soft);
  background: var(--cream); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 999px;
}
.bar-actions { display: flex; gap: 8px; align-items: center; }
.planlink { font-size: 13px; color: var(--coral-deep); text-decoration: none; padding: 7px 10px; }
.planlink:hover { text-decoration: underline; }

button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 7px 14px;
}
button:hover { border-color: var(--coral); }
button.primary { background: var(--coral); border-color: var(--coral); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--coral-deep); }
button.ghost { background: transparent; }
button.danger { color: #B4432F; border-color: #E4B8AE; }
button.warn { color: var(--ink-soft); }

/* ── persona drawer ── */
.drawer { background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 16px; }
.drawer-grid { display: grid; grid-template-columns: 1fr 260px; gap: 16px; max-width: 1200px; margin: 0 auto; }
.drawer-side { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.field textarea, .field input[type=text], .field input[type=password], .field select {
  font: 13px/1.5 ui-monospace, Menlo, monospace; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--cream);
}
.field textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; }
.hint { font-size: 12px; color: var(--ink-soft); margin: 0; }
.hint-inline { font-size: 11px; font-weight: 400; color: var(--ink-soft); }

/* ── layout ── */
.lab {
  flex: 1; display: grid; grid-template-columns: 280px minmax(420px, 1fr) 300px;
  gap: 14px; padding: 14px 16px; max-width: 1400px; margin: 0 auto; width: 100%;
  min-height: 0;
}
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; overflow-y: auto; min-height: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h2 { font-size: 15px; margin: 0; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 16px 0 6px; }
.panel-sub { font-size: 12px; color: var(--ink-soft); margin: 6px 0 12px; }

.switch { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }

/* facts */
.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.facts li {
  display: flex; gap: 8px; align-items: flex-start; font-size: 13px;
  background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px;
}
.facts li.fresh { border-color: var(--coral); box-shadow: 0 0 0 2px rgba(232,144,119,.25); }
.facts li .cat {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em; flex-shrink: 0;
  color: var(--coral-deep); background: rgba(232,144,119,.14); border-radius: 6px; padding: 2px 6px; margin-top: 1px;
}
.facts li .txt { flex: 1; }
.facts li .del { border: none; background: none; color: var(--ink-soft); padding: 0 2px; font-size: 14px; }
.facts.derived li .cat { color: var(--ink-soft); background: var(--line); }
.facts .empty { color: var(--ink-soft); font-size: 12px; border-style: dashed; justify-content: center; }
.noticed-head { margin-top: 14px; }
.fact-add { display: flex; gap: 6px; margin-top: 10px; }
.fact-add select { font-size: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--cream); }
.fact-add input { flex: 1; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.presets { margin-top: 8px; }
.presets button { font-size: 12px; padding: 5px 10px; }

/* conversation */
.convo { display: flex; flex-direction: column; gap: 10px; position: relative; }
.brief {
  font-family: var(--serif); font-size: 15px; line-height: 1.55;
  background: linear-gradient(135deg, #FDF3EC, #FAF6F1);
  border: 1px solid #F0DCCF; border-radius: 14px; padding: 14px 16px;
}
.brief .greet { font-size: 19px; margin-bottom: 4px; }
.brief .probe { margin-top: 10px; font-family: var(--sans); font-size: 13px; }
.brief .probe .q { font-style: italic; color: var(--ink-soft); margin-bottom: 6px; }
.brief .probe button { font-size: 12px; padding: 5px 10px; margin-right: 6px; }

.thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; min-height: 200px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 16px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--coral); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--cream); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.thinking { color: var(--ink-soft); font-style: italic; }
.receipt-chip {
  align-self: flex-start; display: flex; gap: 8px; align-items: center;
  font-size: 12px; color: var(--ink-soft);
  border: 1px dashed var(--line); border-radius: 10px; padding: 5px 10px; background: var(--surface);
}
.receipt-chip .ok { color: var(--green); font-weight: 700; }
.receipt-chip button { border: none; background: none; color: var(--coral-deep); font-size: 12px; padding: 0; text-decoration: underline; }

.scenarios { display: flex; gap: 6px; flex-wrap: wrap; }
.scenarios button { font-size: 12px; padding: 6px 11px; border-radius: 999px; background: var(--cream); }

.composer { display: flex; gap: 8px; }
.composer input { flex: 1; font-size: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; background: var(--surface); }
.composer input:focus { outline: 2px solid rgba(232,144,119,.4); border-color: var(--coral); }
#btn-voice { font-size: 16px; border-radius: 12px; }
#btn-voice.live { background: var(--coral); border-color: var(--coral); }

/* voice overlay */
.voice-overlay[hidden] { display: none; }
.voice-overlay {
  position: absolute; inset: 0; border-radius: 16px;
  background: rgba(43,38,34,.88); color: #fff; backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 5;
  text-align: center; padding: 24px;
}
.orb {
  width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #F5B9A5, var(--coral));
  transition: transform .18s ease;
}
.orb.speaking { animation: pulse 1.1s ease-in-out infinite; }
.orb.listening { box-shadow: 0 0 0 8px rgba(232,144,119,.18); }
@keyframes pulse { 50% { transform: scale(1.12); } }
.voice-state { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; opacity: .75; }
.voice-caption { font-size: 15px; line-height: 1.5; max-width: 480px; min-height: 44px; font-family: var(--serif); }
.voice-overlay .ghost { color: #fff; border-color: rgba(255,255,255,.35); background: transparent; }

/* world */
.week { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.week .day { display: flex; gap: 8px; align-items: baseline; padding: 4px 6px; border-radius: 8px; }
.week .day.today { background: rgba(232,144,119,.1); }
.week .dname { width: 60px; flex-shrink: 0; color: var(--ink-soft); font-weight: 600; }
.week .blocks { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.week .blk { display: flex; gap: 6px; }
.week .blk .t { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.week .blk.done { text-decoration: line-through; color: var(--ink-soft); }
.week .none { color: var(--line); }
.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.tasks li { display: flex; gap: 6px; align-items: baseline; padding: 5px 7px; border-radius: 8px; background: var(--cream); }
.tasks li.done { opacity: .5; text-decoration: line-through; }
.tasks li .est { font-size: 11px; color: var(--ink-soft); margin-left: auto; flex-shrink: 0; }
.receipts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.receipts li { padding: 4px 6px; border-left: 2px solid var(--coral); background: var(--cream); border-radius: 0 8px 8px 0; }

/* settings modal */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(43,38,34,.4); }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.settings-form h2 { margin: 0; font-size: 16px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px; padding: 9px 16px; border-radius: 12px; z-index: 50;
}

/* narrow screens: stack panels, conversation first */
@media (max-width: 980px) {
  .lab { grid-template-columns: 1fr; }
  #panel-convo { order: 0; min-height: 70vh; }
  #panel-facts { order: 1; }
  #panel-world { order: 2; }
  .drawer-grid { grid-template-columns: 1fr; }
}
