:root {
  --bg: #f4f2ee;
  --bg-glow: rgba(99, 102, 241, 0.10);
  --surface: #ffffff;
  --border: rgba(17, 17, 17, 0.10);
  --text: #14140f;
  --muted: #77756d;
  --accent: #3d3ad6;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --shadow: 0 1px 2px rgba(17, 17, 17, 0.04), 0 12px 32px -12px rgba(17, 17, 17, 0.18);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e11;
    --bg-glow: rgba(99, 102, 241, 0.14);
    --surface: #17171c;
    --border: rgba(255, 255, 255, 0.10);
    --text: #ecebe6;
    --muted: #8b8a83;
    --accent: #8b8af8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 20px 40px -20px rgba(0, 0, 0, 0.8);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(900px 480px at 50% -10%, var(--bg-glow), transparent 70%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 880px;
  min-height: 100%;
  padding: clamp(20px, 4vh, 48px) clamp(16px, 4vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- header ---------- */
.app__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3.4vw, 32px);
  font-weight: 640;
  letter-spacing: -0.022em;
}

.app__sub {
  margin: 6px 0 0;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--muted);
  max-width: 46ch;
}

/* ---------- presence pill ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 520;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.status[data-state="online"] {
  color: var(--text);
}
.status[data-state="online"] .status__dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}
.status[data-state="connecting"] .status__dot {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}
.status[data-state="offline"] .status__dot {
  background: var(--err);
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* ---------- editor ---------- */
.editor {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.editor:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}

.editor__area {
  flex: 1 1 auto;
  width: 100%;
  min-height: 46vh;
  margin: 0;
  padding: clamp(18px, 2.6vw, 26px);
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 15.5px;
  line-height: 1.68;
  tab-size: 2;
  caret-color: var(--accent);
}

.editor__area::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.editor__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 20px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, var(--bg));
}

.meta {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ---------- button ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 560;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.06s ease,
    color 0.16s ease;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--err) 40%, var(--border));
  color: var(--err);
  background: color-mix(in srgb, var(--err) 7%, var(--surface));
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn--ghost {
  padding: 7px 14px;
  background: transparent;
}

.btn--ghost:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.btn--danger:hover {
  border-color: color-mix(in srgb, var(--err) 40%, var(--border));
  color: var(--err);
  background: color-mix(in srgb, var(--err) 7%, var(--surface));
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 14px);
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 520;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 560px) {
  .app__head {
    flex-direction: column;
  }
  .status {
    align-self: flex-start;
  }
  .editor__foot {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .toolbar {
    width: 100%;
  }
  .btn--ghost {
    flex: 1 1 auto;
  }
}
