:root {
  --bg: #faf9f7;
  --ink: #1a1918;
  --muted: #777673;
  --accent: #c4501a;
  --border: #e0deda;
  --card: #ffffff;
  --paper: #fdfbf9;
  --error: #b3261e;
  --g: #4f8d3d;
  --c: #7d5260;
  --s: #3a6ea5;
  --a: #b3541e;
}
html[data-theme="dark"] {
  --bg: #0f0e0d;
  --ink: #e8e6e3;
  --muted: #9a9997;
  --border: #272422;
  --card: #1c1b19;
  --paper: #1c1b19;
}
html[data-theme="dark"] mark.g { background: #1e2a1c; border-bottom-color: #2a4a24; }
html[data-theme="dark"] mark.c { background: #2a1e22; }
html[data-theme="dark"] mark.s { background: #1a242f; }
html[data-theme="dark"] mark.a { background: #2a2214; }
html[data-theme="dark"] #history-list li:hover { background: rgba(255,255,255,0.04); }
html[data-theme="dark"] .logo-link img { filter: invert(0.88) brightness(1.1); }
[hidden] { display: none !important; }
* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; overflow-x: hidden; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(at 20% 0%, rgba(196,80,26,0.06) 0px, transparent 60%);
  color: var(--ink); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow-x: hidden; max-width: 100vw;
}
html[data-theme="dark"] body {
  background-image: radial-gradient(at 20% 0%, rgba(196,80,26,0.04) 0px, transparent 60%);
}

/* theme toggle */
.theme-toggle { background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px; cursor: pointer; color: var(--muted); font: inherit; font-size: 0.9em; line-height: 1; transition: all .18s; }
.theme-toggle:hover { color: var(--ink); border-color: var(--ink); transform: translateY(-1px); }

/* skip */
.skip-link { position: absolute; top: -100%; left: 16px; background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 0 0 10px 10px; font-size: 0.88em; font-weight: 650; z-index: 100; text-decoration: none; transition: top 0.15s; }
.skip-link:focus { top: 0; }

/* mobile menu toggle */
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; z-index: 20; }
.menu-toggle span { display: block; width: 20px; height: 2px; background: var(--ink); margin: 4px 0; transition: transform 0.2s, opacity 0.2s; }
.menu-toggle.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* login — centered paper */
.login-wrap { max-width: 480px; min-height: 100dvh; display: grid; place-items: center; margin: 0 auto; padding: 24px; }
.login-box {
  text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  padding: 36px 28px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.06), 0 1px 0 var(--border);
}
.login-box h1 { font-family: Georgia, serif; font-size: 2rem; margin: 0 0 8px; letter-spacing: -0.03em; }
.login-tagline { color: var(--muted); font-size: 1.02em; margin: 0 0 24px; line-height: 1.5; }
.login-features { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin-bottom: 26px; }
.login-feature { font-size: 0.84em; color: var(--muted); display: flex; align-items: center; gap: 7px; background: var(--card); background: color-mix(in srgb, var(--bg) 70%, var(--card)); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; }
.login-feat-dot { width: 7px; height: 7px; border-radius: 50%; }
.login-feat-dot.g { background: var(--g); }
.login-feat-dot.c { background: var(--c); }
.login-feat-dot.s { background: var(--s); }
.login-feat-dot.a { background: var(--a); }
.login-note { font-size: 0.82em; color: var(--muted); margin-top: 16px; }
.btn-dark {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 24px; background: var(--ink); color: var(--bg); border: 1px solid var(--ink);
  border-radius: 999px; font: inherit; font-weight: 650; cursor: pointer; transition: all .18s;
}
.btn-dark:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.btn-dark:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
.error { color: var(--error); margin-top: 12px; font-size: 0.9em; }

/* spinner */
.loading-spinner { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 0.9em; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* copy */
.copy-btn { position: absolute; top: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 0.8em; color: var(--muted); cursor: pointer; transition: all .15s; }
.copy-btn:hover { color: var(--ink); border-color: var(--ink); }
.section-label { position: relative; font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 32px 0 14px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* top bar — blur */
.top-bar {
  display: flex; align-items: center; gap: 14px; padding: 14px 32px;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.logo-link { display: flex; align-items: center; text-decoration: none; }
.nav-tabs { display: flex; gap: 4px; background: color-mix(in srgb, var(--bg) 70%, var(--card)); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.nav-tab { background: transparent; border: none; border-radius: 999px; color: var(--muted); padding: 7px 16px; font: inherit; font-size: 0.86em; font-weight: 600; cursor: pointer; transition: all .15s; }
.nav-tab:hover { color: var(--ink); }
.nav-tab.active { background: var(--ink); color: var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.spacer { flex: 1; }
.email-tag { font-size: 0.82em; color: var(--muted); font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: none; border: 1px solid var(--border); color: var(--muted); font: inherit; font-size: 0.84em; cursor: pointer; padding: 7px 14px; border-radius: 999px; transition: all .15s; }
.link-btn:hover { color: var(--ink); border-color: var(--ink); }
.btn-pro { font-size: 0.82em; font-weight: 700; padding: 8px 16px; background: var(--ink); color: var(--bg); border: 1px solid var(--ink); border-radius: 999px; cursor: pointer; transition: all .15s; }
.btn-pro:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,.12); }

/* main */
main { max-width: 980px; margin: 0 auto; padding: 36px 24px 80px; }
h2 { font-family: Georgia, serif; font-size: 1.55em; margin: 0 0 6px; font-weight: 800; letter-spacing: -0.025em; }
.muted { color: var(--muted); font-size: 0.9em; }
hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* editor — paper desk */
.editor-section { margin-bottom: 28px; }
.editor-section h2 { margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.editor-section h2::before { content: "✎"; font-size: 0.9em; opacity: .4; }
.editor-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.editor-layout .editor-section { min-width: 0; }
.ad-slot { min-height: 250px; border: 1px dashed var(--border); border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 0.8em; background: color-mix(in srgb, var(--bg) 50%, transparent); }
textarea {
  width: 100%; padding: 18px 20px; border: 1px solid var(--border); border-radius: 12px;
  font: inherit; font-size: 1em; background: var(--paper); color: var(--ink);
  resize: none; overflow: hidden; line-height: 1.7;
  box-shadow: 0 1px 0 var(--border), 0 12px 32px rgba(0,0,0,.04);
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 1px 0 var(--ink), 0 16px 40px rgba(0,0,0,.06); }
#title { margin-bottom: 14px; min-height: 52px; font-family: Georgia, serif; font-size: 1.12em; font-weight: 700; letter-spacing: -0.015em; }
#content { min-height: 260px; font-size: 1.02em; }
.editor-foot { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.editor-foot .muted { flex: 1; }
.word-count { font-size: 0.82em; text-align: right; flex: none !important; background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; color: var(--muted); font-weight: 600; }
.usage-line { margin-top: 12px; font-size: 0.86em; background: var(--card); background: color-mix(in srgb, var(--accent) 6%, var(--card)); border: 1px solid var(--border); border-color: color-mix(in srgb, var(--accent) 15%, var(--border)); border-radius: 999px; padding: 8px 14px; display: inline-flex; width: fit-content; }
.upgrade-bar { margin-top: 16px; border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; background: var(--card); display: flex; align-items: center; gap: 16px; flex-wrap: wrap; box-shadow: 0 8px 24px rgba(0,0,0,.04); }
.upgrade-bar strong { display: block; font-size: 0.98em; letter-spacing: -0.01em; }
.upgrade-bar p { margin: 4px 0 0; }
.upgrade-note { flex-basis: 100%; font-size: 0.85em; }
#paypal-button { min-width: 200px; }

/* report — newspaper column */
.report-section { margin-top: 8px; max-width: 760px; }
.report-title { font-family: Georgia, serif; font-size: 1.9em; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.03em; line-height: 1.1; }
.report-author { margin: 0 0 22px; font-size: 0.88em; }
.section-label { margin-top: 32px; }

/* metrics — pill segmented, wraps to 16px radius */
.metrics-row {
  display: flex; gap: 0; flex-wrap: wrap; margin: 16px 0;
  border: 1px solid var(--border); border-radius: 16px; overflow: hidden; background: var(--card);
}
@media (min-width: 640px) {
  .metrics-row { border-radius: 999px; }
}
.metric { flex: 1 1 0; min-width: 90px; text-align: center; padding: 14px 8px; }
.metric:not(:last-child) { border-right: 1px solid var(--border); }
.metric-val { display: block; font-size: 1.18em; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; }
.metric-label { display: block; font-size: 0.68em; margin-top: 3px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; }

/* score + issues */
.score-issues-row { display: grid; grid-template-columns: 160px 1fr; gap: 36px; align-items: start; }
.score-col { text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 20px 16px; }
.score-col h3 { margin: 0 0 14px; font-size: 0.82em; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.score-badge { width: 110px; height: 110px; border-radius: 50%; background: conic-gradient(var(--ring, var(--ink)) calc(var(--pct, 0) * 1%), var(--border) 0); display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; margin: 0 auto; }
.score-badge::before { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--card); }
.score-badge span, .score-badge small { position: relative; z-index: 1; }
.score-badge span { font-size: 2em; font-weight: 800; line-height: 1; color: var(--ink); letter-spacing: -0.03em; }
.score-badge small { font-size: 0.7em; color: var(--muted); font-weight: 600; }
.score-note { font-size: 0.82em; margin-top: 12px; line-height: 1.5; }
.issues-col { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 20px; }
.issues-col h3 { margin: 0 0 14px; font-size: 0.82em; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.issues-summary { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; }
.issues-big { font-size: 1.8em; font-weight: 800; letter-spacing: -0.02em; }
.issues-big.critical { color: var(--error); }
.issues-big.advanced { color: var(--accent); }
.issues-summary .muted { font-size: 0.82em; }

/* issues breakdown */
.issue-group { margin: 14px 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.issue-group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.issue-count { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 999px; color: #fff; font-size: 0.8em; font-weight: 800; }
.issue-item { display: flex; align-items: center; gap: 12px; padding: 8px 0 8px 38px; font-size: 0.9em; border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.issue-item:first-of-type { border-top: none; }
.issue-item span { flex: 1; }
.issue-bar { width: 100px; height: 6px; background: var(--border); background: color-mix(in srgb, var(--border) 70%, transparent); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.issue-bar > div { height: 100%; background: var(--error); border-radius: 999px; transition: width 0.5s ease; }

/* annotated essay — paper */
#annotated { white-space: pre-wrap; line-height: 1.85; border: 1px solid var(--border); border-radius: 12px; padding: 24px; background: var(--paper); font-size: 0.98em; box-shadow: 0 1px 0 var(--border); }
mark { border-radius: 4px; padding: 2px 4px; position: relative; border-bottom: 2px solid transparent; }
mark::after { content: attr(data-num); position: absolute; top: -9px; right: -6px; font-size: 0.6em; font-weight: 800; line-height: 1; width: 16px; height: 16px; border-radius: 999px; display: grid; place-items: center; font-family: system-ui, sans-serif; }
mark.g { background: #e8f0e2; border-bottom-color: #4f8d3d30; } mark.g::after { background: var(--g); color: #fff; }
mark.c { background: #f0e4e8; border-bottom-color: #7d526030; } mark.c::after { color: #fff; background: var(--c); }
mark.s { background: #e4ebf5; border-bottom-color: #3a6ea530; } mark.s::after { color: #fff; background: var(--s); }
mark.a { background: #fbeadc; border-bottom-color: #b3541e30; } mark.a::after { color: #fff; background: var(--a); }

/* annotation table */
.anno-row { display: grid; grid-template-columns: 32px 1fr 1fr 110px; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); align-items: start; font-size: 0.9em; }
.anno-row:last-child { border-bottom: none; }
.anno-num { width: 26px; height: 26px; border-radius: 999px; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: 0.78em; font-weight: 800; }
.anno-quote { font-family: Georgia, serif; font-style: italic; color: var(--ink); background: var(--card); background: color-mix(in srgb, var(--bg) 60%, var(--card)); border-radius: 8px; padding: 8px 10px; border: 1px solid var(--border); }
.anno-type { color: var(--ink); line-height: 1.5; }
.anno-cat { text-align: right; font-weight: 700; color: var(--muted); font-size: 0.84em; text-transform: uppercase; letter-spacing: 0.06em; }

/* history — paper rows */
.history-section { border-top: 1px solid var(--border); padding-top: 32px; margin-top: 8px; }
.history-section h2 { margin-bottom: 6px; }
#history-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
#history-list li {
  cursor: pointer; padding: 16px 14px; border: 1px solid var(--border); border-radius: 12px;
  display: flex; gap: 12px; align-items: center; background: var(--card);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s;
}
#history-list li:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,.06); border-color: var(--ink); }
#history-list li:last-child { border-bottom: 1px solid var(--border); }
#history-list .del { margin-left: auto; background: var(--bg); border: 1px solid var(--border); color: var(--muted); font: inherit; font-size: 0.84em; cursor: pointer; padding: 6px 12px; border-radius: 999px; transition: all .15s; }
#history-list .del:hover { color: var(--error); border-color: var(--error); background: #fff; }

/* responsive */
@media (max-width: 880px) {
  .editor-layout { grid-template-columns: 1fr; }
  .ad-slot { min-height: 120px; }
  .score-issues-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top-bar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .nav-tabs { gap: 0; }
  .nav-tab { padding: 7px 12px; font-size: 0.82em; }
  .email-tag { display: none; }
  .btn-pro { font-size: 0.78em; padding: 7px 12px; }
  .link-btn { font-size: 0.8em; padding: 6px 10px; }
  main { padding: 20px 14px 60px; }
  h2 { font-size: 1.3em; }
  textarea { font-size: 0.95em; padding: 16px; }
  .editor-foot { flex-wrap: wrap; gap: 10px; }
  .editor-foot .muted { flex-basis: 100%; }
  .word-count { flex-basis: 100%; text-align: left; }
  .upgrade-bar { flex-direction: column; align-items: stretch; text-align: center; }
  #paypal-button { min-width: 100%; }
  .score-badge { width: 90px; height: 90px; }
  .score-badge span { font-size: 1.6em; }
  .issues-summary { gap: 12px; }
  .issues-big { font-size: 1.5em; }
  .issue-bar { width: 60px; }
  .anno-row { grid-template-columns: 28px 1fr; gap: 10px; font-size: 0.85em; }
  .anno-cat { display: none; }
  .anno-quote { font-size: 0.9em; }
  #annotated { padding: 18px; font-size: 0.95em; }
  .metrics-row { border-radius: 12px; }
  .metric { min-width: 70px; padding: 12px 6px; }
  .metric-val { font-size: 1.05em; }
  .metric-label { font-size: 0.68em; }
  #history-list li { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
  #history-list .del { margin-left: 0; align-self: flex-end; }
  .menu-toggle { display: block; }
  .nav-tabs, .spacer, .btn-pro, .email-tag, .link-btn, .theme-toggle { display: none !important; }
  .mobile-menu { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border-bottom: 1px solid var(--border); padding: 12px 16px; z-index: 15; }
  .mobile-menu:not([hidden]) { display: flex; flex-direction: column; gap: 4px; }
  .mobile-menu .nav-tab { padding: 10px 0; text-align: left; border-bottom: none; border-radius: 0; }
  .mobile-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
  .mobile-menu .link-btn { text-align: left; padding: 10px 0; border: none; }
  .mobile-menu .btn-pro { text-align: left; padding: 10px 0; }
  .mobile-menu .theme-toggle { display: inline-flex !important; }
  .copy-btn { position: static; margin-top: 10px; }
}

/* print */
@media print {
  .top-bar, .menu-toggle, .mobile-menu, .skip-link, .ad-slot, .editor-section, .editor-foot, .usage-line, .upgrade-bar, .copy-btn, .btn-dark, .btn-pro, .link-btn, #logout, #go-pro { display: none !important; }
  body { background: #fff; }
  main { max-width: 100%; padding: 0; }
  #feedback { display: block !important; }
  .report-section { margin-top: 0; }
  #annotated { border: 1px solid #ccc; background: #fff; }
  .score-badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .anno-row { break-inside: avoid; }
  .issue-group { break-inside: avoid; }
  mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
