/* ---------- Fonts ---------- */
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-ext-500-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-ext-600-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Lexend";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/assets/fonts/lexend-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/jetbrains-mono-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

/* ---------- Themes ---------- */
body {
  --bg: #17151f;
  --panel: #1f1d30;
  --raised: #2a2840;
  --line: #36334f;
  --fg: #ecebf3;
  --muted: #a5a2bb;
  --accent: #fec72e;
  --accent-2: #ffab2f;
  --accent-text: #fec72e;
  --on-accent: #1f1d30;
  --danger: #ff6b71;
  --danger-tint: rgba(255, 107, 113, 0.14);
  --code-bg: #121019;
  --select: rgba(254, 199, 46, 0.28);
  --mark: rgba(254, 199, 46, 0.35);
  --scrim: rgba(8, 7, 14, 0.6);
  --syn-kw: #ffab2f;
  --syn-str: #8fd3c8;
  --syn-num: #f29bb8;
  --syn-com: #7f7c98;
  --syn-fn: #fec72e;
  --syn-type: #a9b8ff;
  --syn-attr: #c9a7ff;
  --gh-kw: #ff7b72; --gh-title: #d2a8ff; --gh-const: #79c0ff; --gh-str: #a5d6ff; --gh-builtin: #ffa657;
  --gh-com: #8b949e; --gh-name: #7ee787; --gh-sub: #c9d1d9; --gh-section: #1f6feb; --gh-bullet: #f2cc60;
  --thumb: #46425f; --thumb-hover: #5a5578;
  --font-ui: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}
body[data-ot-theme="light"] {
  --bg: #ffffff; --panel: #f6f5f9; --raised: #ebe9f2; --line: #dcd9e6; --fg: #1f1d30; --muted: #5e5b76;
  --accent: #fec72e; --accent-2: #ffab2f; --accent-text: #8a5d00; --on-accent: #1f1d30;
  --danger: #c8333a; --danger-tint: rgba(200, 51, 58, 0.1); --code-bg: #f3f2f8; --select: rgba(254, 199, 46, 0.45); --mark: rgba(254, 199, 46, 0.55); --scrim: rgba(31, 29, 48, 0.45);
  --syn-kw: #b05a00; --syn-str: #11756a; --syn-num: #b02f68; --syn-com: #7a7790; --syn-fn: #835c00; --syn-type: #3a4ec2; --syn-attr: #7a3fc4;
  --gh-kw: #d73a49; --gh-title: #6f42c1; --gh-const: #005cc5; --gh-str: #032f62; --gh-builtin: #e36209;
  --gh-com: #6a737d; --gh-name: #22863a; --gh-sub: #24292e; --gh-section: #005cc5; --gh-bullet: #735c0f;
  --thumb: #c9c6d6; --thumb-hover: #aeaabf;
  color-scheme: light;
}
body[data-ot-theme="oled"] {
  --bg: #000000; --panel: #000000; --raised: #141414; --line: #262626; --fg: #e8e8ea; --muted: #8e8e96;
  --code-bg: #0a0a0a; --scrim: rgba(0, 0, 0, 0.75);
  --thumb: #2e2e2e; --thumb-hover: #444444;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
* { scrollbar-color: var(--thumb) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--thumb); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--thumb-hover); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 15px; line-height: 1.5; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top" "side main" "status status";
}

/* ---------- Top bar ---------- */
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.app-icon { width: 32px; height: 32px; flex: none; }
.pixel-art { image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; }
.note-title {
  flex: 1; min-width: 0;
  padding: 6px 10px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  font-weight: 500;
}
.note-title::placeholder { color: var(--muted); opacity: 1; }
.note-title:hover:not([readonly]) { border-color: var(--line); }
.note-title:focus:not([readonly]) { border-color: var(--accent); outline: none; background: var(--bg); }
.top-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn, .text-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 10px;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; white-space: nowrap; font-size: 0.8125rem; font-weight: 500;
}
.icon-btn { width: 34px; padding: 0; }
.icon-btn svg, .text-btn svg { width: 17px; height: 17px; flex: none; }
.icon-btn:hover, .text-btn:hover { background: var(--raised); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 9px; }
.seg button { height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--fg); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }

