:root {
  color-scheme: dark;
  --ink: #f4f1ea;
  --muted: rgba(244, 241, 234, 0.62);
  --line: rgba(244, 241, 234, 0.16);
  --green: #7ee092;
  --yellow: #f2d05c;
  --card: rgba(8, 10, 14, 0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #07080c;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  min-height: 100%;
  min-height: 100dvh;
}

#field {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px));
  pointer-events: none;
}

.card {
  pointer-events: auto;
  width: min(640px, 100%);
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 22px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(16px);
}

.card-head { display: flex; flex-direction: column; gap: 4px; }

.mark {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-size: 1.7rem;
  letter-spacing: 0.01em;
}

.quiet {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: min(52dvh, 520px);
  padding-right: 2px;
}

.thread:empty { display: none; }

.bubble {
  margin: 0;
  max-width: 92%;
  line-height: 1.45;
  font-size: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  align-self: flex-end;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px 14px 4px 14px;
}

.bubble.assistant { align-self: flex-start; }

.bubble.note {
  align-self: stretch;
  color: var(--yellow);
  font-size: 0.95rem;
}

.bubble.pending { color: var(--muted); }

#composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.composer-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.char-count {
  margin: 0;
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
}

.char-count.near { color: var(--yellow); }

.char-count.at { color: #f6d86b; font-weight: 600; }

.paste-notice {
  margin: 0;
  font-size: 0.82rem;
  color: var(--yellow);
}

textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  min-height: 52px;
}

textarea:focus {
  outline: 2px solid rgba(126, 224, 146, 0.55);
  outline-offset: 1px;
}

button {
  border: 0;
  background: var(--green);
  color: #10210f;
  font: inherit;
  font-weight: 650;
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 640px) {
  .stage { padding: 12px 10px calc(12px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px)); }
  .card { padding: 16px 14px 12px; border-radius: 18px; }
  .thread { max-height: 46dvh; }
}

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