:root {
  --bg: #020617;
  --panel: #0f172a;
  --ink: #f8fafc;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #1e293b;
  --line-strong: #334155;
  --cyan: #67e8f9;
  --teal: #0e7490;
  --teal-deep: #155e75;
  --danger: #fecdd3;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: -0.011em;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-decoration: none;
}
.logo {
  display: block;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  object-fit: contain;
}
.side .logo { width: 28px; height: 28px; flex-basis: 28px; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 16px;
  background: #fff;
  color: #0f172a;
  font-weight: 700;
}
button.ghost {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
button.tiny { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: wait; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
h1, h2 { margin: 0; color: var(--ink); letter-spacing: -0.03em; line-height: 1.12; }
h1 { font-size: clamp(1.8rem, 3vw, 2.4rem); }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.error {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #9f1239;
  border-radius: 12px;
  background: #3f1d24;
  color: var(--danger);
}
.toasts {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toasts:empty { display: none; }
.toast {
  padding: 12px 14px;
  border: 1px solid rgba(103, 232, 249, 0.55);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  color: var(--ink);
  box-shadow: 0 16px 36px rgba(2, 6, 23, 0.45);
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}
.row { display: flex; gap: 10px; align-items: center; }
.row.tight { margin-bottom: 8px; }
.row select, .row button { flex: 1; }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px 16px 48px;
  background-color: #0f172a;
  background-image:
    linear-gradient(rgba(103, 232, 249, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(103, 232, 249, 0.07) 1px, transparent 1px),
    linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  background-size: 60px 60px, 60px 60px, cover;
}
.gate-panel { width: min(460px, 100%); display: grid; gap: 18px; }
.card {
  padding: 20px;
  border: 1px solid rgba(103, 232, 249, 0.25);
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.82);
  box-shadow: 0 20px 40px rgba(2, 6, 23, 0.35);
}
.card h1 { margin-bottom: 14px; }
label { display: grid; gap: 6px; margin: 12px 0 0; color: var(--muted); font-size: 0.92rem; }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: #020617;
  color: var(--ink);
}
textarea { resize: vertical; }
.card .row { margin-top: 16px; }
.card .row button { flex: 1; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  background: var(--bg);
}
.side {
  overflow: auto;
  padding: 14px 14px 20px;
  background: #0b1220;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.side-head, .stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.side h2 { margin-bottom: 8px; }
.list { display: grid; gap: 8px; }
button.item {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
  text-align: left;
  box-shadow: none;
}
button.item.active { background: var(--teal); color: #fff; border-color: transparent; }
.item small, .item .meta { display: block; margin-top: 4px; color: var(--muted); font-weight: 500; font-size: 0.85rem; }
button.item.active small { color: rgba(255, 255, 255, 0.8); }
.item .actions { display: flex; gap: 8px; margin-top: 8px; }
.profile { display: grid; gap: 8px; }
#invite-box { display: grid; gap: 8px; }
#invite-box h2 { margin: 0; }
#invite-box button { width: 100%; }
#invite-link { font-size: 0.8rem; resize: none; overflow-wrap: anywhere; }

.stage {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 18px 22px;
  background-image:
    linear-gradient(rgba(103, 232, 249, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(103, 232, 249, 0.045) 1px, transparent 1px);
  background-size: 60px 60px;
}
.stage-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.stage-head,
.bind {
  flex: 0 0 auto;
}
#understand-mode { flex: 0 0 auto; white-space: nowrap; }
.board {
  flex: 0 1 auto;
  min-height: 0;
}
.transcript {
  flex: 1 1 160px;
  min-height: 120px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 16px;
}
.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  background: var(--bg);
}
.bubble {
  max-width: min(680px, 92%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  white-space: pre-wrap;
}
.bubble.user { align-self: flex-end; background: var(--teal); border-color: transparent; color: #fff; }
.bubble.assistant { align-self: flex-start; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
#text { max-height: 140px; overflow: auto; }
.talk {
  align-self: center;
  width: 188px;
  height: 188px;
  margin-top: 0;
  border-radius: 50%;
  background: #fff;
  color: #0f172a;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
  box-shadow: 0 20px 40px rgba(2, 6, 23, 0.45);
}
.talk[data-state="listen"] { background: var(--teal); color: #fff; }
.talk[data-state="think"], .talk[data-state="speak"] { background: var(--teal-deep); color: #fff; }

body.sheet-open { overflow: hidden; }
.sheet-back {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sheet-back.is-open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed;
  z-index: 41;
  top: 0;
  right: 0;
  width: min(440px, 100%);
  height: 100%;
  padding: 20px 22px 32px;
  overflow: auto;
  background: #0f172a;
  border-left: 1px solid rgba(103, 232, 249, 0.25);
  box-shadow: -16px 0 40px rgba(2, 6, 23, 0.45);
  transform: translateX(104%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
}
.sheet.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}
.sheet-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-bar h2 { margin: 0; font-size: 1.35rem; }
.sheet-body { margin-top: 16px; color: var(--text); }
.sheet-body.plain { white-space: pre-wrap; }
.sheet { width: min(520px, 100%); }

.topbar, .nav-back { display: none; }
.bind { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bind select.is-set,
button.is-set { border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan); }
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-height: 220px;
  overflow: auto;
  margin-top: 10px;
}
.board h2 { margin-bottom: 8px; font-size: 1rem; }
.task { padding: 10px 0; border-bottom: 1px solid var(--line); }
.task.current { padding-left: 10px; box-shadow: inset 3px 0 0 var(--cyan); }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: auto; margin-top: 4px; }
.task-title, .sheet-body, button.item { overflow-wrap: anywhere; }
.task-title { font-weight: 650; }
.task-details, .note { margin: 4px 0 0 28px; color: var(--muted); font-size: 0.9rem; }
.note-link { margin-left: 8px; }
.task-actions, .project-actions, .create-row { display: flex; gap: 8px; margin-top: 8px; }
.create-row input { flex: 1; }
.priority { color: var(--cyan); font-size: 0.82rem; font-weight: 700; }

@media (max-width: 800px) {
  .app {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .stage { flex: 1; }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: #0b1220;
    border-bottom: 1px solid var(--line);
  }
  .topbar .brand { font-size: 1.15rem; }
  .nav-back {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(2, 6, 23, 0.55);
  }
  body.nav-open .nav-back { display: block; }
  .side {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  body.nav-open .side { transform: translateX(0); }
  .stage { min-height: 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .board, .bind { grid-template-columns: 1fr; }
  .board { max-height: 180px; }
  .composer { grid-template-columns: 1fr; }
  .talk { width: 112px; height: 112px; margin-top: 0; font-size: 1rem; }
  .dock { padding-top: 8px; gap: 8px; }
  .bubble { max-width: 100%; }
}