.support {
  position: relative;
  display: inline-flex; align-items: center; justify-content: flex-start;
  width: 34px; height: 34px; padding: 0 0 0 7px; overflow: hidden;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid var(--accent); border-radius: 8px;
  text-decoration: none; font-size: 0.8125rem; font-weight: 600;
  transition: width 0.2s ease;
}
.support svg { width: 18px; height: 18px; flex: none; }
.support span { margin-left: 7px; opacity: 0; transition: opacity 0.15s ease; white-space: nowrap; }
.support:hover, .support:focus-visible { width: 98px; background: var(--accent-2); }
.support:hover span, .support:focus-visible span { opacity: 1; }

/* ---------- Notes drawer ---------- */
.sidebar {
  grid-area: side;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.side-head { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.brand-logo { align-self: center; width: 116px; height: 48px; margin: 2px 0 6px; }
.new-note {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; border: 0; border-radius: 9px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer;
}
.new-note:hover { background: var(--accent-2); }
.new-note svg { width: 16px; height: 16px; }
.search {
  height: 34px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 0.875rem;
}
.search:focus { outline: none; border-color: var(--accent); }
.list-heading { margin: 0; padding: 0 20px 6px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--danger); }
.note-list { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; min-height: 0; }
.note-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; text-align: left; cursor: pointer;
}
.note-item:hover { background: var(--raised); }
.note-item[aria-current="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--accent); }
.is-trash .note-item[aria-current="true"] { box-shadow: inset 3px 0 0 var(--danger); }
.note-name { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; font-weight: 500; min-width: 0; }
.note-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-name .untitled { color: var(--muted); font-style: italic; }
.note-meta { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { flex: none; padding: 0 6px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.6875rem; font-style: normal; color: var(--muted); }
.empty-list { padding: 12px; font-size: 0.8125rem; color: var(--muted); }

.ad-slot {
  margin: 0 12px 10px; min-height: 110px; padding: 10px;
  display: grid; place-items: center;
  border: 1px dashed var(--line); border-radius: 10px;
  font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); text-align: center;
}
.trash-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 0 12px 10px; height: 34px;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  color: var(--danger); font-size: 0.8125rem; font-weight: 500; cursor: pointer;
}
.trash-toggle:hover { background: var(--danger-tint); }
.trash-toggle svg { width: 16px; height: 16px; }
.trash-count { padding: 0 6px; border-radius: 999px; background: var(--danger-tint); font-variant-numeric: tabular-nums; font-size: 0.75rem; }
.is-trash .trash-toggle { color: var(--fg); }
.is-trash .trash-toggle svg { display: none; }
.side-foot { display: flex; gap: 6px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.side-foot .text-btn { flex: 1; }
.text-btn.danger { color: var(--danger); }
.text-btn.danger:hover { background: var(--danger-tint); }
.is-trash .ad-slot { display: none; }

/* ---------- Toolbar ---------- */
.workspace { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg); min-width: 0; }
.lang-select {
  flex: none; height: 30px; padding: 0 26px 0 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  font-size: 0.8125rem; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.md-tools {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 2px;
  overflow: hidden;
}
.md-tools button {
  flex: none; height: 30px; min-width: 30px; padding: 0 7px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  font-family: var(--font-code); font-size: 0.8125rem; color: var(--muted);
}
.md-tools button:hover { background: var(--raised); color: var(--fg); }
.md-tools .sep { flex: none; width: 1px; height: 18px; margin: 0 5px; background: var(--line); }
.more-wrap { position: relative; flex: none; }
.more-btn { color: var(--muted); }
.more-btn[aria-expanded="true"] { background: var(--raised); color: var(--fg); }
.more-panel {
  position: fixed; top: 0; left: 0; z-index: 15;
  display: flex; flex-wrap: wrap; gap: 2px;
  width: max-content; max-width: min(300px, calc(100vw - 32px));
  padding: 6px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}
.more-panel button {
  height: 32px; min-width: 34px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  font-family: var(--font-code); font-size: 0.8125rem; color: var(--muted);
}
.more-panel button:hover { background: var(--raised); color: var(--fg); }
.toolbar-gap { flex: 1; }
.note-actions { display: flex; gap: 4px; flex: none; }
.tool-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 30px; border: 0; border-radius: 7px; background: transparent; cursor: pointer;
}
.tool-icon svg { width: 17px; height: 17px; }
.tool-icon:hover { background: var(--raised); }
.tool-icon.copy { color: var(--fg); }
.tool-icon.delete { color: var(--danger); }
.tool-icon.delete:hover { background: var(--danger-tint); }

