/* plankit — dark, minimal, one confident accent. */

/* Light theme is the default; dark is opt-in via <html data-theme="dark">. */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --border: #e3e5ef;
  --text: #1b1c24;
  --muted: #6a6d7d;
  --accent: #6b5cf0;
  --accent-soft: rgba(107, 92, 240, 0.13);
  --danger: #e5484d;
  --radius: 14px;
  --shadow: 0 14px 38px rgba(35, 35, 70, 0.10);
  --topbar-bg: rgba(255, 255, 255, 0.72);
  --btn-hover: #e2e4f0;
  --glow:
    radial-gradient(900px 520px at 84% -14%, rgba(107, 92, 240, 0.18), transparent 60%),
    radial-gradient(680px 460px at -5% 2%, rgba(255, 120, 170, 0.12), transparent 55%);
  --maxw: 1100px;
}

:root[data-theme="dark"] {
  --bg: #0c0c0f;
  --surface: #15151a;
  --surface-2: #1c1c23;
  --border: #26262f;
  --text: #e9e9ee;
  --muted: #8b8b97;
  --accent: #7c6cff;
  --accent-soft: rgba(124, 108, 255, 0.16);
  --danger: #ff5d62;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  --topbar-bg: rgba(12, 12, 15, 0.78);
  --btn-hover: #24242d;
  --glow:
    radial-gradient(900px 520px at 84% -14%, rgba(124, 108, 255, 0.20), transparent 60%),
    radial-gradient(680px 460px at -5% 2%, rgba(255, 90, 140, 0.09), transparent 55%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* subtle ambient glow */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--glow);
  pointer-events: none;
  z-index: 0;
}

button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(1px); }
.btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px var(--accent-soft);
}
.btn--accent:hover { filter: brightness(1.07); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn--danger:hover { filter: brightness(1.08); }
.btn--ghost { background: transparent; }

/* ── Brand ─────────────────────────────────────────────────────────────── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 18px;
  color: var(--text);
  background: none;
  border: none;
  padding: 0;
}
.brand--big { font-size: 30px; }
.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
}
.brand--big .dot { width: 16px; height: 16px; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}
.login-card .muted { margin: -4px 0 6px; }
.tagline { margin: -4px 0 8px; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.etym {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.etym em { font-style: italic; color: var(--accent); }
.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px max(20px, env(safe-area-inset-left)) 14px 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.search {
  flex: 1;
  min-width: 0;
  max-width: 440px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  color: var(--text);
  outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search::placeholder { color: var(--muted); }

/* ── Composer ──────────────────────────────────────────────────────────── */
.composer {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 22px auto 6px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.composer-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.folder-input {
  flex: 1;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  outline: none;
}
.folder-input:focus { border-color: var(--accent); }
.composer-actions { display: flex; gap: 10px; }
.dump {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
  outline: none;
  min-height: 52px;
}
.dump:focus { border-color: var(--accent); }

/* ── Views ─────────────────────────────────────────────────────────────── */
.view {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 10px auto 80px;
  padding: 0 20px;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 2px 14px;
}
.section-title h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0; letter-spacing: 0.01em; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 70px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Folder grid */
.grid-folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.folder-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.folder-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 10px 26px var(--accent-soft);
}
.folder-card .ficon { font-size: 22px; }
.folder-card .fname { font-weight: 600; margin-top: 10px; word-break: break-word; }
.folder-card .fmeta { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Item grid */
.grid-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.1s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 22px var(--accent-soft); }

.card .thumb {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: var(--surface-2);
  cursor: zoom-in;
  display: block;
}
.card .file-face {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  font-size: 40px;
  background: var(--surface-2);
  cursor: pointer;
}
.card .text-body {
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  max-height: 220px;
  overflow: auto;
  flex: 1;
}

/* Text notes span the full modal width and read like a document block.
   They expand to their full height so the modal body is the only scrollbar. */
.card--text { grid-column: 1 / -1; }
.card--text .text-body {
  max-height: none;
  overflow: visible;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  padding: 16px 18px;
}

/* Rendered Markdown in note bodies */
.text-body p { margin: .5em 0; white-space: pre-wrap; }
.text-body h1, .text-body h2, .text-body h3,
.text-body h4, .text-body h5, .text-body h6 { margin: .6em 0 .3em; line-height: 1.25; }
.text-body h1 { font-size: 1.4em; }
.text-body h2 { font-size: 1.25em; }
.text-body h3 { font-size: 1.1em; }
.text-body ul, .text-body ol { margin: .5em 0; padding-left: 1.4em; }
.text-body li { margin: .15em 0; }
.text-body a { color: var(--accent); text-decoration: underline; }
.text-body blockquote { margin: .6em 0; padding: .2em .9em; border-left: 3px solid var(--accent); opacity: .9; }
.text-body hr { border: none; border-top: 1px solid currentColor; opacity: .2; margin: 1em 0; }
.text-body code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: .9em; padding: .1em .35em; border-radius: 6px;
  background: rgba(127, 127, 127, .16);
}
.text-body pre {
  margin: .6em 0; padding: 14px 16px; border-radius: 12px; overflow-x: auto;
  background: rgba(127, 127, 127, .12);
}
.text-body pre code { background: none; padding: 0; font-size: .85em; }

