:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #e5e1d7;
  --paper: #efebe1;
  --editor-surface: #f7f4ec;
  --text: #3f3d37;
  --muted: #6d6960;
  --border: #d6d0c4;
  --editor-border: #cec7ba;
  --accent: #536b58;
  --soft: #e1ded4;
  --warning: #a36825;
  --error: #b74444;
  --selection: #d8dfd2;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #20211d;
  --paper: #252620;
  --editor-surface: #2b2c26;
  --text: #d6d3c9;
  --muted: #aaa79e;
  --border: #3a3b34;
  --editor-border: #46473f;
  --accent: #a8bea9;
  --soft: #3b3d35;
  --warning: #d1a160;
  --error: #e18b8b;
  --selection: #445247;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
    --bg: #20211d;
    --paper: #252620;
    --editor-surface: #2b2c26;
    --text: #d6d3c9;
    --muted: #aaa79e;
    --border: #3a3b34;
    --editor-border: #46473f;
    --accent: #a8bea9;
    --soft: #3b3d35;
    --warning: #d1a160;
    --error: #e18b8b;
    --selection: #445247;
  }
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
  overflow-anchor: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

button:hover {
  background: var(--soft);
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 1040px;
  margin: 28px auto 0;
  overflow: clip;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -.5px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#btn-issue {
  color: var(--accent);
}

.check-group p,
.privacy-note {
  color: var(--muted);
  font-size: 12px;
}

.theme-switch {
  display: flex;
  flex-shrink: 0;
  gap: 4px;
  margin-left: auto;
}

.theme-switch {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.theme-switch button[aria-pressed="true"],
.check-btn.active {
  background: var(--soft);
  color: var(--accent);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 28px;
  padding: 16px 28px;
}

.check-buttons {
  display: flex;
  gap: 4px;
}

.check-group p {
  margin: 6px 0 0;
  padding: 0 12px;
}

main {
  width: 100%;
  max-width: 800px;
  margin: 22px auto 0;
  padding: 0 30px 32px;
}

.document-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.editor-wrapper {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow: visible;
  background: var(--editor-surface);
  border: 1px solid var(--editor-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(50 45 35 / 4%), inset 0 1px 0 rgb(255 255 255 / 18%);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.editor-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

#editor,
#overlay,
#editor-measure {
  width: 100%;
  margin: 0;
  padding: 26px clamp(22px, 4vw, 36px);
  box-sizing: border-box;
  font-family: Verdana, "Segoe UI", Arial, sans-serif;
  font-size: 18px;
  font-weight: 400;
  font-kerning: normal;
  line-height: 1.7;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

#editor {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  resize: none;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  caret-color: var(--text);
}

#editor-measure {
  position: relative;
  width: 100%;
  min-height: 440px;
  height: auto;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  border: 0;
}

#editor::placeholder {
  color: var(--muted);
  opacity: .8;
}

#editor::selection {
  background: var(--selection);
  color: var(--text);
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
  background: transparent;
  color: transparent;
}

.highlight-active #overlay {
  visibility: visible;
}

#overlay mark {
  padding: 0;
  background: transparent;
  color: transparent;
  font: inherit;
  text-decoration: underline wavy var(--warning);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}

#overlay mark:is([data-cat="spelling"], [data-cat="grammar"], [data-cat="style"]) {
  text-decoration-color: var(--error);
}

#overlay mark.current-issue {
  background: var(--selection);
  border-radius: 2px;
}

.issue-detail {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 24px;
  padding: 16px;
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.issue-body,
#issue-content {
  flex: 1;
  min-width: 0;
}

#issue-content {
  cursor: pointer;
  border-radius: 4px;
}

#issue-content:focus-visible {
  outline-offset: 6px;
}

#close-issue {
  padding: 0 8px;
  font-size: 20px;
}

.editor-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  min-height: 61px;
  padding: 10px 28px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#spellingStatus {
  flex: 1;
  min-width: 180px;
}

#save-status[data-failed="true"] {
  color: var(--error);
}

.privacy-note {
  max-width: 1040px;
  margin: 12px auto 24px;
  padding: 0 12px;
}

.privacy-note a {
  color: inherit;
}

.custom-tooltip {
  position: fixed;
  z-index: 100;
  max-width: min(360px, calc(100vw - 24px));
  pointer-events: none;
  visibility: hidden;
}

.custom-tooltip.visible {
  visibility: visible;
}

.selection-tooltip {
  position: fixed;
  z-index: 110;
  max-width: calc(100vw - 24px);
  padding: 7px 10px;
  pointer-events: none;
  background: var(--text);
  color: var(--editor-surface);
  border-radius: 6px;
  box-shadow: 0 3px 12px #0003;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.custom-tooltip-content {
  padding: 14px 16px;
  overflow-wrap: anywhere;
  background: var(--editor-surface);
  color: var(--text);
  border: 1px solid var(--editor-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px #0002;
  font-size: 14px;
}

.tt-category {
  color: var(--accent);
  font-size: 12px;
}

.tt-word {
  margin: 5px 0;
  font-weight: 600;
}

.tt-hint,
.tt-repl-label {
  color: var(--muted);
}

.tt-replacements {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.tt-repl-label {
  margin-bottom: 5px;
  font-size: 12px;
}

.tt-repl-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tt-repl-item {
  padding: 2px 7px;
  background: var(--soft);
  border-radius: 4px;
}

.tt-repl-item.remove {
  color: var(--error);
}

@media (max-width: 700px) {
  .app {
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .app-header {
    gap: 12px;
    padding: 16px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand p {
    font-size: 11px;
  }

  .editor-toolbar {
    gap: 16px 8px;
    padding: 14px 8px;
  }

  .check-group:last-child {
    flex-basis: 100%;
  }

  main {
    max-width: none;
    margin-top: 10px;
    padding: 0 12px 20px;
  }

  .editor-wrapper {
    border-radius: 8px;
  }

  #editor,
  #overlay,
  #editor-measure {
    padding: 20px 18px;
    font-size: 17px;
    line-height: 1.7;
  }

  #editor-measure {
    min-height: 420px;
  }

  .editor-footer {
    gap: 8px 16px;
    padding: 12px 16px;
  }

  #spellingStatus {
    min-width: 150px;
  }

  .privacy-note {
    padding: 0 16px;
  }
}

@media (pointer: coarse) {
  button {
    min-height: 44px;
  }

  .check-buttons {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}