:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f1b16;
  --text-muted: #6b6355;
  --border: #e3dcd0;
  --accent: #7a3b2e;
  --accent-hover: #642f25;
  --accent-contrast: #fffaf5;
  --strength: #2f6b4f;
  --improve: #a6631f;
  --error-bg: #fbeae7;
  --error-text: #8a2e1f;
  --error-border: #edb9ac;
  --focus-ring: #b98d6f;
  --radius: 10px;
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #211d17;
    --text: #efe9df;
    --text-muted: #a89e8c;
    --border: #3a342a;
    --accent: #d99a7d;
    --accent-hover: #e5ac92;
    --accent-contrast: #1a1310;
    --strength: #7fc9a3;
    --improve: #e0a54f;
    --error-bg: #3a1f19;
    --error-text: #f0b6a6;
    --error-border: #5c2e24;
    --focus-ring: #d99a7d;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  text-align: center;
  margin-bottom: 40px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-muted);
  margin-bottom: 28px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.brand:hover,
.brand:focus-visible {
  color: var(--text);
  background-color: var(--surface);
}

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

.brand-logo {
  width: 28px;
  height: 28px;
  display: block;
}

.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.site-header h1 {
  font-family: var(--serif);
  font-size: 2.25rem;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 46ch;
  margin: 0 auto;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}

textarea#essay-input {
  width: 100%;
  min-height: 340px;
  resize: vertical;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.65;
  padding: 20px;
  outline: none;
}

textarea#essay-input::placeholder {
  color: var(--text-muted);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 14px;
  gap: 16px;
}

.char-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.char-count.near-limit {
  color: var(--improve);
}

.char-count.at-limit {
  color: var(--error-text);
}

button#submit-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 24px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

button#submit-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

button#submit-btn:active:not(:disabled) {
  transform: scale(0.98);
}

button#submit-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button#submit-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.status {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.status.loading {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.status.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.results {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  user-select: none;
  -webkit-user-select: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
}

.card h3 {
  font-family: var(--serif);
  font-size: 1.15rem;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.impression-card h3::before { content: "◆"; color: var(--accent); font-size: 0.75em; }
.strengths-card h3::before { content: "✓"; color: var(--strength); }
.improvements-card h3::before { content: "→"; color: var(--improve); }
.grammar-card h3::before { content: "¶"; color: var(--accent); }
.spelling-card h3::before { content: "abc"; color: var(--accent); font-size: 0.7em; letter-spacing: 0.05em; }

#overall-impression {
  margin: 0;
  color: var(--text);
  line-height: 1.65;
}

.card ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card ul li {
  padding-left: 22px;
  position: relative;
  line-height: 1.55;
}

.strengths-card li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--strength);
  font-weight: 700;
}

.improvements-card li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--improve);
  font-weight: 700;
}

.grammar-card li::before,
.spelling-card li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

.card ul li.empty {
  color: var(--text-muted);
  font-style: italic;
}

.card ul li.empty::before {
  content: none;
}

.site-footer {
  margin-top: 56px;
  text-align: center;
}

.site-footer p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 6px;
}

.site-footer p:last-child {
  margin-bottom: 0;
}

.copy-note {
  font-size: 0.78rem;
  opacity: 0.8;
}

@media (max-width: 520px) {
  .page { padding: 32px 16px 60px; }
  .site-header h1 { font-size: 1.8rem; }
  .composer-footer { flex-direction: column; align-items: stretch; }
  button#submit-btn { width: 100%; }
}
