/* ============ Writing assistant (local, Grammarly-style) ============ */
:root {
  --c-spelling: #d93a49;
  --c-grammar: #d93a49;
  --c-clarity: #2f6fdb;
  --c-style: #1f9d6b;
  --c-ai: #8a4fd6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --c-spelling: #ff6b78; --c-grammar: #ff6b78; --c-clarity: #6ea2ff; --c-style: #45c991; --c-ai: #b78cff; }
}
:root[data-theme="dark"] { --c-spelling: #ff6b78; --c-grammar: #ff6b78; --c-clarity: #6ea2ff; --c-style: #45c991; --c-ai: #b78cff; }

.c-spelling { --c: var(--c-spelling); }
.c-grammar { --c: var(--c-grammar); }
.c-clarity { --c: var(--c-clarity); }
.c-style { --c: var(--c-style); }
.c-ai { --c: var(--c-ai); }

/* Underline layer sits exactly behind the transparent textarea and mirrors its text. */
.ed-area { position: relative; flex: 1; min-height: 0; display: flex; }
.ed-area #story { position: relative; z-index: 1; }
.hl-layer { position: absolute; z-index: 0; overflow: hidden; pointer-events: none; }
.hl-layer[hidden] { display: none; }
#hlText {
  color: transparent; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  margin: 0; border: 0; box-sizing: border-box; width: 100%; will-change: transform;
}
#hlText mark { color: transparent; background: transparent; border-radius: 2px; border-bottom: 2px solid var(--c); transition: background .15s; }
#hlText mark.u-spelling { --c: var(--c-spelling); }
#hlText mark.u-grammar { --c: var(--c-grammar); }
#hlText mark.u-clarity { --c: var(--c-clarity); }
#hlText mark.u-style { --c: var(--c-style); }
#hlText mark.u-ai { --c: var(--c-ai); border-bottom-style: dashed; }
#hlText mark.active { background: color-mix(in srgb, var(--c) 18%, transparent); }
#hlText mark.fresh { animation: mark-in .35s var(--ease-out, ease-out) both; }
@keyframes mark-in { from { border-bottom-color: transparent; } }
.hl-layer.stale #hlText mark { border-bottom-color: transparent; transition: border-color .2s; }
@media (prefers-reduced-motion: reduce) { #hlText mark.fresh { animation: none; } }

/* Suggestion card */
.chk-card {
  position: fixed; z-index: 40; width: 300px; display: flex; flex-direction: column; gap: 6px; padding: 14px 16px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--c, var(--accent));
  border-radius: 10px; box-shadow: var(--shadow);
}
.chk-card[hidden] { display: none; }
.cc-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.cc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.cc-title { font-weight: 700; font-size: 15px; }
.cc-msg { margin: 0; font-size: 13.5px; color: var(--text-2); }
.cc-reps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.cc-rep {
  border: 0; border-radius: 6px; padding: 6px 12px; font-weight: 700; font-size: 14px;
  background: var(--c); color: #fff;
}
.cc-rep:hover { filter: brightness(1.1); }
.cc-foot { display: flex; gap: 4px; margin: 4px -8px -6px; }
.cc-foot .text-btn { font-size: 13px; }

/* Floating badge */
.chk-badge {
  position: absolute; right: 30px; bottom: 124px; z-index: 5; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--c, #2e9e5b); color: #fff; font-weight: 800; font-size: 15px; box-shadow: var(--shadow);
  transition: transform .15s;
}
.chk-badge.clean { --c: #2e9e5b; }
.chk-badge:hover { transform: scale(1.06); }
.chk-badge[hidden] { display: none; }

/* Review panel */
.chk-panel {
  position: absolute; right: 24px; bottom: 178px; z-index: 6; width: min(360px, calc(100% - 32px)); max-height: min(560px, 62vh);
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.chk-panel[hidden] { display: none; }
.cp-head { display: flex; align-items: center; gap: 12px; padding: 14px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.cp-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.cp-title strong { font-size: 15px; }
.score-ring {
  --p: 100; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(#2e9e5b calc(var(--p) * 1%), var(--panel-2) 0);
}
.score-ring span { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-weight: 800; font-size: 14px; }
.cp-chips { padding: 10px 16px 4px; }
.cp-chips .chip { font-size: 12px; padding: 3px 10px; }
.cp-chips .chip.added { color: var(--c, var(--accent)); }
.cp-list { flex: 1; min-height: 60px; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.chk-item { display: flex; align-items: flex-start; gap: 10px; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); }
.chk-item:hover { background: var(--panel-2); }
.chk-item .cc-dot { margin-top: 6px; }
.ci-main { display: flex; flex-direction: column; min-width: 0; }
.ci-main strong { font-size: 13.5px; }
.ci-ctx { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chk-empty { padding: 12px 8px; margin: 0; }
.cp-foot { display: flex; flex-direction: column; gap: 6px; padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.cp-foot p { margin: 0; }

@media (max-width: 900px) {
  .chk-badge { position: fixed; right: 16px; bottom: 80px; }
  .chk-panel { position: fixed; right: 16px; bottom: 132px; }
}
