:root {
  --font-scale: 1;
  --canvas: #e8ece6;
  --paper: #fffdf8;
  --paper-soft: #f6f3e9;
  --ink: #17201b;
  --muted: #617068;
  --line: #d8ddd6;
  --green: #173d30;
  --green-soft: #dce9e1;
  --gold: #85621a;
  --danger: #9b3c2f;
  --shadow: 0 24px 70px rgba(23, 61, 48, .1);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
}

[data-theme="dark"] {
  --canvas: #0e1713;
  --paper: #17231d;
  --paper-soft: #202d26;
  --ink: #edf3ef;
  --muted: #b5c1ba;
  --line: #34463c;
  --green: #2f7357;
  --green-soft: #294639;
  --gold: #d8b45f;
  --danger: #ef9387;
  --shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

[data-theme="blue"] {
  --canvas: #eaf5fa;
  --paper: #fbfeff;
  --paper-soft: #e5f3f8;
  --ink: #123047;
  --muted: #526f80;
  --line: #bfdce8;
  --green: #075985;
  --green-soft: #d7edf6;
  --gold: #80550d;
  --shadow: 0 24px 70px rgba(7, 89, 133, .12);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.esboco-app {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: calc(16px * var(--font-scale));
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  background: var(--paper);
  color: var(--ink);
  left: 16px;
  padding: 10px 16px;
  position: fixed;
  top: -80px;
  z-index: 1000;
}
.skip-link:focus { top: 12px; }

.esboco-topbar {
  background: #102d24;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}
[data-theme="blue"] .esboco-topbar { background: #064b70; }
.header-inner {
  align-items: center;
  display: flex;
  gap: 12px;
  margin: 0 auto;
  max-width: 1600px;
  min-height: 74px;
  padding: 10px clamp(18px, 4vw, 56px);
}
.esboco-brand { align-items: center; color: #fff; display: flex; gap: 12px; text-decoration: none; }
.esboco-brand img { border: 2px solid rgba(255,255,255,.25); border-radius: 14px; }
.esboco-brand span { display: grid; line-height: 1.1; }
.esboco-brand strong { letter-spacing: .14em; }
.esboco-brand small { color: rgba(255,255,255,.64); font-size: .72rem; margin-top: 4px; }
.back-link { color: rgba(255,255,255,.78); font-size: .82rem; margin-left: auto; text-decoration: none; }
.account-actions { align-items: center; display: flex; gap: 13px; margin-left: auto; }
.account-actions .back-link { margin-left: 0; }
.balance-link {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px;
  color: #fff;
  font-size: .76rem;
  padding: 8px 11px;
  text-decoration: none;
}
.logout-button { background: transparent; border: 0; color: #efc9c3; font-size: .78rem; padding: 8px; }

.theme-toggle,
.font-scale-btn {
  align-items: center;
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px;
  color: #fff;
  display: inline-flex;
  justify-content: center;
  min-height: 38px;
  min-width: 38px;
}
.theme-toggle { flex: 0 0 auto; }
.font-scale-controls { align-items: center; color: rgba(255,255,255,.72); display: inline-flex; gap: 4px; margin-left: 2px; }
.font-scale-value { font-size: .7rem; min-width: 38px; text-align: center; }

.esboco-shell {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1600px;
  min-height: calc(100vh - 74px);
}
.drafts-panel {
  border-right: 1px solid var(--line);
  padding: 44px 28px;
}
.drafts-heading { align-items: center; display: flex; gap: 16px; justify-content: space-between; }
.drafts-heading h2 { font: 600 2rem/1 var(--serif); margin: 5px 0 0; }
.eyebrow { color: var(--gold); font-size: .7rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.icon-button {
  background: var(--green);
  border: 0;
  border-radius: 50%;
  color: #fff;
  font-size: 1.5rem;
  height: 42px;
  width: 42px;
}
.search-label { display: block; font-size: .76rem; font-weight: 700; margin: 32px 0 7px; }
.draft-search,
.field input,
.field textarea {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  outline: 0;
  width: 100%;
}
.draft-search { min-height: 46px; padding: 0 13px; }
.draft-search:focus,
.field input:focus,
.field textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent); }
.storage-note { color: var(--muted); font-size: .72rem; margin: 9px 0 22px; }
.draft-list { display: grid; gap: 9px; }
.draft-empty { color: var(--muted); font-size: .88rem; padding: 22px 0; }
.draft-item {
  align-items: stretch;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  overflow: hidden;
}
.draft-open { background: transparent; border: 0; color: var(--ink); min-width: 0; padding: 13px 10px 13px 14px; text-align: left; }
.draft-open strong, .draft-open span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-open span { color: var(--muted); font-size: .72rem; margin-top: 3px; }
.draft-delete { background: transparent; border: 0; color: var(--danger); font-size: .7rem; padding: 0 11px; }
.draft-item.active { border-color: var(--gold); box-shadow: inset 3px 0 var(--gold); }

.builder { min-width: 0; padding: clamp(42px, 6vw, 88px); }
.builder-intro { margin-bottom: 38px; max-width: 830px; }
.builder-intro h1 { font: 600 clamp(3rem, 6vw, 6rem)/.9 var(--serif); letter-spacing: -.04em; margin: 14px 0 22px; }
.builder-intro p { color: var(--muted); font-size: 1.05rem; max-width: 650px; }
.ai-generator {
  background:
    radial-gradient(circle at 92% 12%, rgba(216, 180, 95, .16), transparent 30%),
    var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
  overflow: hidden;
  padding: clamp(24px, 4vw, 38px);
}
.ai-heading { align-items: flex-start; display: flex; gap: 17px; }
.ai-mark {
  align-items: center;
  background: var(--green);
  border-radius: 13px;
  color: #fff;
  display: flex;
  flex: 0 0 auto;
  font-size: .72rem;
  font-weight: 800;
  height: 46px;
  justify-content: center;
  letter-spacing: .08em;
  width: 46px;
}
.ai-heading h2 { font: 600 2.25rem/1 var(--serif); margin: 5px 0 8px; }
.ai-title-row { align-items: center; display: flex; flex-wrap: wrap; gap: 10px; }
.ai-model { background: var(--green-soft); border-radius: 999px; color: var(--green); font-size: .68rem; font-weight: 800; letter-spacing: .06em; padding: 5px 9px; }
.ai-heading p { color: var(--muted); margin: 0; max-width: 660px; }
.ai-form { margin-top: 22px; }
.ai-form .field { margin-top: 0; }
.ai-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 14px; }
.field select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  min-height: 48px;
  padding: 0 12px;
  width: 100%;
}
.field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent); outline: 0; }
.ai-actions { align-items: center; display: flex; gap: 18px; justify-content: space-between; margin-top: 18px; }
.ai-actions p { color: var(--muted); font-size: .74rem; margin: 0; }
.button-ai {
  background: linear-gradient(135deg, var(--green), color-mix(in srgb, var(--green) 76%, var(--gold)));
  border: 0;
  color: #fff;
  flex: 0 0 auto;
  min-width: 150px;
}
.button-ai[disabled] { cursor: wait; opacity: .68; }
.ai-status { color: var(--muted); font-size: .78rem; margin: 12px 0 0; min-height: 20px; }
.ai-status.error { color: var(--danger); }
.editor-toolbar { align-items: center; display: flex; gap: 18px; justify-content: space-between; margin-bottom: 10px; }
.view-tabs { background: var(--paper-soft); border-radius: 12px; display: inline-flex; padding: 4px; }
.view-tab { background: transparent; border: 0; border-radius: 9px; color: var(--muted); min-height: 38px; padding: 0 16px; }
.view-tab.active { background: var(--paper); box-shadow: 0 3px 12px rgba(0,0,0,.08); color: var(--ink); font-weight: 700; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.button { border-radius: 11px; font-size: .82rem; font-weight: 700; min-height: 42px; padding: 0 16px; }
.button-quiet, .button-add { background: var(--paper); border: 1px solid var(--line); color: var(--ink); }
.button-primary { background: var(--green); border: 1px solid var(--green); color: #fff; }
.editor-status { color: var(--muted); font-size: .78rem; min-height: 24px; text-align: right; }
.editor-status.error { color: var(--danger); }

.editor-panel, .preview-panel { background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; }
.paper-section { display: grid; gap: 28px; grid-template-columns: 42px minmax(0, 1fr); padding: clamp(28px, 5vw, 62px); }
.paper-section + .paper-section { border-top: 1px solid var(--line); }
.section-number { color: var(--gold); font: 600 1.35rem var(--serif); }
.section-content { min-width: 0; }
.field-grid { display: grid; gap: 20px; margin-top: 19px; }
.field-grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-wide { grid-column: 1 / -1; }
.field { display: grid; gap: 7px; margin-top: 20px; }
.field > span { font-size: .78rem; font-weight: 700; }
.field input { min-height: 48px; padding: 0 14px; }
.field textarea { line-height: 1.65; min-height: 120px; padding: 13px 14px; resize: vertical; }
.points-heading { align-items: end; display: flex; gap: 20px; justify-content: space-between; }
.points-heading h2 { font: 600 2.1rem/1 var(--serif); margin: 6px 0 0; }
.points-list { display: grid; gap: 14px; margin-top: 24px; }
.point-card { background: var(--paper-soft); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.point-heading { align-items: center; display: flex; justify-content: space-between; }
.point-index { color: var(--gold); font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.remove-point { background: transparent; border: 0; color: var(--danger); font-size: .72rem; }

.outline-preview { margin: 0 auto; max-width: 850px; padding: clamp(38px, 7vw, 90px); }
.preview-kicker { color: var(--gold); font-size: .72rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.outline-preview h1 { font: 600 clamp(2.8rem, 6vw, 5rem)/.95 var(--serif); letter-spacing: -.03em; margin: 15px 0; }
.preview-reference { color: var(--gold); font-weight: 700; }
.preview-meta { color: var(--muted); font-size: .85rem; }
.preview-block { border-top: 1px solid var(--line); margin-top: 35px; padding-top: 28px; }
.preview-block h2 { font: 600 2rem/1.1 var(--serif); margin: 0 0 13px; }
.preview-block h3 { font: 600 1.55rem/1.2 var(--serif); margin: 28px 0 9px; }
.preview-block p { white-space: pre-wrap; }
.preview-placeholder { color: var(--muted); font-style: italic; }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-page { background: #102d24; }
.login-shell {
  align-items: center;
  background:
    radial-gradient(circle at 78% 18%, rgba(99, 153, 120, .32), transparent 30%),
    radial-gradient(circle at 18% 82%, rgba(181, 139, 52, .2), transparent 28%);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 30px 100px rgba(0,0,0,.28);
  max-width: 470px;
  padding: clamp(30px, 6vw, 54px);
  width: 100%;
}
.login-brand { align-items: center; color: var(--ink); display: flex; font-weight: 700; gap: 12px; margin-bottom: 42px; text-decoration: none; }
.login-brand img { border-radius: 16px; }
.login-card h1 { font: 600 clamp(2.8rem, 9vw, 4.4rem)/.95 var(--serif); letter-spacing: -.035em; margin: 12px 0 18px; }
.login-card > p { color: var(--muted); margin-bottom: 28px; }
.login-button { margin-top: 18px; width: 100%; }
.login-button[disabled] { cursor: wait; opacity: .7; }
.login-status { color: var(--danger); font-size: .8rem; min-height: 22px; }
.login-back { color: var(--muted); display: block; font-size: .8rem; margin-top: 22px; text-align: center; }

@media (max-width: 980px) {
  .esboco-shell { grid-template-columns: 1fr; }
  .drafts-panel { border-bottom: 1px solid var(--line); border-right: 0; padding: 28px 20px; }
  .draft-list { grid-auto-columns: minmax(230px, 280px); grid-auto-flow: column; overflow-x: auto; padding-bottom: 8px; }
  .builder { padding: 48px 20px 70px; }
}

@media (max-width: 700px) {
  .header-inner { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .account-actions { grid-column: 1 / -1; justify-content: flex-end; margin-left: 0; }
  .account-actions .back-link { display: none; }
  .theme-toggle { grid-column: 2; grid-row: 1; }
  .font-scale-controls { grid-column: 1 / -1; justify-self: end; }
  .editor-toolbar { align-items: stretch; flex-direction: column; }
  .ai-grid { grid-template-columns: 1fr; }
  .ai-actions { align-items: stretch; flex-direction: column; }
  .button-ai { width: 100%; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view-tabs { align-self: flex-start; }
  .paper-section { gap: 12px; grid-template-columns: 1fr; padding: 28px 20px; }
  .field-grid-two { grid-template-columns: 1fr; }
  .points-heading { align-items: flex-start; flex-direction: column; }
  .button-add { width: 100%; }
  .editor-status { text-align: left; }
}

@media (max-width: 420px) {
  .esboco-brand small, .font-scale-value { display: none; }
  .builder-intro h1 { font-size: 3rem; }
  .toolbar-actions { grid-template-columns: 1fr; }
}

@media print {
  @page { margin: 18mm; }
  .esboco-topbar, .drafts-panel, .builder-intro, .ai-generator, .editor-toolbar, .editor-status, .editor-panel { display: none !important; }
  .esboco-app, .esboco-shell, .builder, .preview-panel { background: #fff !important; color: #111 !important; display: block !important; margin: 0; padding: 0; }
  .preview-panel { border: 0; box-shadow: none; overflow: visible; }
  .outline-preview { max-width: none; padding: 0; }
  .preview-block { break-inside: avoid; }
}
