:root, [data-theme="dark"] {
  --bg: #121212; --fg: #d9d6cf; --dim: #6b6862; --faint: #2a2927; --sel: #3a3833; --panel: #181817;
}
[data-theme="light"] {
  --bg: #fbfaf7; --fg: #2b2a28; --dim: #9a968e; --faint: #e7e4dd; --sel: #e6e1d4; --panel: #f3f1ec;
}
[data-theme="sepia"] {
  --bg: #f1e7d0; --fg: #433422; --dim: #9b8667; --faint: #e0d3b5; --sel: #dccaa2; --panel: #eadfc4;
}
[data-font="serif"] { --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; --size: 1.25rem; }
[data-font="sans"]  { --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; --size: 1.15rem; }
[data-font="mono"]  { --font: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; --size: 1.02rem; }
[data-width="narrow"] { --col: 32rem; }
[data-width="normal"] { --col: 40rem; }
[data-width="wide"]   { --col: 56rem; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { overflow: hidden; transition: background .3s, color .3s; font-family: -apple-system, "Segoe UI", sans-serif; }
::selection { background: var(--sel); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

main { position: fixed; inset: 0; }
#pad {
  display: block; width: 100%; height: 100%; resize: none; border: 0; outline: 0;
  background: transparent; color: var(--fg);
  font-family: var(--font); font-size: var(--size); line-height: 1.7;
  padding: max(14vh, 4.5rem) max(1.5rem, calc((100% - var(--col)) / 2)) 45vh;
  caret-color: var(--fg);
  scrollbar-width: thin; scrollbar-color: var(--faint) transparent;
}
#pad::placeholder { color: var(--dim); opacity: .6; }

/* the controls fade away while you write and come back when the mouse moves */
.chrome { position: fixed; z-index: 5; color: var(--dim); transition: opacity .6s; }
body.writing .chrome { opacity: 0; pointer-events: none; }
.corner { top: max(14px, env(safe-area-inset-top)); }
.corner.left { left: 14px; }
.corner.right { right: 14px; display: flex; gap: 4px; }
.corner button, #menuBtn { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; }
.corner button:hover, #menuBtn:hover { color: var(--fg); background: var(--faint); }
.aa { font-family: Georgia, serif; font-size: 15px; }
footer {
  bottom: max(12px, env(safe-area-inset-bottom)); left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0 20px; font-size: 12px; letter-spacing: .02em;
  pointer-events: none;
}
#status.bad { color: #c8775f; }

/* notes drawer */
#drawer {
  position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
  background: var(--panel); border-right: 1px solid var(--faint);
  display: flex; flex-direction: column; animation: slide .18s ease-out;
  padding-top: env(safe-area-inset-top);
}
#drawer[hidden] { display: none; }
@keyframes slide { from { transform: translateX(-16px); opacity: 0; } }
#scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.25); }
#scrim[hidden] { display: none; }
.drawer-head { padding: 14px; }
#search {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--faint);
  background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; outline: 0;
}
#search:focus { border-color: var(--dim); }
#list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
#list li {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
#list li:hover { background: var(--faint); }
#list li.on { background: var(--faint); }
#list .t { flex: 1; min-width: 0; }
#list .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .name.untitled { color: var(--dim); font-style: italic; }
#list .when { font-size: 11px; color: var(--dim); margin-top: 2px; }
#list .del { opacity: 0; color: var(--dim); width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; }
#list li:hover .del, #list li.on .del { opacity: 1; }
#list .del:hover { color: #c8775f; }
#list .del svg { width: 16px; height: 16px; }
@media (hover: none) { #list .del { opacity: .7; } }
.drawer-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
.link { font-size: 12px; color: var(--dim); }
.link:hover { color: var(--fg); }

/* login */
#login { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: grid; place-items: center; }
#login[hidden] { display: none; }
#password {
  width: 260px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--dim); outline: 0;
  background: transparent; color: var(--fg); font-family: var(--font); font-size: 1.2rem; text-align: center;
}
#loginErr { color: #c8775f; text-align: center; font-size: 13px; min-height: 1em; }

@media (max-width: 600px) {
  #pad { padding-top: 4.5rem; font-size: calc(var(--size) * .92); }
  .corner.right { gap: 0; }
}
