:root {
  --bg: #f2f2f7;            /* iOS grouped background */
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-soft: #8e8e93;
  --line: rgba(60, 60, 67, .12);
  --accent: #bd8f24;        /* notes gold, Apple Notes adjacent */
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .06), 0 6px 18px rgba(0, 0, 0, .10);

  --c-default: #ffffff;
  --c-work: #dbe7fb;
  --c-home: #dcf0d9;
  --c-cooking: #ffe6c9;
  --c-ideas: #e8ddfb;
  --c-quotes: #fcdce9;
  --c-sunny: #fdf2bf;
  --c-sea: #d2efeb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --text-soft: #98989f;
    --line: rgba(84, 84, 88, .48);
    --accent: #e3bb4e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-hover: 0 2px 6px rgba(0, 0, 0, .5);

    --c-default: #1c1c1e;
    --c-work: #263449;
    --c-home: #263c26;
    --c-cooking: #45301a;
    --c-ideas: #34294a;
    --c-quotes: #452333;
    --c-sunny: #403a17;
    --c-sea: #1d3a36;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* slim, theme-matched scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* ---------- Auth screen ---------- */
.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.auth-lock { font-size: 34px; }

.auth-card h1 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0; }

.auth-sub { font-size: 14px; color: var(--text-soft); margin: -6px 0 0; }

.auth-card input[type="password"] {
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}

.auth-card input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.auth-warning {
  font-size: 13px;
  line-height: 1.55;
  text-align: left;
  color: var(--text);
  background: color-mix(in srgb, var(--c-sunny) 55%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 12px;
  padding: 11px 13px;
}

.auth-remember {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.auth-remember input { accent-color: var(--accent); }

.auth-btn {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}

.auth-btn:hover { filter: brightness(1.06); }
.auth-btn:active { transform: scale(.98); }
.auth-btn:disabled { opacity: .6; cursor: wait; }

.auth-msg { font-size: 13.5px; color: #eb4d3d; min-height: 18px; margin: 0; }
.auth-msg.ok { color: #34a853; }

/* ---------- Settings ---------- */
.settings-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 60px;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.settings-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 8px 0 16px; }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px 22px;
}

.settings-card h2 { font-size: 17px; font-weight: 600; margin: 0 0 6px; }

.settings-sub {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-soft);
  margin: 0 0 16px;
}

.settings-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card input[type="password"] {
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.settings-card input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.brand-mark { color: var(--accent); font-size: 15px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.save-status {
  font-size: 12px;
  color: var(--text-soft);
  margin-right: 6px;
  transition: opacity .3s;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 9px 12px;
  min-height: 40px;
  border-radius: 11px;
  border: none;
  cursor: pointer;
  color: var(--accent);
  background: transparent;
  white-space: nowrap;
  transition: background .15s;
}

.btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn:active { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- Views ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Editor ---------- */
.editor-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 4px 20px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  min-height: 0;
}

#editor {
  width: 100%;
  max-width: 760px;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
  line-height: 1.6;
  padding: 8px 2px;
  caret-color: var(--accent);
}

#editor::placeholder { color: var(--text-soft); opacity: .6; }

/* ---------- Library ---------- */
.library-wrap {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 20px 60px;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.library-tools { margin-bottom: 18px; }

#search {
  width: 100%;
  max-width: 420px;
  font: inherit;
  font-size: 16px;
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  background: color-mix(in srgb, var(--text-soft) 14%, transparent);
  color: var(--text);
  outline: none;
  transition: box-shadow .15s, background .15s;
}

#search::placeholder { color: var(--text-soft); }

#search:focus {
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-soft);
  margin: 24px 0 10px 4px;
}

.grid {
  column-width: 250px;
  column-gap: 14px;
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  break-inside: avoid;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px 15px 9px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: box-shadow .18s, transform .18s;
}

.card:hover, .card:focus-visible { box-shadow: var(--shadow-hover); transform: translateY(-1px); outline: none; }
.card:active { transform: scale(.985); }

.card-title {
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: -.01em;
  margin-bottom: 5px;
  overflow-wrap: anywhere;
}

.card-text {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  opacity: .8;
  display: -webkit-box;
  -webkit-line-clamp: 10;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}

.card-date { font-size: 12px; color: var(--text-soft); }

.card-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}

.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }

@media (hover: none) { .card-actions { opacity: .85; } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: color-mix(in srgb, var(--text-soft) 18%, transparent); color: var(--text); }

.card.pinned .act-pin { color: var(--accent); }
.card.pinned .act-pin svg { fill: color-mix(in srgb, var(--accent) 30%, transparent); }

/* note colours */
.card[data-color="work"]    { background: var(--c-work); }
.card[data-color="home"]    { background: var(--c-home); }
.card[data-color="cooking"] { background: var(--c-cooking); }
.card[data-color="ideas"]   { background: var(--c-ideas); }
.card[data-color="quotes"]  { background: var(--c-quotes); }
.card[data-color="sunny"]   { background: var(--c-sunny); }
.card[data-color="sea"]     { background: var(--c-sea); }
.card:not([data-color="default"]) { border-color: transparent; }

/* ---------- Colour palette popover ---------- */
.palette {
  position: absolute;
  bottom: 44px;
  right: 10px;
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-hover);
  z-index: 10;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
  transition: transform .12s;
}

.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--accent); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  color: var(--text-soft);
  margin-top: 12vh;
  font-size: 15px;
}

.empty-icon { font-size: 44px; margin-bottom: 10px; }
.empty-state a { color: var(--accent); }

/* ---------- Delete confirm ---------- */
.card.confirm-delete .card-text { opacity: .3; }

.confirm-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--text-soft);
}

.confirm-bar button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}

.confirm-yes { color: #eb4d3d; }
.confirm-no { color: var(--text); }
.confirm-bar button:hover { background: color-mix(in srgb, var(--text-soft) 18%, transparent); }

/* ---------- Small screens: icon-only toolbar ---------- */
@media (max-width: 640px) {
  .btn-label { display: none; }
  .btn { padding: 9px 11px; }
  .topbar { padding-left: 14px; padding-right: 8px; }
  .editor-wrap { padding: 2px 16px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .library-wrap { padding-left: 14px; padding-right: 14px; }
  .grid { column-width: 160px; column-gap: 10px; }
  .card { margin-bottom: 10px; padding: 13px 13px 8px; }
  .save-status { font-size: 11px; margin-right: 2px; }
}
