:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #18181b;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --highlight: #fde68a;
  --shadow: 0 8px 24px rgba(0, 0, 0, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #18181b;
    --surface-2: #27272a;
    --text: #fafafa;
    --muted: #a1a1aa;
    --line: #3f3f46;
    --accent: #fafafa;
    --accent-text: #18181b;
    --danger: #f87171;
    --highlight: #854d0e;
    --shadow: 0 8px 28px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }

.app-shell { min-height: 100dvh; max-width: 880px; margin: 0 auto; background: var(--surface); }
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 440px); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); }
.logo { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-size: 28px; margin-bottom: 20px; }
h1, h2, p { margin-top: 0; }
.auth-card h1 { margin-bottom: 8px; }
.subtle { color: var(--muted); line-height: 1.5; }
.form-grid { display: grid; gap: 14px; margin-top: 24px; }
label { display: grid; gap: 7px; font-weight: 650; }
input, textarea { width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 14px; padding: 13px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 12%, transparent); }
textarea { resize: none; line-height: 1.55; }
.primary, .secondary, .icon-button, .danger-button { border: 0; border-radius: 14px; min-height: 46px; padding: 0 16px; font-weight: 750; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary, .icon-button { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.danger-button { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); }
.text-button { border: 0; background: transparent; color: var(--text); padding: 8px; font-weight: 700; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--muted); }
.auth-switch button { border: 0; background: none; color: var(--text); font-weight: 800; }
.error-box { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); border-radius: 12px; padding: 12px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; min-height: 68px; padding: env(safe-area-inset-top) 14px 0; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-line { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.icon-button { width: 46px; padding: 0; display: grid; place-items: center; font-size: 21px; }
.content { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.empty { margin: 56px auto; max-width: 360px; text-align: center; color: var(--muted); line-height: 1.55; }
.note-list { display: grid; gap: 10px; }
.note-card { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--radius); padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.03); }
.note-card:active { transform: scale(.995); }
.note-title { font-weight: 800; font-size: 17px; overflow-wrap: anywhere; }
.note-preview { color: var(--muted); margin-top: 7px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.note-date { color: var(--muted); font-size: 12px; margin-top: 10px; }
.fab { position: fixed; right: max(22px, calc((100vw - 880px) / 2 + 22px)); bottom: calc(22px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-text); font-size: 30px; box-shadow: var(--shadow); }

.search-wrap { padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 68px; z-index: 19; }
.search-box { display: flex; gap: 8px; }
.search-box input { flex: 1; }
mark { background: var(--highlight); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-snippet { color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.45; }

.note-view { padding: 24px 20px calc(80px + env(safe-area-inset-bottom)); }
.note-view h1 { font-size: clamp(25px, 5vw, 36px); overflow-wrap: anywhere; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; font-size: 17px; user-select: text; min-height: 40vh; }
.editor { display: grid; grid-template-rows: auto 1fr; height: calc(100dvh - 69px); }
.editor-title { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: var(--surface); font-size: 23px; font-weight: 800; padding: 18px 20px; }
.editor-body { border: 0; border-radius: 0; background: var(--surface); min-height: 0; height: 100%; padding: 20px; font-size: 17px; }
.editor-title:focus, .editor-body:focus { box-shadow: none; }
.top-actions { display: flex; gap: 6px; }

.menu { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.38); display: grid; align-items: end; }
.menu-card { background: var(--surface); border-radius: 22px 22px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.menu-card button { width: 100%; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--surface); padding: 11px 15px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 881px) {
  .app-shell { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
