:root {
  --ink: #17211d;
  --muted: #66716c;
  --cream: #f4f1e9;
  --paper: #fffdf8;
  --line: #dedbd2;
  --green: #254d3d;
  --green-bright: #3c755f;
  --sage: #dce7df;
  --rust: #ba633f;
  --danger: #9f342e;
  --shadow: 0 24px 80px rgba(25, 39, 33, 0.14);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }

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

body { margin: 0; }

button, input, textarea { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(60, 117, 95, 0.34);
  outline-offset: 2px;
}

.kicker {
  margin: 0 0 0.75rem;
  color: var(--rust);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.studio-mark {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  place-items: center;
  border-radius: 1rem 1rem 1rem 0.28rem;
  color: white;
  background: var(--green);
  box-shadow: 0 12px 32px rgba(37, 77, 61, 0.2);
  font-family: Georgia, serif;
  font-size: 1.6rem;
  font-style: italic;
}

.studio-mark.small {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.68rem 0.68rem 0.68rem 0.18rem;
  font-size: 1.05rem;
}

.primary-button,
.secondary-button,
.outline-button,
.attach-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0.7rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.primary-button {
  min-height: 3rem;
  padding: 0.75rem 1.15rem;
  color: white;
  background: var(--green);
  font-weight: 750;
}

.primary-button:hover { background: #193d2f; transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: 0.55; transform: none; }

.secondary-button {
  width: 100%;
  min-height: 2.75rem;
  justify-content: flex-start;
  padding: 0.65rem 0.8rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.secondary-button:hover { background: rgba(255, 255, 255, 0.12); }

.outline-button {
  min-height: 2.4rem;
  padding: 0.5rem 0.8rem;
  color: var(--ink);
  border: 1px solid var(--line);
  background: white;
  font-size: 0.82rem;
  font-weight: 700;
}

.outline-button:hover { border-color: #b7bdb8; }

.text-button {
  padding: 0.5rem;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 15% 10%, rgba(214, 170, 126, 0.28), transparent 34rem),
    radial-gradient(circle at 90% 90%, rgba(66, 117, 93, 0.2), transparent 32rem),
    var(--cream);
}

.login-shell { width: min(100%, 28rem); }

.login-card {
  padding: clamp(2rem, 6vw, 3.4rem);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 1.5rem;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-card .studio-mark { margin-bottom: 2.2rem; }

.login-card h1 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: clamp(2.25rem, 8vw, 3.4rem);
  font-weight: 500;
  letter-spacing: -0.045em;
}

.login-intro {
  margin: 0.8rem 0 2rem;
  color: var(--muted);
  line-height: 1.6;
}

.login-form { display: grid; gap: 1rem; }

.login-form label { display: grid; gap: 0.42rem; }

.login-form label span {
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.login-form input {
  width: 100%;
  min-height: 3.15rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  color: var(--ink);
  background: white;
}

.login-form input:focus { border-color: var(--green-bright); }

.login-form .primary-button { margin-top: 0.5rem; }

.login-footnote {
  margin: 1.5rem 0 0;
  color: #8a928e;
  font-size: 0.74rem;
  text-align: center;
}

.alert {
  margin-bottom: 1rem;
  padding: 0.8rem 0.9rem;
  border-radius: 0.6rem;
  font-size: 0.85rem;
  line-height: 1.4;
}

.alert-error { color: #70231f; background: #f7dedb; }

.editor-page {
  height: 100vh;
  overflow: hidden;
  background: #e9e8e2;
}

.editor-header {
  display: flex;
  height: 4.25rem;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.15rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.96);
}

.editor-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
}

.editor-brand > span:last-child { display: grid; line-height: 1; }
.editor-brand strong { font-family: Georgia, serif; font-size: 1.12rem; letter-spacing: 0.02em; }
.editor-brand small { margin-top: 0.2rem; font-size: 0.53rem; font-weight: 800; letter-spacing: 0.25em; }

.header-actions { display: flex; align-items: center; gap: 0.7rem; }
.header-actions form { margin: 0; }

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.save-state i,
.preview-bar i {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: #42a06f;
  box-shadow: 0 0 0 4px rgba(66, 160, 111, 0.11);
}

.save-state.busy i { background: #d39048; animation: pulse 1.1s infinite; }
.save-state.error i { background: var(--danger); }

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

.editor-layout {
  display: grid;
  height: calc(100vh - 4.25rem);
  grid-template-columns: 15.5rem minmax(23rem, 35rem) minmax(26rem, 1fr);
}

.studio-sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.65rem 1.2rem;
  color: #eff5f1;
  background: var(--green);
  overflow-y: auto;
}

.studio-sidebar .kicker { color: #dba986; }
.studio-sidebar .secondary-button { color: #eff5f1; }

.studio-sidebar h1 {
  max-width: 12ch;
  margin: 0 0 1rem;
  font-family: Georgia, serif;
  font-size: 1.65rem;
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.studio-sidebar p { color: #c8d6cf; font-size: 0.82rem; line-height: 1.55; }
.sidebar-actions { display: grid; gap: 0.55rem; margin: 1.5rem 0; }

.workspace-facts { margin: auto 0 0; }
.workspace-facts div { padding: 0.72rem 0; border-top: 1px solid rgba(255,255,255,0.12); }
.workspace-facts dt { color: #a9beb4; font-size: 0.62rem; letter-spacing: 0.12em; text-transform: uppercase; }
.workspace-facts dd { margin: 0.25rem 0 0; font-size: 0.78rem; overflow-wrap: anywhere; }
.studio-sidebar .privacy-note { margin: 1rem 0 0; color: #9db2a8; font-size: 0.68rem; }

.chat-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.chat-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem 1.35rem 1rem;
  border-bottom: 1px solid #ece9e1;
}

.chat-heading .kicker { margin-bottom: 0.35rem; }
.chat-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 1.35rem; font-weight: 500; }

.validation-state { color: var(--muted); font-size: 0.68rem; white-space: nowrap; }
.validation-state.good { color: #347355; }
.validation-state.bad { color: var(--danger); }

.message-list {
  min-height: 0;
  padding: 1.25rem;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message { display: flex; gap: 0.68rem; margin-bottom: 1.1rem; }

.message-avatar {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 0.55rem 0.55rem 0.55rem 0.14rem;
  color: white;
  background: var(--green);
  font-family: Georgia, serif;
  font-size: 0.86rem;
}

.user-message { justify-content: flex-end; }
.user-message .message-avatar { order: 2; color: var(--ink); background: #e6dfd1; }

.message-body {
  max-width: min(88%, 34rem);
  padding: 0.78rem 0.9rem;
  border: 1px solid #e5e3dc;
  border-radius: 0.3rem 0.9rem 0.9rem 0.9rem;
  background: white;
  box-shadow: 0 5px 18px rgba(28, 42, 35, 0.04);
}

.user-message .message-body {
  border-color: #d8e2db;
  border-radius: 0.9rem 0.3rem 0.9rem 0.9rem;
  background: #edf3ef;
}

.message-body p { margin: 0; font-size: 0.86rem; line-height: 1.55; white-space: pre-wrap; }
.message-meta { margin-top: 0.55rem; color: #84908a; font-size: 0.66rem; }
.changed-files { margin: 0.55rem 0 0; padding-left: 1.1rem; color: #66716c; font-size: 0.68rem; }

.message-images { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.65rem; }
.message-images img { width: 5.5rem; height: 4rem; border-radius: 0.45rem; object-fit: cover; background: #eee; }

.thinking .message-body { color: var(--muted); }
.thinking-dots { display: inline-flex; gap: 0.2rem; margin-left: 0.4rem; }
.thinking-dots i { width: 0.25rem; height: 0.25rem; border-radius: 50%; background: currentColor; animation: thinking 1s infinite; }
.thinking-dots i:nth-child(2) { animation-delay: 150ms; }
.thinking-dots i:nth-child(3) { animation-delay: 300ms; }
@keyframes thinking { 50% { transform: translateY(-0.2rem); opacity: 0.35; } }

.composer {
  margin: 0 1rem 1rem;
  padding: 0.75rem;
  border: 1px solid #d9d7cf;
  border-radius: 0.9rem;
  background: white;
  box-shadow: 0 12px 35px rgba(25, 39, 33, 0.08);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 4.7rem;
  max-height: 11rem;
  resize: vertical;
  padding: 0.25rem 0.3rem 0.65rem;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  line-height: 1.45;
}

.composer textarea::placeholder { color: #949b97; }

.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; }
.composer-footer > div { display: flex; align-items: center; min-width: 0; gap: 0.55rem; }

.attach-button { padding: 0.48rem 0.6rem; color: var(--green); background: var(--sage); font-size: 0.73rem; font-weight: 750; }
.attach-button:hover { background: #ccddd2; }
.upload-help { color: #919792; font-size: 0.6rem; }
.send-button { min-height: 2.6rem; white-space: nowrap; font-size: 0.78rem; }
.send-button span { margin-left: 0.4rem; font-size: 1rem; }

.attachment-preview { display: flex; gap: 0.5rem; padding-bottom: 0.7rem; overflow-x: auto; }
.attachment-chip { position: relative; flex: 0 0 auto; }
.attachment-chip img { display: block; width: 4rem; height: 3.2rem; border-radius: 0.45rem; object-fit: cover; }
.attachment-chip span { display: block; width: 4rem; margin-top: 0.2rem; overflow: hidden; color: var(--muted); font-size: 0.56rem; text-overflow: ellipsis; white-space: nowrap; }

.preview-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 2.35rem 1fr;
  padding: 0.65rem 0.65rem 0.65rem 0;
  background: #e9e8e2;
}

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  color: #66716c;
  font-size: 0.68rem;
}

.preview-bar span { display: inline-flex; align-items: center; gap: 0.45rem; }
.preview-bar button { border: 0; color: #66716c; background: transparent; cursor: pointer; font-size: 1rem; }

.preview-panel iframe {
  width: 100%;
  height: 100%;
  border: 1px solid #d5d4ce;
  border-radius: 0.75rem;
  background: white;
  box-shadow: 0 8px 26px rgba(25, 39, 33, 0.08);
}

@media (max-width: 1180px) {
  .editor-layout { grid-template-columns: 13rem minmax(22rem, 34rem) 1fr; }
  .studio-sidebar { padding-inline: 1rem; }
  .upload-help { display: none; }
}

@media (max-width: 900px) {
  .editor-page { height: auto; min-height: 100vh; overflow: auto; }
  .editor-header { position: sticky; top: 0; z-index: 20; }
  .save-state { display: none; }
  .editor-layout { display: block; height: auto; }
  .studio-sidebar { min-height: auto; }
  .studio-sidebar > div:first-child p:last-child,
  .workspace-facts,
  .privacy-note { display: none; }
  .studio-sidebar h1 { max-width: none; margin-bottom: 0; font-size: 1.35rem; }
  .sidebar-actions { grid-template-columns: repeat(3, 1fr); margin-bottom: 0; }
  .secondary-button { justify-content: center; text-align: center; }
  .chat-panel { height: calc(100vh - 11rem); min-height: 38rem; border-right: 0; }
  .preview-panel { height: 75vh; padding: 0.65rem; }
}

@media (max-width: 580px) {
  .editor-header { padding-inline: 0.75rem; }
  .outline-button { display: none; }
  .studio-sidebar { padding: 1rem; }
  .sidebar-actions { grid-template-columns: 1fr; }
  .secondary-button { min-height: 2.35rem; }
  .chat-heading { padding-inline: 1rem; }
  .validation-state { display: none; }
  .message-list { padding: 1rem 0.75rem; }
  .message-body { max-width: 92%; }
  .composer { margin-inline: 0.6rem; }
  .composer-footer { align-items: flex-end; }
  .composer-footer > div { display: block; }
  .upload-help { display: none; }
  .send-button { padding-inline: 0.8rem; }
  .preview-panel { height: 60vh; }
}