.trash-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--danger-tint); color: var(--fg); font-size: 0.8125rem;
  border-bottom: 1px solid var(--line);
}
.trash-banner p { margin: 0; flex: 1; min-width: 200px; }
.trash-banner .text-btn { height: 30px; }
.restore-btn { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.restore-btn:hover { background: var(--accent-2); }

/* ---------- Editor with live highlighting ---------- */
.panes { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.app[data-view="write"] .panes, .app[data-view="preview"] .panes { grid-template-columns: minmax(0, 1fr); }
.app[data-view="write"] .preview { display: none; }
.app[data-view="preview"] .editor-wrap { display: none; }

.editor-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
.editor, .code-layer {
  position: absolute; inset: 0; margin: 0;
  padding: 22px 26px 40vh;
  font-family: var(--font-code); font-size: 14.5px; line-height: 1.7; tab-size: 2; letter-spacing: normal;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal;
  overflow-y: scroll; overflow-x: hidden;
  border: 0;
}
.code-layer { color: var(--fg); pointer-events: none; background: transparent; }
.code-layer code { font: inherit; background: none; padding: 0; }
.editor {
  z-index: 1; width: 100%; height: 100%; resize: none; outline: none;
  color: transparent; background: transparent; caret-color: var(--accent);
}
.editor::selection { color: transparent; background: var(--select); }
.editor::placeholder { color: var(--muted); }
.editor-wrap.is-plain .editor { color: var(--fg); }
.editor-wrap.is-plain .code-layer { display: none; }

/* ---------- Preview ---------- */
.preview { overflow-y: auto; min-width: 0; padding: 22px 30px 40vh; border-left: 1px solid var(--line); background: var(--panel); }
.app[data-view="preview"] .preview { border-left: 0; }
.preview > * { max-width: 42rem; }
.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 { line-height: 1.25; text-wrap: balance; font-weight: 600; }
.preview h1 { font-size: 1.75rem; margin: 0 0 0.6em; }
.preview h2 { font-size: 1.3rem; margin: 1.6em 0 0.5em; }
.preview h3 { font-size: 1.1rem; margin: 1.4em 0 0.4em; }
.preview h4, .preview h5, .preview h6 { font-size: 1rem; margin: 1.3em 0 0.4em; }
.preview h6 { color: var(--muted); }
.preview p, .preview ul, .preview ol, .preview blockquote, .preview pre, .preview table, .preview dl { margin: 0 0 1em; }
.preview a { color: var(--accent-text); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.preview img { max-width: 100%; border-radius: 8px; }
.preview code { font-family: var(--font-code); font-size: 0.85em; padding: 0.1em 0.35em; border-radius: 5px; background: var(--raised); }
.preview pre { position: relative; overflow-x: auto; padding: 14px 16px; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--line); }
.preview pre code { padding: 0; background: none; font-size: 0.8125rem; line-height: 1.65; color: var(--gh-sub); }
.preview pre[data-lang]::after { content: attr(data-lang); position: absolute; top: 6px; right: 10px; font-family: var(--font-code); font-size: 0.6875rem; color: var(--muted); text-transform: lowercase; }
.preview blockquote { padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--raised); border-radius: 0 8px 8px 0; }
.preview blockquote p:last-child { margin-bottom: 0; }
.preview ul:has(> li > input[type="checkbox"]) { padding-left: 4px; list-style: none; }
.preview li input[type="checkbox"] { width: 16px; height: 16px; margin: 0 8px 0 0; vertical-align: -2px; accent-color: var(--accent); cursor: pointer; }
.preview hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.preview table { border-collapse: collapse; display: block; overflow-x: auto; }
.preview th, .preview td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.preview th { background: var(--raised); font-weight: 600; }
.preview mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }
.preview dt { font-weight: 600; }
.preview dd { margin: 0 0 0.6em 1.2em; }
.preview .footnotes { margin-top: 2.5em; padding-top: 1em; border-top: 1px solid var(--line); font-size: 0.875rem; color: var(--muted); }
.preview .footnotes ol { padding-left: 1.2em; }
.preview .fn-ref a, .preview .fn-back { text-decoration: none; }
.preview .code-preview { margin: 0; }

