/* ── Palette: "Paper & Ink". Change colors here only. ── */
:root {
  --bg: #14151b;
  --surface: #1c1e27;
  --hover: #2a2d3a;
  --border: #343849;
  --text: #e7e9f1;
  --muted: #9ba1b6;
  --accent: #ffb454;
  --accent-soft: rgba(255, 180, 84, .16);
  --on-accent: #1d1403;
  --editor: #14151b;
  --danger: #ff8f8f;
  --mark: rgba(255, 180, 84, .28);
  --mark-current: rgba(255, 180, 84, .7);
  --kw: #82aaff; --st: #c3e88d; --cm: #7d85a6; --nm: #f78c6c; --fn: #ffcb6b; --tp: #89ddff; --at: #c792ea;
  --zoom: 1;
  --ui: system-ui, -apple-system, 'Segoe UI Variable Text', 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, 'Courier New', monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --surface: #fbf9f4;
  --hover: #ece6d9;
  --border: #d9d2c3;
  --text: #24222b;
  --muted: #625e6c;
  --accent: #b45309;
  --accent-soft: rgba(180, 83, 9, .13);
  --on-accent: #fff;
  --editor: #fffdf8;
  --danger: #c92a2a;
  --mark: rgba(180, 83, 9, .22);
  --mark-current: rgba(180, 83, 9, .5);
  --kw: #2f4fc9; --st: #2a6f0f; --cm: #6b6f7b; --nm: #b3410e; --fn: #8a5a00; --tp: #0b7285; --at: #9c36b5;
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.4 var(--ui);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Title bar ── */
#titlebar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--surface); flex-shrink: 0;
}
#titlebar img { flex-shrink: 0; border-radius: 5px; }
.brand { font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--muted); letter-spacing: .2px; }
.brand b { color: var(--accent); font-weight: 700; }
/* File name and extension are separate fields: [ name ] . [ ext ] */
#fileBox { display: flex; align-items: center; min-width: 0; }
#fileName, #fileExt {
  field-sizing: content; min-width: 3ch;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font: inherit; padding: 4px 6px;
}
#fileName { max-width: min(420px, 40vw); padding-inline-end: 3px; }
#fileExt { max-width: 12ch; padding-inline-start: 3px; }
#fileBox .dot { color: var(--muted); }
#fileExt::placeholder { color: var(--muted); opacity: 1; } /* the automatic extension */
#fileExt::-webkit-calendar-picker-indicator { display: none !important; }
#fileName:hover, #fileExt:hover { border-color: var(--border); }
#fileName:focus, #fileExt:focus { border-color: var(--accent); background: var(--editor); outline: none; }
#langSelect {
  margin-inline-start: auto; flex-shrink: 0;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font: inherit; padding: 4px 6px; cursor: pointer;
}
#langSelect option { background: var(--surface); color: var(--text); }

/* ── Toolbar ── */
#toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 8px 6px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0; scrollbar-width: thin;
}
.sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; flex-shrink: 0; }
button {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  min-height: 30px; padding: 4px 9px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font: inherit; white-space: nowrap; cursor: pointer;
}
button:hover { background: var(--hover); }
button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
button.txt { font-variant-numeric: tabular-nums; }
button.icon-only { padding: 4px 7px; }
.ic { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
@keyframes deny { 35%, 65% { background: var(--danger); color: var(--bg); border-color: var(--danger); } }
.deny { animation: deny .55s ease; }
@keyframes invite { 50% { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); } }
.invite { animation: invite 1.8s ease-in-out infinite; }

/* ── Find bar ── */
#findBar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#findBar input[type=text] {
  width: 170px; padding: 5px 8px;
  background: var(--editor); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font: inherit;
}
#findBar input[type=text]:focus { border-color: var(--accent); outline: none; }
#findCount { min-width: 84px; padding: 0 4px; color: var(--muted); font-variant-numeric: tabular-nums; }
#findBar label { display: flex; align-items: center; gap: 4px; padding: 0 4px; cursor: pointer; }
#findBar input[type=checkbox] { accent-color: var(--accent); }
#bReplace, #bReplaceAll { border-color: var(--border); }
#bFindClose { margin-inline-start: auto; }

