/* =========================
   NOTES — same design language as the main EsSelqm app.
   THEMES: each theme is one block of color tokens (identical palette to
   the main app). The active theme is set as <html data-theme="…">.
   Selectors are attribute-only so the theme preview cards in Settings
   can show their own colors. Brown is the default.
   ========================= */
:root,
[data-theme="brown"] {
  color-scheme: dark;
  --bg: #1e1b18;  --panel: #2a2521;  --panel-2: #322c27;  --hover: #3a322c;  --border: #3a332d;
  --text: #f2e9e4;  --muted: #c9b8a8;
  --accent: #d4a373;  --accent-soft: rgba(212, 163, 115, 0.14);  --accent-line: rgba(212, 163, 115, 0.35);  --on-accent: #2a1d12;
  --danger: #e07a6a;  --shadow: rgba(0, 0, 0, 0.35);  --backdrop: rgba(0, 0, 0, 0.6);
  --player-end: #221e1b;  --cover-1: #3b2f2a;  --cover-2: #1f1a17;  --footer-bg: #1a1715;  --toast-bg: #3d342d;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;  --panel: #1e1e1e;  --panel-2: #262626;  --hover: #2f2f2f;  --border: #333333;
  --text: #ededed;  --muted: #a8a8a8;
  --accent: #8ab4f8;  --accent-soft: rgba(138, 180, 248, 0.14);  --accent-line: rgba(138, 180, 248, 0.4);  --on-accent: #0d1b2e;
  --danger: #f28b82;  --shadow: rgba(0, 0, 0, 0.5);  --backdrop: rgba(0, 0, 0, 0.65);
  --player-end: #181818;  --cover-1: #2c2c2c;  --cover-2: #151515;  --footer-bg: #0d0d0d;  --toast-bg: #2b2b2b;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;  --panel: #ffffff;  --panel-2: #eceef2;  --hover: #e3e6eb;  --border: #d6dae0;
  --text: #1f2328;  --muted: #5b6470;
  --accent: #2563eb;  --accent-soft: rgba(37, 99, 235, 0.1);  --accent-line: rgba(37, 99, 235, 0.35);  --on-accent: #ffffff;
  --danger: #c62828;  --shadow: rgba(20, 30, 50, 0.12);  --backdrop: rgba(20, 25, 35, 0.35);
  --player-end: #f6f7f9;  --cover-1: #e6ebf5;  --cover-2: #cfd8ea;  --footer-bg: #e9ebef;  --toast-bg: #ffffff;
}

[data-theme="orange"] {
  color-scheme: dark;
  --bg: #18191b;  --panel: #222326;  --panel-2: #2a2c30;  --hover: #33363a;  --border: #34373c;
  --text: #f2f2f2;  --muted: #b5b8bd;
  --accent: #ff9a3c;  --accent-soft: rgba(255, 154, 60, 0.14);  --accent-line: rgba(255, 154, 60, 0.4);  --on-accent: #2a1300;
  --danger: #ff8a80;  --shadow: rgba(0, 0, 0, 0.45);  --backdrop: rgba(0, 0, 0, 0.6);
  --player-end: #1c1d1f;  --cover-1: #3d2a1a;  --cover-2: #1a1410;  --footer-bg: #121314;  --toast-bg: #2d2f33;
}

[data-theme="peach"] {
  color-scheme: light;
  --bg: #fff2e8;  --panel: #fffaf6;  --panel-2: #ffe8d6;  --hover: #ffdec6;  --border: #f1d3bd;
  --text: #3b2417;  --muted: #7a5442;
  --accent: #c2410c;  --accent-soft: rgba(194, 65, 12, 0.1);  --accent-line: rgba(194, 65, 12, 0.35);  --on-accent: #ffffff;
  --danger: #b42318;  --shadow: rgba(120, 60, 20, 0.15);  --backdrop: rgba(60, 30, 10, 0.35);
  --player-end: #fff6ef;  --cover-1: #ffe2cc;  --cover-2: #f8c9a6;  --footer-bg: #ffe9da;  --toast-bg: #fffaf6;
}