/* ---------- Syntax colors ---------- */
.syn-md .hljs-section { color: var(--accent-text); font-weight: 600; }
.syn-md .hljs-strong { color: var(--fg); font-weight: 600; }
.syn-md .hljs-emphasis { color: var(--fg); font-style: italic; }
.syn-md .hljs-code { color: var(--syn-str); }
.syn-md .hljs-bullet { color: var(--syn-kw); }
.syn-md .hljs-link, .syn-md .hljs-symbol { color: var(--syn-type); }
.syn-md .hljs-string { color: var(--muted); }
.syn-md .hljs-quote { color: var(--syn-com); font-style: italic; }
.syn-gh { color: var(--gh-sub); }
.syn-gh .hljs-doctag, .syn-gh .hljs-keyword, .syn-gh .hljs-meta .hljs-keyword, .syn-gh .hljs-template-tag, .syn-gh .hljs-template-variable, .syn-gh .hljs-type, .syn-gh .hljs-variable.language_ { color: var(--gh-kw); }
.syn-gh .hljs-title, .syn-gh .hljs-title.class_, .syn-gh .hljs-title.class_.inherited__, .syn-gh .hljs-title.function_ { color: var(--gh-title); }
.syn-gh .hljs-attr, .syn-gh .hljs-attribute, .syn-gh .hljs-literal, .syn-gh .hljs-meta, .syn-gh .hljs-number, .syn-gh .hljs-operator, .syn-gh .hljs-selector-attr, .syn-gh .hljs-selector-class, .syn-gh .hljs-selector-id, .syn-gh .hljs-variable { color: var(--gh-const); }
.syn-gh .hljs-meta .hljs-string, .syn-gh .hljs-regexp, .syn-gh .hljs-string { color: var(--gh-str); }
.syn-gh .hljs-built_in, .syn-gh .hljs-symbol { color: var(--gh-builtin); }
.syn-gh .hljs-code, .syn-gh .hljs-comment, .syn-gh .hljs-formula { color: var(--gh-com); }
.syn-gh .hljs-name, .syn-gh .hljs-quote, .syn-gh .hljs-selector-pseudo, .syn-gh .hljs-selector-tag { color: var(--gh-name); }
.syn-gh .hljs-subst { color: var(--gh-sub); }
.syn-gh .hljs-section { color: var(--gh-section); font-weight: 600; }
.syn-gh .hljs-bullet { color: var(--gh-bullet); }
.syn-gh .hljs-emphasis { font-style: italic; }
.syn-gh .hljs-strong { font-weight: 600; }

/* ---------- Status bar ---------- */
.statusbar {
  grid-area: status;
  display: flex; align-items: center; gap: 18px; overflow: hidden;
  padding: 4px 14px calc(4px + env(safe-area-inset-bottom, 0px));
  background: var(--panel); border-top: 1px solid var(--line);
  font-family: var(--font-code); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.statusbar .grow { flex: 1; }
.status-saved::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--accent); vertical-align: 1px; }

/* ---------- Focus mode ---------- */
.app.is-focus { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "status"; }
@media (min-width: 821px) {
  .app.is-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "status"; }
  .app.is-collapsed .sidebar { display: none; }
}
.app.is-focus .sidebar, .app.is-focus .toolbar, .app.is-focus .hide-in-focus { display: none; }
.app.is-focus .editor, .app.is-focus .code-layer { padding-inline: max(26px, calc((100% - 760px) / 2)); }
.app.is-focus .preview > * { margin-inline: auto; }
.app.is-focus .topbar, .app.is-focus .statusbar { background: var(--bg); border-color: transparent; }