/* ── Workspace ── */
#workspace { flex: 1; display: flex; min-height: 0; background: var(--editor); }
#editor, #highlight {
  flex: 1; min-width: 0; padding: 14px 18px;
  background: var(--editor); color: var(--text);
  font: calc(13.5px * var(--zoom))/1.65 var(--mono);
  white-space: pre; tab-size: 2; overflow: auto;
  border: none; outline: none; resize: none;
}
#editor { caret-color: var(--accent); }
#highlight { cursor: text; }
#highlight > div { content-visibility: auto; contain-intrinsic-size: auto 800px; } /* off-screen blocks of a large file are not laid out */
.wrap #editor, .wrap #highlight { white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; }
#editor:focus-visible, #highlight:focus-visible, #preview:focus-visible { outline: none; }
::selection { background: var(--mark); }
::highlight(qwn-find) { background: var(--mark); }
::highlight(qwn-find-current) { background: var(--mark-current); }
* { scrollbar-color: var(--border) transparent; }

.kw { color: var(--kw); } .st { color: var(--st); } .cm { color: var(--cm); font-style: italic; }
.nm { color: var(--nm); } .fn { color: var(--fn); } .tp { color: var(--tp); } .at { color: var(--at); }

/* ── Markdown view ── */
#preview {
  flex: 1; min-width: 0; overflow: auto;
  padding: 28px max(20px, calc((100% - 46em) / 2)) 64px;
  font: calc(15px * var(--zoom))/1.7 var(--ui);
  overflow-wrap: break-word;
}
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.5em 0 .5em; line-height: 1.25; letter-spacing: -.01em; }
.md h1 { font-size: 2em; } .md h2 { font-size: 1.5em; } .md h3 { font-size: 1.22em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md h1, .md h2 { padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 1em; }
.md ul, .md ol { padding-inline-start: 1.6em; }
.md li + li { margin-top: .2em; }
.md li > ul, .md li > ol { margin: .2em 0 0; }
.md li:has(> input[type=checkbox]) { list-style: none; margin-inline-start: -1.3em; }
.md input[type=checkbox] { accent-color: var(--accent); margin-inline-end: .4em; }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md blockquote { padding: .1em 1em; border-inline-start: 3px solid var(--accent); color: var(--muted); }
.md code { font: .9em var(--mono); padding: .15em .4em; border-radius: 4px; background: var(--hover); }
.md pre { padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow-x: auto; }
.md pre code { padding: 0; background: none; line-height: 1.6; }
.md table { display: block; width: max-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.md th, .md td { padding: 6px 12px; border: 1px solid var(--border); text-align: start; }
.md th { background: var(--surface); }
.md img { max-width: 100%; }
.md hr { margin: 2em 0; border: none; border-top: 1px solid var(--border); }

#noscript { padding: 24px; max-width: 62ch; font-size: 15px; line-height: 1.6; }
#noscript a { color: var(--accent); }

/* ── Status bar ── */
#statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 12px; background: var(--surface); border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.group { display: flex; align-items: center; gap: 14px; min-width: 0; }
#stLock { color: var(--danger); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
#stMode { color: var(--text); }
#statusbar a { color: inherit; text-underline-offset: 2px; }
#statusbar a:hover { color: var(--text); }

/* ── Ad strip: collapsed until Google reports the slot as filled ── */
#adStrip {
  flex-shrink: 0; height: 0; overflow: hidden;
  display: flex; justify-content: center;
  background: var(--surface);
}
#adStrip ins { display: block; flex-shrink: 0; width: 320px; height: 50px; }
#adStrip:has(ins[data-ad-status="filled"]) { height: 51px; border-top: 1px solid var(--border); }
@media (min-width: 800px) and (min-height: 640px) {
  #adStrip ins { width: 728px; height: 90px; }
  #adStrip:has(ins[data-ad-status="filled"]) { height: 91px; }
}
body:has(#adStrip ins[data-ad-status="filled"]) #toast { bottom: 140px; }

/* ── Toast ── */
#toast {
  position: fixed; inset-inline: 0; bottom: 44px; margin-inline: auto; width: max-content; max-width: calc(100% - 32px);
  padding: 9px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: none; }

@media (max-width: 860px) {
  #toolbar .lbl { display: none; }
  #toolbar { flex-wrap: wrap; overflow-x: visible; }
  .brand { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } /* still announced to screen readers */
  #stZoom, #stVersion { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition: none !important; }
}
