/* Self-hosted (static/fonts, see static/LICENSES.txt): variable woff2, latin + latin-ext, so the app is identical offline. */
@font-face { font-family: 'Fraunces'; font-style: normal; font-weight: 600 700; font-display: swap; src: url(fonts/fraunces-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Fraunces'; font-style: normal; font-weight: 600 700; font-display: swap; src: url(fonts/fraunces-latin.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: 'Inter'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(fonts/inter-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(fonts/inter-latin.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; }
/* WHY env() only: on Android the native shell (MainActivity) pads the WebView container with the status bar,
   display cutout, navigation bar and keyboard insets and consumes them, so env() reads 0 there and nothing is
   applied twice. Plain browsers and notched/iOS PWAs have no native layer, so env() carries the real inset.
   Capacitor's injected --safe-area-inset-* vars are deliberately not used (insetsHandling "disable"). */
:root { --inset-top: env(safe-area-inset-top, 0px); --inset-right: env(safe-area-inset-right, 0px); --inset-bottom: env(safe-area-inset-bottom, 0px); --inset-left: env(safe-area-inset-left, 0px); }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 16px; line-height: 1.5; min-height: 100vh; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: .5rem 1rem; z-index: 300; }
.skip:focus { left: 0; }
[hidden] { display: none !important; }

/* Lock */
.lock { position: fixed; inset: 0; z-index: 200; display: none; overflow-y: auto; align-items: flex-start; justify-content: center; padding: calc(1rem + var(--inset-top)) calc(1rem + var(--inset-right)) calc(1rem + var(--inset-bottom)) calc(1rem + var(--inset-left)); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.locked .lock { display: flex; }
.locked .app, .locked .sheet { display: none; }
.lock-card { margin: auto; width: 100%; max-width: 340px; background: var(--surface); border-radius: var(--r-lg); padding: 2rem 1.5rem; box-shadow: var(--shadow-lock); text-align: center; display: grid; gap: .75rem; }
.lock-mark { font-size: 2.5rem; }
.lock-card h1 { margin: 0; font-family: var(--font-display); font-size: 1.6rem; }
.lock-card p { margin: 0; color: var(--muted); }
.lock-card input { width: 100%; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg); text-align: center; font-size: 1.1rem; letter-spacing: .2em; }
.lock-error { color: var(--danger) !important; font-size: .9rem; }

.primary { background: var(--accent); color: var(--on-accent); border: 0; border-radius: var(--r-pill); padding: .7rem 1.4rem; font-weight: 600; min-height: 44px; }
.ghost { background: transparent; border: 1px solid var(--border); border-radius: var(--r-pill); padding: .7rem 1.2rem; min-height: 44px; }
.icon-btn { background: transparent; border: 0; border-radius: var(--r-sm); min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.icon-btn:hover { background: var(--surface-2); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); min-height: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: var(--inset-top) 0 0 var(--inset-left); z-index: 90; transform: translateX(-100%); transition: transform .25s ease; }
.sidebar.open { transform: none; box-shadow: var(--shadow); }
.overlay { position: fixed; inset: 0; background: var(--scrim); z-index: 80; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 70; display: flex; align-items: center; gap: .25rem; padding: calc(.4rem + var(--inset-top)) calc(.6rem + var(--inset-right)) .4rem calc(.6rem + var(--inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 .4rem; }
.main { flex: 1; display: flex; flex-direction: column; padding: 1.25rem calc(1rem + var(--inset-right)) calc(2rem + var(--inset-bottom)) calc(1rem + var(--inset-left)); outline: none; background: var(--bg); }
.view { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 920px; margin: 0 auto; }
/* Short viewports (landscape phone, keyboard open): let the whole sidebar scroll so the search field stays reachable. */
@media (max-height: 480px) and (max-width: 899px) {
  .sidebar { overflow-y: auto; }
  .notes-list { flex: none; overflow: visible; }
}
@media (min-width: 900px) {
  .sidebar { position: sticky; top: 0; height: 100vh; width: var(--sidebar-w, 320px); flex: none; transform: none; z-index: 1; }
  .drawer-only { display: none !important; }
  .overlay { display: none; }
  /* The pinned sidebar already clears the left inset, so the content column must not add it again. */
  .main { padding: 2rem calc(2rem + var(--inset-right)) calc(2.5rem + var(--inset-bottom)) 2rem; }
  .topbar { padding-left: .6rem; }
}

/* Sidebar */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem .5rem; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; letter-spacing: -.01em; }
.new-note { margin: .25rem 1rem .5rem; }
.search { position: relative; margin: .25rem 1rem; }
.search input { width: 100%; min-width: 0; padding: .6rem 2.2rem .6rem .75rem; border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--bg); min-height: 44px; }
.search input::-webkit-search-cancel-button { display: none; }
.search .icon-btn { position: absolute; right: 0; top: 0; font-size: .9rem; }
.list-tools { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .1rem 1rem 0 1.2rem; min-height: 1.6rem; }
.search-meta { flex: 1; min-width: 0; font-size: .8rem; color: var(--muted); }
.sort-btn { flex: none; background: none; border: 0; border-radius: var(--r-pill); padding: .2rem .6rem; font-size: .78rem; font-weight: 600; color: var(--muted); min-height: 32px; }
.sort-btn:hover { background: var(--surface-2); color: var(--text); }
.notes-list { flex: 1; overflow-y: auto; padding: .25rem 0 2rem; overscroll-behavior: contain; }
.sec-title { display: flex; align-items: center; gap: .4rem; width: 100%; background: none; border: 0; text-align: left; margin: .6rem .5rem 0; padding: .8rem .7rem .35rem; width: calc(100% - 1rem); border-top: 1px solid var(--border); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
button.sec-title::after { content: "▸"; margin-left: auto; transition: transform .2s; }
button.sec-title[aria-expanded="true"]::after { transform: rotate(90deg); }
.note-row { position: relative; display: flex; align-items: center; gap: .6rem; margin: 0 .5rem; padding: .55rem 64px .55rem .7rem; min-height: 56px; border-radius: var(--r-sm); color: var(--text); text-decoration: none; }
.note-row:hover { background: var(--surface-2); }
.note-row.active { background: var(--accent-soft); }
.note-row.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.note-link { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.note-ic { font-size: 1.35rem; width: 1.8rem; text-align: center; flex: none; }
.note-txt { flex: 1; min-width: 0; }
.note-title { display: block; font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-row.active .note-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-sum { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-date { display: block; font-size: .7rem; color: var(--muted); opacity: .85; }
.note-acts { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 60px; display: flex; justify-content: flex-end; }
.note-acts button { background: none; border: 0; min-width: 30px; min-height: 36px; border-radius: var(--r-sm); font-size: .95rem; opacity: 0; }
.note-acts button:hover { background: var(--border); }
.note-row:hover .note-acts button, .note-row:focus-within .note-acts button, .note-row.active .note-acts button { opacity: 1; }
@media (hover: none) { .note-acts button { opacity: .85; min-width: 30px; } }
.empty-side { padding: 1.5rem 1.2rem; color: var(--muted); font-size: .9rem; text-align: center; }
mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 3px; }

/* Note view */
.note-head { margin-bottom: 1.25rem; display: flex; align-items: flex-start; gap: .75rem; }
.note-head-ic { font-size: 2rem; line-height: 1.2; }
.note-head-txt { flex: 1; min-width: 0; }
.note-head h1 { margin: 0; font-family: var(--font-display); font-size: clamp(1.3rem, 4vw, 1.7rem); line-height: 1.2; }
.note-meta { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.copy-btn { flex: none; }
#note-host { display: block; }
.state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.state .big { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.state button { margin-top: 1rem; }
.skeleton { display: grid; gap: .8rem; }
.skeleton div { height: 1rem; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
.skeleton div:first-child { height: 7rem; border-radius: var(--r-lg); }
@keyframes sk { to { background-position: -200% 0; } }

/* Settings */
.sheet { border: 0; border-radius: var(--r-lg); padding: 0; width: min(420px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-sheet); }
.sheet::backdrop { background: var(--scrim-dialog); }
.sheet-body { padding: 1.25rem; display: grid; gap: .6rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.3rem; }
.field-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: .5rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: var(--r-pill); padding: 3px; }
.seg button { border: 0; background: none; border-radius: var(--r-pill); min-height: 40px; font-weight: 600; }
.seg button[aria-checked="true"] { background: var(--surface); box-shadow: var(--shadow); color: var(--accent-strong); }
.swatches { display: flex; gap: .7rem; flex-wrap: wrap; }
.swatches button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--sw); }
.swatches [data-accent="saffron"] { --sw: var(--accent-saffron); } .swatches [data-accent="indigo"] { --sw: var(--accent-indigo); } .swatches [data-accent="emerald"] { --sw: var(--accent-emerald); }
.swatches [data-accent="rose"] { --sw: var(--accent-rose); } .swatches [data-accent="ocean"] { --sw: var(--accent-ocean); } .swatches [data-accent="violet"] { --sw: var(--accent-violet); }
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--sw); }
.sheet-foot { display: flex; justify-content: space-between; gap: .5rem; margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.help { margin-top: .75rem; border: 1px solid var(--border); border-radius: var(--r-sm); }
.help > summary { cursor: pointer; padding: .7rem .9rem; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.help-body { padding: 0 .9rem .9rem; font-size: .88rem; max-height: 45vh; overflow-y: auto; }
.help-body h3 { font-size: .95rem; margin: .9rem 0 .3rem; }
.help-body ul, .help-body ol { margin: 0; padding-left: 1.2rem; }
.help-body li + li { margin-top: .35rem; }
.help-body code, .help-body kbd, .help-body pre { font-family: var(--font-mono); font-size: .8rem; background: var(--surface-2); border-radius: var(--r-xs); }
.help-body code, .help-body kbd { padding: .05em .35em; }
.help-body pre { padding: .7rem; white-space: pre-wrap; margin: 0 0 .6rem; border: 1px solid var(--border); }
.sheet { inset: var(--inset-top) var(--inset-right) var(--inset-bottom) var(--inset-left); max-height: min(92vh, calc(100dvh - var(--inset-top) - var(--inset-bottom) - 1rem)); max-width: calc(100% - 6px - 2em - var(--inset-left) - var(--inset-right)); overflow-y: auto; }
.sheet-body { grid-template-columns: minmax(0, 1fr); }
.help-body { overflow-wrap: anywhere; }
.help-body code { white-space: normal; }

.side-foot { padding: .5rem 1.2rem calc(.5rem + var(--inset-bottom)); border-top: 1px solid var(--border); font-size: .72rem; color: var(--muted); }
.resizer { display: none; }
@media (min-width: 900px) {
  .resizer { display: block; position: absolute; top: 0; right: -4px; bottom: 0; width: 8px; cursor: col-resize; z-index: 5; touch-action: none; }
  .resizer:hover, .resizer.drag, .resizer:focus-visible { background: color-mix(in srgb, var(--accent) 40%, transparent); outline: none; }
}
#note-host { flex: 1; display: flex; flex-direction: column; }
.toggle { display: flex; align-items: center; gap: .7rem; min-height: 44px; font-weight: 500; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.about { margin-top: .8rem; font-size: .82rem; color: var(--muted); line-height: 1.5; }
.about b { color: var(--text); }
.hint { margin: 0; color: var(--muted); font-size: .9rem; }
.text-input { width: 100%; min-width: 0; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg); min-height: 44px; }
.prompt-box { margin: 0; padding: .7rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow-y: auto; font-family: var(--font-mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); }

/* native app: sync status, toast, diagnostics */
.sync-last { margin-top: .6rem; font-size: .82rem; }
.state-sync-row { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; font-size: .82rem; }
.diag { margin: .5rem 0 0; padding: .5rem .7rem; background: var(--surface-2); border-radius: var(--r-sm); font-size: .72rem; color: var(--muted); white-space: pre-wrap; user-select: text; }
.spin { display: inline-block; width: .9em; height: .9em; vertical-align: -.1em; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#sync-now:disabled { opacity: .7; cursor: progress; }
.toast { position: fixed; left: 50%; bottom: calc(1.2rem + var(--inset-bottom)); transform: translate(-50%, 1rem); max-width: min(92vw, 420px); padding: .65rem 1rem; background: var(--text); color: var(--bg); border-radius: var(--r-pill); font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.lock-card .ghost { justify-self: center; }
