:root {
  --gradient: linear-gradient(150deg, #f1ecfe 0%, #fbeff7 55%, #fff4ec 100%);
  --surface: #ffffff;
  --soft: #f4f0fa;
  --ink: #1d1530;
  --muted: #6a6180;
  --line: #e4dcf0;
  --field-line: #8f83a8;
  --accent: #6d28d9;
  --accent-dark: #5b21b6;
  --danger: #b91c1c;
  --warn-bg: #fff6e0;
  --warn-ink: #7a4d00;
  --radius: 28px;
  --radius-field: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
  background: var(--gradient) fixed;
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.card {
  width: 100%;
  max-width: 460px;
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgb(76 40 130 / 10%);
}

.brand { color: var(--ink); font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em; }
h1 { margin: 0 0 8px; font-size: 2rem; line-height: 1.1; letter-spacing: -0.03em; font-weight: 800; }
.sub { margin: 0 0 24px; color: var(--muted); }
form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 650; font-size: 0.9rem; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

input[type="text"], input[type="password"], input[type="file"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius-field);
  background: var(--soft);
  color: inherit;
  font: inherit;
}
textarea { min-height: 150px; resize: vertical; }
:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

a.btn { display: grid; place-items: center; text-decoration: none; }
.btn {
  width: 100%;
  min-height: 50px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  transition: background 120ms, transform 120ms;
}
.btn:hover:not(:disabled) { background: var(--accent-dark); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.quiet { background: var(--soft); color: var(--accent-dark); }
.btn.quiet:hover:not(:disabled) { background: var(--line); }
.btn.danger { background: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #991b1b; }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn.small { width: auto; min-height: 44px; padding: 8px 16px; font-size: 0.9rem; }

.code {
  padding: 16px;
  background: var(--soft);
  border-radius: var(--radius-field);
  font: 650 1rem/1.6 ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}
.code.tiny { font-size: 0.75rem; text-align: start; }
.stack { display: grid; gap: 12px; }
.note { padding: 12px 14px; border-radius: var(--radius-field); background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; margin: 0; }
.error { color: var(--danger); font-size: 0.92rem; font-weight: 600; margin: 0; }
.counter { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 700; }

.links { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: center; }
.links a { color: var(--accent-dark); font-size: 0.9rem; min-height: 24px; }

body.wide { justify-content: flex-start; }
.card.big { max-width: 1040px; padding: 0; height: min(760px, calc(100dvh - 110px)); overflow: hidden; }
.shell { display: grid; grid-template-columns: 320px 1fr; height: 100%; }
.side { display: flex; flex-direction: column; border-inline-end: 1.5px solid var(--line); min-height: 0; }
.side-head { padding: 20px; display: grid; gap: 12px; }
.side-head h1 { font-size: 1.5rem; margin: 0; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.list { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: grid; gap: 4px; align-content: start; }
.thread { position: relative; display: grid; gap: 2px; width: 100%; padding: 12px 28px 12px 14px; border: 0; border-radius: var(--radius-field); background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.thread:hover { background: var(--soft); }
.thread.active { background: var(--line); }
.thread:disabled { opacity: 0.6; cursor: progress; }
.thread small { color: var(--muted); font-size: 0.75rem; }
.thread span { color: var(--muted); font-size: 0.9rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dot { position: absolute; inset-inline-end: 12px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: #ec4899; }
.empty { padding: 20px; color: var(--muted); margin: 0; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.placeholder { margin: auto; padding: 24px; color: var(--muted); text-align: center; }
.card.big > .pane { height: 100%; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1.5px solid var(--line); flex-wrap: wrap; }
.pane-head .grow { flex: 1; font-weight: 750; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 12px 16px; border-radius: 22px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble time { display: block; margin-top: 4px; font-size: 0.75rem; }
.bubble.theirs { align-self: flex-start; background: var(--soft); border-end-start-radius: 6px; }
.bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; border-end-end-radius: 6px; }
.bubble.broken { align-self: center; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; }
.composer { padding: 12px 16px 16px; display: grid; gap: 8px; border-top: 1.5px solid var(--line); }
.composer textarea { min-height: 60px; }
.composer-note { padding: 16px; color: var(--muted); text-align: center; margin: 0; border-top: 1.5px solid var(--line); }
.pane-error { padding: 0 16px 12px; }
.pane-status { padding: 0 16px 12px; }
.side-message { padding: 0 20px 12px; }
.done-links { margin-top: 16px; }

dialog { width: min(420px, calc(100vw - 32px)); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); }
dialog::backdrop { background: rgb(29 21 48 / 45%); }
dialog h2 { margin: 0 0 8px; font-size: 1.35rem; letter-spacing: -0.02em; }
dialog p { margin: 0 0 20px; color: var(--muted); }
.dialog-actions { display: flex; gap: 12px; }

@media (max-height: 500px) {
  body.wide { justify-content: flex-start; }
  .card.big { height: auto; overflow: visible; }
  .shell { height: auto; }
  .messages { min-height: 220px; max-height: 60vh; }
  .composer textarea { min-height: 44px; }
}

@media (max-width: 720px) {
  .card { padding: 24px; }
  .card.big { height: calc(100dvh - 100px); }
  .shell { grid-template-columns: 1fr; }
  .side { border-inline-end: 0; }
  .shell .main { display: none; }
  .shell.reading .side { display: none; }
  .shell.reading .main { display: flex; }
  .back { display: inline-block; }
  .bubble { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