/* Collapsible header with the note's name */
.text-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  user-select: none;
  background: linear-gradient(90deg, var(--accent-soft), rgba(124, 108, 255, 0.04) 55%, transparent 85%);
  transition: background 0.15s ease;
}
.text-head:hover {
  background: linear-gradient(90deg, rgba(124, 108, 255, 0.30), rgba(124, 108, 255, 0.08) 55%, transparent 90%);
}
.caret {
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
  flex: none;
}
.text-title {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Collapsed: hide body + footer, rotate the caret, drop the header border */
.card--text.collapsed .text-body,
.card--text.collapsed .meta { display: none; }
.card--text.collapsed .text-head { border-bottom: none; }
.card--text.collapsed .caret { transform: rotate(-90deg); }

/* Inline editor (name + content) */
.text-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}
.text-editor .text-name-input,
.text-editor .text-edit {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
.text-editor .text-name-input:focus,
.text-editor .text-edit:focus { border-color: var(--accent); }
.text-editor .text-edit {
  min-height: 240px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}
.edit-actions { display: flex; gap: 10px; justify-content: flex-end; }
.card .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}
.card .meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* hover controls (delete / copy) */
.card-tools, .folder-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.card:hover .card-tools, .folder-card:hover .folder-tools { opacity: 1; }
/* Touch devices have no hover, so always show the controls (delete, share, etc.). */
@media (hover: none) {
  .card-tools, .folder-tools { opacity: 1; }
}
.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon-btn.copy:hover { background: var(--accent); border-color: var(--accent); }

/* ── Drag overlay ──────────────────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(12, 12, 15, 0.86);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.drop-overlay div {
  border: 2px dashed var(--accent);
  border-radius: 18px;
  padding: 50px 70px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

/* ── Folder modal ──────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 6, 8, 0.7);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
}
/* Animate only the card (transform/opacity = GPU-friendly). The blurred
   overlay appears instantly so the backdrop-filter isn't recomputed per frame. */
.modal-card {
  width: min(1000px, 94vw);
  height: min(860px, 90vh);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform, opacity;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-composer-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 26px;
}

@media (max-width: 560px) {
  .modal { padding: 0; }
  .modal-card { width: 100vw; height: 100dvh; border-radius: 0; border: none; }
  .modal-composer-actions .btn { flex: 1; }
}

