:root {
  --ink: #14251f;
  --muted: #607069;
  --paper: #f4f1e9;
  --card: #fffdf8;
  --line: #d9d5ca;
  --green: #1f5a49;
  --green-dark: #163e34;
  --green-soft: #e6f0eb;
  --ochre: #c97843;
  --ochre-soft: #f7e7db;
  --danger: #a74636;
  --shadow: 0 18px 50px rgba(29, 47, 39, 0.08);
  --radius: 22px;
}

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

html { color-scheme: light; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(201, 120, 67, 0.10), transparent 34rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  align-items: center;
  background: rgba(244, 241, 233, 0.92);
  border-bottom: 1px solid rgba(20, 37, 31, 0.10);
  display: flex;
  justify-content: space-between;
  padding: 18px clamp(20px, 4vw, 64px);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand { align-items: center; display: flex; gap: 14px; }
.brand h1 { font-family: Georgia, serif; font-size: 1.35rem; font-weight: 500; margin: 0; }
.brand-mark {
  align-items: center;
  background: var(--green);
  border-radius: 50%;
  color: white;
  display: flex;
  font-family: Georgia, serif;
  font-size: 0.95rem;
  height: 44px;
  justify-content: center;
  letter-spacing: 0.04em;
  width: 44px;
}

.eyebrow {
  color: var(--ochre);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.14em;
  margin: 0 0 2px;
  text-transform: uppercase;
}

.skill-state {
  align-items: center;
  background: var(--green-soft);
  border: 1px solid #c8ddd3;
  border-radius: 999px;
  color: var(--green-dark);
  display: flex;
  font-size: 0.82rem;
  font-weight: 700;
  gap: 8px;
  padding: 8px 12px;
}
.state-dot { background: #2b8a67; border-radius: 50%; height: 8px; width: 8px; }

.topbar-actions { align-items: center; display: flex; gap: 12px; }
.logout-button { background: transparent; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.82rem; padding: 9px 14px; }
.logout-button:hover { border-color: var(--ochre); color: var(--green-dark); }

main { margin: 0 auto; max-width: 1500px; padding: 40px clamp(16px, 4vw, 64px) 64px; }
.hero { align-items: end; display: flex; gap: 24px; justify-content: space-between; margin: 0 0 28px; }
.hero h2 { font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3.5rem); font-weight: 500; letter-spacing: -0.035em; line-height: 1.04; margin: 0; max-width: 850px; }
.hero-copy { color: var(--muted); font-size: 1rem; margin: 16px 0 0; max-width: 710px; }

.card { background: var(--card); border: 1px solid rgba(20, 37, 31, 0.10); border-radius: var(--radius); box-shadow: var(--shadow); }
.intent-card { margin-bottom: 22px; padding: 26px; }
.section-heading { align-items: flex-start; display: flex; gap: 13px; margin-bottom: 22px; }
.section-heading.compact { margin-bottom: 16px; }
.section-heading h3 { font-family: Georgia, serif; font-size: 1.28rem; font-weight: 500; margin: 0; }
.section-heading p { color: var(--muted); font-size: 0.87rem; margin: 3px 0 0; }
.step { align-items: center; background: var(--ochre-soft); border-radius: 50%; color: #8d4529; display: flex; flex: 0 0 auto; font-weight: 800; height: 30px; justify-content: center; width: 30px; }

fieldset { border: 0; margin: 0; padding: 0; }
.segmented-control { background: #ece9e0; border-radius: 14px; display: inline-flex; gap: 4px; margin-bottom: 24px; padding: 4px; }
.segmented-control input { position: absolute; opacity: 0; }
.segmented-control span { border-radius: 10px; color: var(--muted); display: block; font-size: 0.88rem; font-weight: 750; padding: 9px 15px; transition: 160ms ease; }
.segmented-control input:checked + span { background: white; box-shadow: 0 3px 12px rgba(20, 37, 31, 0.10); color: var(--ink); }
.segmented-control input:focus-visible + span { outline: 3px solid rgba(31, 90, 73, 0.25); }

.settings-grid { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.settings-grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 0.78rem; font-weight: 760; }
.field-help { color: var(--muted); font-size: 0.7rem; }
.length-control { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr) 130px; }
.length-control input, .length-control select { min-width: 0; width: 100%; }
input, select, textarea { background: #fff; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); outline: none; transition: border 140ms, box-shadow 140ms; }
input, select { min-height: 44px; padding: 0 12px; }
textarea { line-height: 1.62; padding: 14px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31, 90, 73, 0.12); }

.switch-row { border-top: 1px solid var(--line); display: flex; gap: 34px; margin-top: 22px; padding-top: 20px; }
.switch { align-items: center; cursor: pointer; display: flex; gap: 11px; }
.switch input { opacity: 0; position: absolute; }
.switch-ui { background: #c9cec9; border-radius: 999px; height: 24px; position: relative; transition: 160ms; width: 42px; }
.switch-ui::after { background: white; border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,.15); content: ""; height: 18px; left: 3px; position: absolute; top: 3px; transition: 160ms; width: 18px; }
.switch input:checked + .switch-ui { background: var(--green); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch strong, .switch small { display: block; }
.switch strong { font-size: 0.84rem; }
.switch small { color: var(--muted); font-size: 0.72rem; }

.workspace-grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); }
.editor-card, .result-card { min-height: 720px; padding: 24px; }
.toolbar { align-items: center; color: var(--muted); display: flex; font-size: 0.74rem; justify-content: space-between; margin: 4px 0 9px; }
.text-button { background: transparent; border: 0; color: var(--green); font-size: 0.78rem; font-weight: 760; padding: 2px; }
#sourceText { font-family: Georgia, serif; font-size: 1rem; height: 340px; width: 100%; }
.context-field { margin-top: 16px; }
.context-field textarea { font-size: 0.88rem; }
.privacy-note { align-items: flex-start; background: var(--green-soft); border-radius: 12px; color: var(--green-dark); display: flex; flex-direction: column; font-size: 0.75rem; margin: 16px 0; padding: 12px 14px; }

.primary-button, .secondary-button { align-items: center; border-radius: 12px; display: inline-flex; font-weight: 780; justify-content: center; }
.primary-button { background: var(--green); border: 1px solid var(--green); color: white; font-size: 0.92rem; gap: 12px; min-height: 50px; width: 100%; }
.primary-button:hover { background: var(--green-dark); }
.primary-button:disabled { cursor: wait; opacity: 0.66; }
.secondary-button { background: transparent; border: 1px solid var(--line); color: var(--ink); font-size: 0.8rem; min-height: 38px; padding: 0 13px; }
.secondary-button:hover { background: white; border-color: #aaa99f; }

.empty-state, .loading-state, .error-state { align-items: center; display: flex; flex-direction: column; justify-content: center; min-height: 560px; text-align: center; }
.empty-mark { align-items: center; border: 1px solid var(--line); border-radius: 18px; color: var(--ochre); display: flex; font-family: Georgia, serif; font-size: 2rem; height: 78px; justify-content: center; margin-bottom: 16px; width: 78px; }
.empty-state h4, .loading-state h4, .error-state h4 { font-family: Georgia, serif; font-size: 1.25rem; font-weight: 500; margin: 0; }
.empty-state p, .loading-state p, .error-state p { color: var(--muted); font-size: 0.86rem; max-width: 360px; }
.loader { animation: spin 900ms linear infinite; border: 3px solid #d7ded9; border-radius: 50%; border-top-color: var(--green); height: 44px; margin-bottom: 18px; width: 44px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { color: var(--danger); }

.quality-strip { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.quality-pill { background: var(--green-soft); border-radius: 999px; color: var(--green-dark); font-size: 0.72rem; font-weight: 750; padding: 6px 9px; }
.quality-pill.warn { background: #fff0d4; color: #81531d; }

.score-board { align-items: stretch; display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); margin: 4px 0 10px; }
.score-card { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; }
.score-card > span { color: var(--muted); display: block; font-size: 0.7rem; font-weight: 760; text-transform: uppercase; }
.score-card strong { color: var(--ink); display: block; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; line-height: 1; margin-top: 5px; }
.score-card strong small { color: var(--muted); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 0.75rem; font-weight: 700; margin-left: 2px; }
.score-card p { color: var(--muted); font-size: 0.72rem; line-height: 1.4; margin: 7px 0 0; }
.score-after { background: var(--green-soft); border-color: #c8ddd3; }
.score-progress { align-items: center; color: var(--ochre); display: flex; flex-direction: column; justify-content: center; min-width: 54px; }
.score-progress > span { font-size: 1.4rem; }
.score-progress strong { font-size: 0.72rem; white-space: nowrap; }
.score-details { background: #faf8f2; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; padding: 9px 11px; }
.score-details summary { cursor: pointer; font-size: 0.74rem; font-weight: 760; }
.score-details > p { color: var(--muted); font-size: 0.68rem; margin: 8px 0 0; }
.score-row { align-items: center; border-top: 1px solid var(--line); display: grid; font-size: 0.72rem; gap: 8px; grid-template-columns: minmax(0, 1fr) 38px 38px; padding: 7px 0; }
.score-row:first-child { margin-top: 8px; }
.score-row strong { text-align: center; }
.score-row-head { border-top: 0; color: var(--muted); font-size: 0.65rem; padding-bottom: 3px; }

.tabs { border-bottom: 1px solid var(--line); display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-size: 0.78rem; font-weight: 760; padding: 9px 10px; white-space: nowrap; }
.tab.active { border-bottom-color: var(--ochre); color: var(--ink); }
.tab-panel { min-height: 520px; }
#finalText { font-family: Georgia, serif; font-size: 1rem; height: 510px; width: 100%; }
.result-actions { align-items: center; color: var(--muted); display: flex; font-size: 0.74rem; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.result-actions span { margin-right: auto; }
.comparison-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.comparison-grid h4, #diagnosticContent h4, #sourcesContent h4 { font-family: Georgia, serif; font-weight: 500; margin: 0 0 8px; }
.comparison-heading { align-items: center; display: flex; justify-content: space-between; }
.comparison-heading span { background: var(--green-soft); border-radius: 999px; color: var(--green-dark); font-size: 0.72rem; font-weight: 800; padding: 4px 8px; }
.prose-box { background: white; border: 1px solid var(--line); border-radius: 12px; font-family: Georgia, serif; font-size: 0.88rem; height: 500px; overflow: auto; padding: 14px; white-space: pre-wrap; }
.diagnostic-section { border-bottom: 1px solid var(--line); padding: 15px 0; }
.diagnostic-section:first-child { padding-top: 0; }
.diagnostic-section p { color: var(--muted); font-size: 0.84rem; }
.diagnostic-section ul { margin: 8px 0 0; padding-left: 20px; }
.diagnostic-section li { font-size: 0.82rem; margin-bottom: 7px; }
.source-list { display: grid; gap: 10px; }
.source-card { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.source-card a { color: var(--green); font-size: 0.82rem; font-weight: 720; overflow-wrap: anywhere; }
.source-card p { color: var(--muted); font-size: 0.75rem; margin: 5px 0 0; }

footer { border-top: 1px solid rgba(20, 37, 31, 0.10); color: var(--muted); display: flex; font-size: 0.72rem; justify-content: space-between; margin: 0 clamp(20px, 4vw, 64px); padding: 20px 0 30px; }

.login-page {
  background: radial-gradient(circle at 15% 15%, rgba(185, 112, 79, 0.2), transparent 32rem), linear-gradient(135deg, #172520 0%, #253a31 48%, #f4f0e8 48%, #faf8f3 100%);
  min-height: 100vh;
}
.login-shell { align-items: stretch; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 520px); min-height: 100vh; padding: clamp(24px, 5vw, 72px); }
.login-brand { color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(10px, 4vw, 52px); }
.login-logo h1, .login-brand .eyebrow { color: #fff; }
.login-message { max-width: 600px; }
.login-message h2 { color: #fff; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.8rem, 6vw, 5.8rem); font-weight: 400; letter-spacing: -0.05em; line-height: 0.95; margin: 16px 0 24px; }
.login-message > p:last-child { color: rgba(255, 255, 255, 0.76); font-size: 1.05rem; line-height: 1.7; max-width: 540px; }
.login-footnote { color: rgba(255, 255, 255, 0.58); font-size: 0.82rem; }
.login-card { align-self: center; border: 0; box-shadow: 0 30px 80px rgba(12, 24, 19, 0.2); display: grid; gap: 28px; padding: clamp(28px, 5vw, 56px); }
.login-card h2 { font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3.2rem); font-weight: 400; margin: 8px 0 10px; }
.login-card form { display: grid; gap: 18px; }
.login-card .primary-button { margin-top: 8px; width: 100%; }
.login-error { background: #fff1ef; border: 1px solid #e7b3aa; border-radius: 10px; color: #8d2f20; font-size: 0.9rem; margin: 0; padding: 12px 14px; }
.privacy-line { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; margin: 0; padding-top: 18px; }

@media (max-width: 860px) {
  .login-page { background: linear-gradient(180deg, #172520 0%, #253a31 40%, #f4f0e8 40%, #faf8f3 100%); }
  .login-shell { grid-template-columns: 1fr; padding: 22px; }
  .login-brand { gap: 42px; padding: 10px 4px 46px; }
  .login-footnote { display: none; }
  .topbar-actions { align-items: flex-end; flex-direction: column; }
}

@media (max-width: 1000px) {
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .workspace-grid { grid-template-columns: 1fr; }
  .editor-card, .result-card { min-height: auto; }
}

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .skill-state { font-size: 0; padding: 9px; }
  main { padding-top: 26px; }
  .hero { align-items: flex-start; flex-direction: column; }
  .intent-card, .editor-card, .result-card { border-radius: 17px; padding: 18px; }
  .settings-grid, .settings-grid-two { grid-template-columns: 1fr; }
  .length-control { grid-template-columns: minmax(0, 1fr) 120px; }
  .switch-row { align-items: flex-start; flex-direction: column; gap: 16px; }
  .segmented-control { display: grid; grid-template-columns: 1fr 1fr 1fr; width: 100%; }
  .segmented-control span { font-size: 0.72rem; padding: 9px 6px; text-align: center; }
  .comparison-grid { grid-template-columns: 1fr; }
  .score-board { grid-template-columns: 1fr; }
  .score-progress { flex-direction: row; gap: 8px; min-height: 30px; }
  footer { flex-direction: column; gap: 5px; }
  .skill-state { display: none; }
  .logout-button { font-size: 0.75rem; padding: 8px 10px; }
}