/* ---------- Dialogs ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: var(--scrim); }
.dialog {
  width: min(100%, 420px); max-height: calc(100% - 32px); overflow-y: auto;
  padding: 22px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.dialog.wide { width: min(100%, 560px); }
.dialog:focus { outline: none; }
.dialog h2 { margin: 0 0 8px; font-size: 1.125rem; font-weight: 600; }
.dialog p { margin: 0 0 16px; color: var(--muted); font-size: 0.875rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn {
  height: 38px; padding: 0 16px; border-radius: 9px; cursor: pointer; font-weight: 500; font-size: 0.875rem;
  background: transparent; border: 1px solid var(--line);
}
.btn:hover { background: var(--raised); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.lang-grid button {
  height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); cursor: pointer; font-size: 0.8125rem; text-align: left;
}
.lang-grid button:hover { background: var(--raised); }
.lang-grid button.is-last { border-color: var(--accent); }
.keys { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.keys td { padding: 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys td:last-child { text-align: right; white-space: nowrap; padding-left: 12px; }
.keys h3 { margin: 14px 0 4px; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
kbd { font-family: var(--font-code); font-size: 0.75rem; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--bg); }

.toast {
  position: fixed; left: 50%; bottom: 46px; z-index: 50; transform: translateX(-50%);
  max-width: min(92vw, 440px); padding: 10px 14px; border-radius: 10px;
  background: var(--fg); color: var(--bg); font-size: 0.8125rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* ---------- Narrow screens ---------- */
.only-narrow { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "status"; }
  .only-narrow { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: min(86vw, 300px);
    transform: translateX(-102%); transition: transform 0.2s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
  .app.is-drawer .sidebar { transform: none; }
  .seg [data-view="split"], .hide-narrow { display: none; }
  .app[data-view="split"] .panes { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="split"] .preview { display: none; }
  .editor, .code-layer { padding: 16px 16px 40vh; }
  .preview { padding: 16px 16px 40vh; border-left: 0; }
  .statusbar { gap: 12px; }
  .status-optional { display: none; }
}
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .top-actions { order: 5; flex-basis: 100%; justify-content: center; }
}
/* ---------- Writing timer ---------- */
.panes { position: relative; }
.timer-btn { color: var(--fg); }
.timer-btn.is-running { color: var(--accent-text); }
.timer-widget {
  position: absolute; top: 10px; right: 16px; z-index: 5;
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--fg);
  font-family: var(--font-code); font-size: 0.9375rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}
.timer-widget:hover { background: var(--raised); }
.timer-widget svg { width: 14px; height: 14px; flex: none; }
.timer-widget.is-paused { color: var(--muted); }
.timer-widget.is-done { background: var(--danger); border-color: var(--danger); color: #fff; animation: timer-flash 0.5s steps(1) 6; }
@keyframes timer-flash { 50% { background: transparent; color: var(--danger); } }
.timer-widget.is-leaving { opacity: 0; transition: opacity 0.4s; }
.timer-pop {
  position: fixed; top: 0; left: 0; z-index: 30;
  width: 250px; padding: 14px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}
.timer-pop-time { margin: 0 0 12px; font-family: var(--font-code); font-size: 1.375rem; font-variant-numeric: tabular-nums; text-align: center; }
.timer-pop-label { margin: 0 0 6px; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.timer-add { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.timer-add button, .timer-presets button {
  height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  font-family: var(--font-code); font-size: 0.8125rem; cursor: pointer;
}
.timer-add button:hover, .timer-presets button:hover { background: var(--raised); }
.timer-pop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.timer-pop-actions .btn { height: 36px; padding: 0 10px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: var(--danger-tint); }
.clock-input { display: flex; justify-content: center; align-items: flex-start; gap: 6px; margin: 4px 0 16px; }
.clock-unit { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.clock-field {
  width: 3.6ch; padding: 8px 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-family: var(--font-code); font-size: 2.25rem; line-height: 1.1; text-align: center; font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
}
.clock-field:focus { outline: none; border-color: var(--accent); }
.clock-unit span { font-size: 0.75rem; color: var(--muted); }
.clock-sep { padding-top: 10px; font-family: var(--font-code); font-size: 2rem; color: var(--muted); }
.timer-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; cursor: pointer; }
.check-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .sidebar, .support, .support span { transition: none; }
  .timer-widget.is-done { animation: none; }
  .timer-widget.is-leaving { transition: none; }
}
