:root {
  --bg: #0b0b0d;
  --panel: #141418;
  --panel-2: #1b1b21;
  --line: #26262e;
  --text: #ececf1;
  --muted: #8b8b98;
  --accent: #8b7bff;
  --accent-2: #a597ff;
  --good: #2fbf71;
  --bad: #ef4a5a;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.muted { color: var(--muted); margin: 0 0 8px; }
.error { color: var(--bad); min-height: 1.5em; margin: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3a3a46; background: #22222a; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { color: #ff8692; }
.btn.danger:hover:not(:disabled) { background: rgba(239, 74, 90, 0.12); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.icon-btn { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.danger:hover { color: var(--bad); border-color: var(--bad); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }

/* inputs */
input:not([type=checkbox]):not([type=range]):not([type=color]), select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: #0f0f13; color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* layout */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 16px; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px; }
.tabs { display: flex; flex-direction: column; gap: 2px; }
.tab { text-align: left; padding: 9px 12px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.content { padding: 28px 32px 120px; max-width: 900px; width: 100%; }
.content h2 { margin: 0 0 20px; font-size: 22px; }

.group { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 14px; }
.group h3 { margin: 0; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.stack .field, .stack .grid { width: 100%; max-width: 440px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; color: #c5c5d0; font-weight: 500; }
.field-label output { color: var(--muted); font-weight: 400; }
.hint { font-size: 12px; color: var(--muted); }
.hint.block { display: block; }

.toggle { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { flex: none; width: 36px; height: 20px; margin-top: 1px; border-radius: 999px; background: #33333d; position: relative; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.color-row { display: flex; gap: 8px; }
.color-row input[type=color] { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #0f0f13; cursor: pointer; flex: none; }
.color-row .hex { font-family: ui-monospace, monospace; }

/* lists */
.list { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.list-item { width: 100%; display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #101014; }
.list-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.list-fields > div { display: flex; flex-direction: column; gap: 12px; }
.list-actions { display: flex; flex-direction: column; gap: 6px; }

/* media */
.media-pick { display: flex; gap: 12px; align-items: center; }
.media-pick-controls { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; align-items: flex-start; }
.preview { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 8px; background: #0f0f13; display: block; }
.preview.small { width: 64px; height: 64px; aspect-ratio: auto; flex: none; }
.preview.empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; border: 1px dashed var(--line); }
.preview-audio { width: 100%; height: 36px; }
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(139, 123, 255, 0.06); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.media-card { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #101014; }
.media-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.media-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; width: fit-content; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(139, 123, 255, 0.18); color: var(--accent-2); }
.pill.good { background: rgba(47, 191, 113, 0.18); color: var(--good); }
.pill.bad { background: rgba(239, 74, 90, 0.18); color: #ff8692; }
.qr { width: 200px; height: 200px; border-radius: 8px; background: #fff; }

/* big text + code */
textarea.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12.5px; line-height: 1.55; tab-size: 2; }
.field-foot { display: flex; justify-content: space-between; gap: 12px; }

/* theme presets */
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 18px; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}
.preset:hover { transform: translateY(-2px); border-color: #4a4a58; }
.preset-swatches { display: flex; gap: 4px; }
.preset-swatches i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.2); }
.preset-name { font-weight: 600; font-size: 13px; }

/* blocks / sections editor */
.sections { display: flex; flex-direction: column; gap: 8px; }
.section-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #101014;
}
.section-row.off { opacity: 0.55; }
.section-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-controls select { width: auto; padding: 6px 8px; }
.page-tag { flex-basis: 100%; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-2); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #c5c5d0; cursor: pointer; }
.check input { accent-color: var(--accent); }

/* lyrics */
.lyrics-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #0d0d11; }
.lyrics-box summary { cursor: pointer; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.lyrics-box[open] summary { margin-bottom: 12px; }
.lyrics-box .stack .field { max-width: none; }
.finder-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lyrics-results { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.lyrics-results:empty { display: none; }
.lyrics-result { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #141418; flex-wrap: wrap; }
.lr-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 220px; }
.lr-text strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-tags { display: flex; gap: 6px; flex-wrap: wrap; }

/* save bar + toasts */
.savebar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 18px; padding: 10px 10px 10px 18px;
  background: #1d1d24; border: 1px solid #34343f; border-radius: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  width: max-content; max-width: calc(100% - 32px);
}
.savebar div { display: flex; gap: 8px; }
.toasts { position: fixed; top: 16px; right: 16px; z-index: 30; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100% - 32px)); }
.toast { padding: 12px 14px; border-radius: 10px; background: #1d1d24; border: 1px solid #34343f; border-left: 4px solid var(--good); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); }
.toast.bad { border-left-color: var(--bad); }
.toast ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .tabs { flex-direction: row; overflow-x: auto; }
  .tab { white-space: nowrap; }
  .tab.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .sidebar-foot { flex-direction: row; }
  .content { padding: 20px 16px 120px; }
  .savebar { flex-direction: column; gap: 8px; padding: 12px; }
}

/* live preview */
.app.with-preview { grid-template-columns: 230px minmax(0, 1fr) minmax(360px, 34vw); }
.preview-pane { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #08080a; }
.preview-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.preview-actions { margin-left: auto; display: flex; gap: 6px; }
.preview-actions .btn.active { border-color: var(--accent); color: #fff; background: rgba(139, 123, 255, 0.18); }
.preview-box { position: relative; flex: 1; overflow: hidden; }
.preview-box iframe {
  position: absolute; top: 0; left: 0; border: 0; transform-origin: top left; background: #000;
  border-radius: 14px; box-shadow: 0 0 0 1px var(--line), 0 30px 80px -30px rgba(0, 0, 0, 0.9);
}
.preview-box iframe[data-device="phone"] { border-radius: 44px; box-shadow: 0 0 0 10px #17171c, 0 0 0 11px var(--line), 0 30px 80px -30px rgba(0, 0, 0, 0.9); }
/* the next version loads underneath, out of sight, and is swapped in once it has drawn */
.preview-box iframe.loading { visibility: hidden; }
@media (max-width: 1100px) {
  .app.with-preview { grid-template-columns: 1fr; }
  .preview-pane { position: fixed; inset: 0; z-index: 25; height: 100%; border-left: 0; }
}

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.25); flex: none; }
.fresh-invites { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--accent); border-radius: 10px; background: rgba(139, 123, 255, 0.08); }
.fresh-invite { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fresh-invite .invite-link { flex: 1 1 260px; font-family: ui-monospace, monospace; font-size: 12px; }

.subgroup { display: flex; flex-direction: column; gap: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }

/* media thumbnails: same size whatever the file's shape (tall phone screenshots, vertical videos…) */
.media-card .preview, .preview:not(.small):not(.preview-audio) {
  width: 100%; height: 130px; aspect-ratio: auto; object-fit: cover; object-position: center;
}
.media-card { justify-content: space-between; }
.media-card .btn { margin-top: auto; }

.official-row { display: flex; gap: 8px; flex-wrap: wrap; }
.official-pill { background: transparent; border: 1px solid currentColor; color: var(--text); }
.badge-grants { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.plan-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.plan-check { padding-right: 12px; border-right: 1px solid rgba(255, 255, 255, 0.1); font-weight: 600; }

/* header: title + search + undo/redo */
.content-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 20px; position: sticky; top: 0; z-index: 20; padding: 12px 0; background: linear-gradient(var(--bg) 75%, transparent); }
.content-head h2 { margin: 0; flex: 1; min-width: 140px; }
.head-tools { display: flex; align-items: center; gap: 6px; }
.head-tools .icon-btn { font-size: 16px; }
.search-wrap { position: relative; }
#settings-search { width: 230px; padding: 7px 64px 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); outline: none; }
#settings-search:focus { border-color: var(--accent); }
.search-kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; pointer-events: none; }
#settings-search:focus + .search-kbd { display: none; }
.search-results { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; max-width: 80vw; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 20px 50px -20px #000; z-index: 30; }
.search-hit { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: none; text-align: left; cursor: pointer; }
.search-hit.active, .search-hit:hover { background: var(--panel-2); }
.search-label { font-weight: 600; }
.search-where { font-size: 12px; color: var(--muted); }
.search-none { margin: 8px; color: var(--muted); font-size: 13px; }
@media (max-width: 700px) { #settings-search { width: 160px; } .search-kbd { display: none; } }

/* jump-to-setting highlight */
.flash { animation: flash 1.6s ease-out; border-radius: 8px; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent); background: rgba(139, 123, 255, 0.12); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* back-to-default arrow next to a changed setting */
.reset-btn { margin-left: 6px; padding: 0 5px; border: 0; border-radius: 5px; background: none; color: var(--muted); font-size: 13px; line-height: 1.4; cursor: pointer; vertical-align: 1px; }
.reset-btn:hover, .reset-btn:focus-visible { color: var(--text); background: var(--panel-2); }

.preset-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ───────── stats */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-tile { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.chart-plot { position: relative; height: 180px; margin: 6px 0 0 34px; }
.chart-grid { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.grid-line { position: relative; border-top: 1px solid var(--line); height: 0; }
.grid-line span { position: absolute; right: calc(100% + 8px); top: -8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.bar-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; padding: 0 1px; outline: none; cursor: default; }
.bar { width: min(100%, 24px); min-height: 0; background: var(--accent); border-radius: 4px 4px 0 0; transition: filter 0.15s; }
.bar.zero { height: 2px !important; background: var(--line); border-radius: 0; }
.bar-slot:hover .bar, .bar-slot:focus-visible .bar { filter: brightness(1.25); }
.bar-slot:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); border-radius: 4px; }
.chart-tip {
  position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12px; white-space: nowrap; pointer-events: none;
}
.chart-tip span { color: var(--muted); }
.chart-axis { display: flex; justify-content: space-between; margin: 6px 0 0 34px; font-size: 11px; color: var(--muted); }
.chart-table { margin-top: 12px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.chart-table table { margin-top: 8px; border-collapse: collapse; font-size: 13px; }
.chart-table td, .chart-table th { padding: 4px 16px 4px 0; text-align: left; font-variant-numeric: tabular-nums; }
.chart-table th { color: var(--muted); font-weight: 500; }
.click-list { display: flex; flex-direction: column; gap: 10px; }
.click-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr auto; align-items: center; gap: 12px; }
.click-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.click-track { height: 8px; }
.click-bar { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.click-count { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.bad-text { color: var(--bad); }
