:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c2033;
  --muted: #6b7189;
  --line: #e4e7f0;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 4px 16px rgba(20, 24, 50, .05);
}
.dark {
  --bg: #0f1220;
  --card: #181c2e;
  --text: #e8eaf4;
  --muted: #9aa0ba;
  --line: #2a2f47;
  --accent: #8b85ff;
  --accent-soft: #24264a;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; }
.icon-btn { border: 1px solid var(--line); background: transparent; color: var(--text); width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; cursor: pointer; }

.hero { text-align: center; padding: 36px 0 24px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(1.7rem, 4vw, 2.4rem); }
.hero p { margin: 0; color: var(--muted); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2 { font-size: 1rem; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.sidebar { display: grid; gap: 20px; }

.quick-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.quick-stats div { background: var(--accent-soft); border-radius: 10px; padding: 12px; text-align: center; }
.quick-stats strong { display: block; font-size: 1.6rem; color: var(--accent); line-height: 1.2; }
.quick-stats span { font-size: .8rem; color: var(--muted); }
@media (max-width: 520px) { .quick-stats { grid-template-columns: repeat(2, 1fr); } }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.group { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar button, .seg button {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 11px; border-radius: 8px; font-size: .85rem; cursor: pointer;
}
.toolbar button:hover:not(:disabled), .seg button:hover { border-color: var(--accent); color: var(--accent); }
.toolbar button:disabled { opacity: .45; cursor: default; }
.toolbar .danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- Word-style ribbon ---------- */
.ribbon {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px; margin-bottom: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  position: sticky; top: 0; z-index: 5;
}
.rgroup { display: flex; align-items: center; gap: 2px; padding-right: 6px; border-right: 1px solid var(--line); }
.rgroup:last-child { border-right: 0; }
.ribbon button {
  min-width: 32px; height: 32px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 7px;
  background: transparent; color: var(--text); font-size: .95rem; cursor: pointer;
}
.ribbon button:hover:not(:disabled) { background: var(--card); border-color: var(--line); }
.ribbon button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ribbon button:disabled { opacity: .35; cursor: default; }
.ribbon svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; fill: none; }
.ribbon svg circle { fill: currentColor; stroke: none; }
.ribbon small { font-size: .65rem; margin-top: 6px; }
.ribbon select {
  height: 32px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--card); color: var(--text); font-size: .85rem; padding: 0 6px; cursor: pointer;
}
#fontSelect { width: 150px; }
#blockSelect { width: 104px; }
#sizeSelect { width: 62px; }
.color-btn {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 34px; height: 32px; border-radius: 7px; cursor: pointer;
}
.color-btn:hover { background: var(--card); }
.color-a { font-weight: 700; line-height: 1; }
.color-a.hl { font-size: .8rem; }
.swatch { width: 18px; height: 4px; border-radius: 2px; margin-top: 3px; }
.color-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

/* ---------- The "page" (like a Word sheet) ---------- */
.page {
  min-height: 460px; max-height: 75vh; overflow-y: auto;
  padding: 28px 34px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: #1a1a1a; outline: none;
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 12pt; line-height: 1.6;
  word-wrap: break-word; position: relative;
}
.page:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.page.is-empty::before { content: attr(data-placeholder); color: #9aa0b0; pointer-events: none; position: absolute; }
.page > :first-child { margin-top: 0; }
.page p { margin: 0 0 .6em; }
.page h1 { font-size: 22pt; margin: .4em 0 .3em; }
.page h2 { font-size: 17pt; margin: .4em 0 .3em; }
.page h3 { font-size: 14pt; margin: .4em 0 .3em; }
.page blockquote { margin: .6em 0; padding: 4px 14px; border-left: 4px solid #c7cbe0; color: #444; }
.page pre { background: #f3f4f8; padding: 10px 12px; border-radius: 6px; font-family: Consolas, "Courier New", monospace; font-size: 10.5pt; white-space: pre-wrap; }
.page a { color: #2b59c3; }
.page hr { border: 0; border-top: 1px solid #ccc; margin: 1em 0; }
.page ul, .page ol { margin: 0 0 .6em; padding-left: 1.6em; }
@media (max-width: 520px) { .page { padding: 18px; } }

@media print {
  body * { visibility: hidden; }
  #text, #text * { visibility: visible; }
  #text { position: absolute; inset: 0; border: 0; max-height: none; overflow: visible; box-shadow: none; padding: 0; }
}
.editor-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-top: 8px; }

.details { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; margin: 0; font-size: .9rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; font-weight: 600; text-align: right; }

.seg { display: flex; gap: 4px; }
.seg button { padding: 3px 10px; }
.seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.keywords { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9rem; }
.keywords li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.keywords .kw { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keywords .count { color: var(--muted); }
.keywords .pct { font-weight: 600; min-width: 46px; text-align: right; }
.keywords .empty { display: block; color: var(--muted); }

.limits { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; font-size: .85rem; }
.limit-row { display: flex; justify-content: space-between; margin-bottom: 3px; }
.limit-row .num { color: var(--muted); }
.limit-row .num.over { color: var(--danger); font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .2s; }
.bar span.near { background: var(--warn); }
.bar span.over { background: var(--danger); }

.goal { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .85rem; font-weight: 600; margin-bottom: 8px; }
.goal input { width: 110px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.hidden { display: none; }
.muted { color: var(--muted); }
.small { font-size: .8rem; margin: 6px 0 0; }

.content { margin: 28px 0; }
.content h2 { font-size: 1.2rem; margin: 10px 0; }
.content p { color: var(--muted); }
details { border-top: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; }
details p { margin: 8px 0 0; }

.footer { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: .85rem; text-align: center; }
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }
.legal { max-width: 820px; margin: 32px auto; }
.legal h1 { margin-top: 0; }
.legal p, .legal li { color: var(--text); }
.legal a { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