[data-theme="green"] {
  color-scheme: dark;
  --bg: #142019;  --panel: #1c2b22;  --panel-2: #233529;  --hover: #2b4033;  --border: #2b3d31;
  --text: #e9f3ec;  --muted: #a9c2b2;
  --accent: #7fd49b;  --accent-soft: rgba(127, 212, 155, 0.14);  --accent-line: rgba(127, 212, 155, 0.4);  --on-accent: #0d2615;
  --danger: #ff9a8f;  --shadow: rgba(0, 0, 0, 0.4);  --backdrop: rgba(0, 10, 5, 0.6);
  --player-end: #17241c;  --cover-1: #2a4434;  --cover-2: #12201a;  --footer-bg: #101a14;  --toast-bg: #24382b;
}

[data-theme="mint"] {
  color-scheme: light;
  --bg: #eef6f0;  --panel: #ffffff;  --panel-2: #e2efe6;  --hover: #d6e9dc;  --border: #cfe0d4;
  --text: #17301f;  --muted: #4f6b58;
  --accent: #23774a;  --accent-soft: rgba(35, 119, 74, 0.1);  --accent-line: rgba(35, 119, 74, 0.35);  --on-accent: #ffffff;
  --danger: #b3261e;  --shadow: rgba(20, 60, 35, 0.12);  --backdrop: rgba(10, 30, 20, 0.35);
  --player-end: #f3f9f5;  --cover-1: #d8ecdf;  --cover-2: #bcdcc7;  --footer-bg: #e3efe7;  --toast-bg: #ffffff;
}

[data-theme="blue"] {
  color-scheme: dark;
  --bg: #0f1a2b;  --panel: #16243a;  --panel-2: #1c2d47;  --hover: #243857;  --border: #24375a;
  --text: #eaf1fb;  --muted: #a7b8d0;
  --accent: #6cb4ff;  --accent-soft: rgba(108, 180, 255, 0.14);  --accent-line: rgba(108, 180, 255, 0.4);  --on-accent: #06203d;
  --danger: #ff8f8f;  --shadow: rgba(0, 0, 0, 0.45);  --backdrop: rgba(0, 5, 15, 0.6);
  --player-end: #121f33;  --cover-1: #24406a;  --cover-2: #0e1a2c;  --footer-bg: #0b1422;  --toast-bg: #1f3150;
}

[data-theme="sky"] {
  color-scheme: light;
  --bg: #eef4fb;  --panel: #ffffff;  --panel-2: #e1ecf8;  --hover: #d4e4f5;  --border: #cddcee;
  --text: #142336;  --muted: #4c607a;
  --accent: #1d6fd1;  --accent-soft: rgba(29, 111, 209, 0.1);  --accent-line: rgba(29, 111, 209, 0.35);  --on-accent: #ffffff;
  --danger: #c0262d;  --shadow: rgba(20, 40, 80, 0.12);  --backdrop: rgba(10, 25, 50, 0.35);
  --player-end: #f3f8fd;  --cover-1: #d9e7f7;  --cover-2: #b9d1ee;  --footer-bg: #e3edf8;  --toast-bg: #ffffff;
}

[data-theme="slate"] {
  color-scheme: dark;
  --bg: #415669;  --panel: #4b6176;  --panel-2: #556c82;  --hover: #5f778e;  --border: #62798f;
  --text: #f4f8fb;  --muted: #d5e0ea;
  --accent: #b0e8dd;  --accent-soft: rgba(176, 232, 221, 0.16);  --accent-line: rgba(176, 232, 221, 0.45);  --on-accent: #1f3a40;
  --danger: #ffb4a8;  --shadow: rgba(15, 25, 35, 0.3);  --backdrop: rgba(20, 30, 40, 0.55);
  --player-end: #44596d;  --cover-1: #5a7489;  --cover-2: #3b5062;  --footer-bg: #3a4e60;  --toast-bg: #2f4252;
}