/* ── Lightbox ──────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.9);
  display: grid;
  place-items: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.lb-stage { max-width: 92vw; max-height: 88vh; display: flex; align-items: center; justify-content: center; }
.lb-img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 8px; }
.lb-frame { width: 92vw; height: 88vh; border: none; border-radius: 8px; background: #fff; }
.lb-audio { width: min(92vw, 520px); }
.lb-close, .lb-nav {
  position: absolute; background: rgba(0, 0, 0, 0.45); color: #fff; border: none;
  cursor: pointer; border-radius: 999px; line-height: 1;
}
.lb-close { top: 18px; right: 18px; width: 40px; height: 40px; font-size: 18px; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 28px; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lb-counter { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; opacity: 0.85; }

/* ── Toasts ────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: rise 0.2s ease;
}
.toast.err { border-color: var(--danger); color: #ffd2d3; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ── App footer (tagline) ──────────────────────────────────────────────── */
.app-footer {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 24px auto 48px;
  padding: 18px 20px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.app-footer .dot { width: 9px; height: 9px; flex: none; box-shadow: none; }
.app-footer strong { color: var(--text); font-weight: 700; }
.app-footer em { color: var(--accent); font-style: italic; }

/* ── Folder rename (inline) ────────────────────────────────────────────── */
.folder-card .rename-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  outline: none;
}

/* ── Confirm dialog ────────────────────────────────────────────────────── */
.confirm {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 8, 14, 0.55);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.confirm-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: pop 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.confirm-card h3 { margin: 0 0 8px; font-size: 18px; letter-spacing: -0.01em; }
.confirm-card p { margin: 0 0 20px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Share dialog */
.share-card { width: min(540px, 100%); }
.share-create { display: flex; gap: 10px; margin-bottom: 16px; }
.share-expiry {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  outline: none;
}
.share-expiry:focus { border-color: var(--accent); }
.share-list { display: flex; flex-direction: column; gap: 10px; max-height: 280px; overflow: auto; margin-bottom: 18px; }
.share-empty { font-size: 14px; }
.share-row { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.share-row-top { display: flex; gap: 8px; align-items: center; }
.share-url {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 12.5px;
}
.share-exp { font-size: 12px; margin-top: 6px; }

/* ── Trash view ────────────────────────────────────────────────────────── */
.modal--trash .modal-composer { display: none; }
.trash-list { display: flex; flex-direction: column; gap: 10px; }
.trash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.trash-info { min-width: 0; }
.trash-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta { font-size: 12.5px; text-transform: capitalize; margin-top: 2px; }
.trash-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.result-row { cursor: pointer; transition: border-color 0.12s ease, transform 0.08s ease; }
.result-row:hover { border-color: var(--accent); transform: translateY(-1px); }

/* Toast action (Undo) */
.toast { display: flex; align-items: center; gap: 12px; }
.toast-action {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  padding: 0;
}
:root[data-theme="dark"] .toast-action { color: #b3a8ff; }

/* ── Install hint (PWA) ────────────────────────────────────────────────── */
.install-banner {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 14px auto 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 12px;
  font-size: 14px;
}
.install-actions { display: flex; gap: 8px; flex: none; }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .brand { font-size: 16px; }
  /* Top bar: brand + buttons on row 1, search drops to a full-width row 2. */
  .topbar { flex-wrap: wrap; gap: 10px; }
  .brand { margin-right: auto; }
  .topbar .btn { padding: 8px 12px; }
  .search { order: 5; flex-basis: 100%; max-width: none; margin: 2px 0 0; }
  .composer-actions { width: 100%; }
  .composer-actions .btn { flex: 1; }
  .grid-folders { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .grid-items { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .install-banner { flex-direction: column; align-items: stretch; }
  .install-actions .btn { flex: 1; }
}

/* highlight.js palette — light (default) */
:root {
  --hl-fg: #1b1c24; --hl-comment: #6a737d; --hl-keyword: #d73a49;
  --hl-string: #032f62; --hl-number: #005cc5; --hl-title: #6f42c1; --hl-attr: #22863a;
}
:root[data-theme="dark"] {
  --hl-fg: #e9e9ee; --hl-comment: #8b949e; --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff; --hl-number: #79c0ff; --hl-title: #d2a8ff; --hl-attr: #7ee787;
}