[data-theme="purple"] {
  color-scheme: dark;
  --bg: #1c1626;  --panel: #261e33;  --panel-2: #2e2540;  --hover: #382d4d;  --border: #3a2f4d;
  --text: #f1ecf8;  --muted: #bfb3d1;
  --accent: #c3a6ff;  --accent-soft: rgba(195, 166, 255, 0.14);  --accent-line: rgba(195, 166, 255, 0.4);  --on-accent: #261447;
  --danger: #ff9aa8;  --shadow: rgba(0, 0, 0, 0.45);  --backdrop: rgba(5, 0, 15, 0.6);
  --player-end: #201a2c;  --cover-1: #3d2f57;  --cover-2: #1a1424;  --footer-bg: #16111f;  --toast-bg: #33294a;
}

[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f4ecd8;  --panel: #fbf6e9;  --panel-2: #efe4cb;  --hover: #e8dcc0;  --border: #dccdaa;
  --text: #3b2f22;  --muted: #6e5d48;
  --accent: #a0522d;  --accent-soft: rgba(160, 82, 45, 0.12);  --accent-line: rgba(160, 82, 45, 0.35);  --on-accent: #fff8ee;
  --danger: #b3261e;  --shadow: rgba(80, 60, 30, 0.15);  --backdrop: rgba(60, 45, 25, 0.35);
  --player-end: #f1e7cf;  --cover-1: #e9dcbc;  --cover-2: #d8c69c;  --footer-bg: #ebe0c5;  --toast-bg: #fbf6e9;
}

[data-theme="contrast"] {
  color-scheme: dark;
  --bg: #000000;  --panel: #0d0d0d;  --panel-2: #1a1a1a;  --hover: #262626;  --border: #5c5c5c;
  --text: #ffffff;  --muted: #e0e0e0;
  --accent: #ffd60a;  --accent-soft: rgba(255, 214, 10, 0.16);  --accent-line: #ffd60a;  --on-accent: #000000;
  --danger: #ff6b6b;  --shadow: rgba(0, 0, 0, 0.6);  --backdrop: rgba(0, 0, 0, 0.75);
  --player-end: #000000;  --cover-1: #1f1f1f;  --cover-2: #000000;  --footer-bg: #000000;  --toast-bg: #1a1a1a;
}

:root { --radius: 12px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ic { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* =========================
   LAYOUT
   ========================= */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}

.list-pane {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 16px;
  overscroll-behavior: contain;
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  text-align: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--footer-bg);
}
footer a { text-decoration: none; font-weight: 600; }
footer a:hover { text-decoration: underline; }

/* =========================
   HEADER
   ========================= */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, var(--panel), var(--player-end));
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 2;
}

.logo {
  width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cover-1), var(--cover-2));
  border: 1px solid var(--border);
  color: var(--accent);
}
.logo .ic { width: 22px; height: 22px; }

.brand-text { flex: 1; min-width: 0; }
.brand-text h1 {
  margin: 0; font-size: 16px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-text p {
  margin: 2px 0 0; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: 44px; height: 44px;
  background: transparent; border: 0; border-radius: 50%;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, transform 0.08s;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--accent); }
.icon-btn:active:not(:disabled) { transform: scale(0.94); }

/* =========================
   TOOLBAR + LIST
   ========================= */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input {
  flex: 1; min-width: 0;
  padding: 11px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  outline: none;
}
.toolbar input:focus { border-color: var(--accent-line); }
.toolbar input::placeholder { color: var(--muted); opacity: 0.8; }

.primary-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border: 0; border-radius: 20px;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
  white-space: nowrap;
}
.primary-btn .ic { width: 18px; height: 18px; }
.primary-btn:hover { filter: brightness(1.08); }

.note-list { display: flex; flex-direction: column; gap: 10px; }

.note-card {
  display: flex; align-items: stretch;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.note-card:hover { border-color: var(--accent-line); }
.note-card.active { background: var(--accent-soft); border-color: var(--accent-line); }

.card-hit {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
  padding: 11px 4px 11px 12px;
  background: transparent; border: 0; text-align: left;
}
.card-top { display: flex; align-items: baseline; gap: 10px; }
.card-title {
  flex: 1; min-width: 0; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-date { flex: none; font-size: 11px; color: var(--muted); }
.card-snippet {
  font-size: 12.5px; line-height: 1.45; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-del { min-width: 44px; height: auto; margin: 4px 4px 4px 0; border-radius: 8px; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px;
}
.empty .ic { width: 34px; height: 34px; opacity: 0.55; }

/* =========================
   EDITOR (full-screen overlay)
   ========================= */
.editor {
  position: fixed; inset: 0; z-index: 900;
  display: flex; flex-direction: column;
  max-width: 760px; margin: 0 auto;
  background: var(--bg);
  opacity: 0; transform: translateY(16px);
  transition: opacity 0.2s, transform 0.2s;
}
.editor.open { opacity: 1; transform: none; }

.editor-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--player-end));
}
.save-state { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.save-state.is-saving { color: var(--accent); }
.save-state.is-error { color: var(--danger); }

.editor-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.note-title {
  flex: none;
  background: transparent; border: 0; outline: none;
  font-size: 18px; font-weight: 700;
  padding: 4px 0;
}
.note-title::placeholder { color: var(--muted); opacity: 0.7; }
.note-text {
  flex: 1; min-height: 260px;
  background: transparent; border: 0; outline: none; resize: none;
  font-size: 15px; line-height: 1.65;
  padding: 2px 0;
}
.note-text::placeholder { color: var(--muted); opacity: 0.7; }

/* =========================
   SHEETS
   ========================= */
.sheet {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: flex-end; justify-content: center;
  background: transparent; backdrop-filter: blur(0);
  transition: background 0.25s, backdrop-filter 0.25s;
}
.sheet.open { background: var(--backdrop); backdrop-filter: blur(4px); }

.sheet-body {
  width: 100%; max-width: 640px; max-height: 85vh; max-height: 85dvh;
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px var(--shadow);
  transform: translateY(100%); transition: transform 0.25s ease-out;
}
.sheet.open .sheet-body { transform: translateY(0); }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-scroll { overflow-y: auto; flex: 1; padding-right: 4px; }

.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: 0; }
.setting > div { min-width: 0; }
.setting span { display: block; font-size: 15px; font-weight: 500; }
.setting p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.setting-block { padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting-title { display: block; font-size: 15px; font-weight: 500; }
.setting-desc { margin: 3px 0 10px; font-size: 12px; color: var(--muted); }

/* buttons */
.secondary-btn {
  flex: none;
  display: inline-block;
  padding: 8px 14px; border-radius: 8px;
  background: transparent; border: 1px solid var(--accent-line); color: var(--accent);
  text-decoration: none;
}
.secondary-btn:hover { background: var(--accent-soft); }
.danger-btn {
  flex: none;
  padding: 8px 14px; border-radius: 8px;
  background: transparent; border: 1px solid var(--danger); color: var(--danger);
}
.danger-btn:hover { background: rgba(0, 0, 0, 0.06); }

.confirm-text { margin: 6px 0 14px; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.theme-swatch {
  position: relative;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px;
  background: var(--bg); color: var(--text);
  border: 2px solid var(--border); border-radius: 10px;
  text-align: left;
}
.theme-swatch:hover { border-color: var(--accent-line); }
.theme-swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatch-preview {
  display: flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 6px;
  background: var(--panel-2); border-radius: 6px;
}
.swatch-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); flex: none; }
.swatch-line { flex: 1; height: 4px; border-radius: 2px; background: var(--muted); opacity: 0.7; }
.swatch-name { font-size: 13px; font-weight: 600; }
.theme-swatch .ic { position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; color: var(--accent); display: none; }
.theme-swatch[aria-pressed="true"] .ic { display: block; }

/* =========================
   TOAST
   ========================= */
.toast {
  position: fixed; left: 50%; bottom: calc(60px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: 90vw; padding: 10px 16px;
  background: var(--toast-bg); border: 1px solid var(--accent-line); border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 16px var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
  z-index: 2000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 400px) {
  .icon-btn { min-width: 40px; }
  .primary-btn { padding: 9px 12px; }
}

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