:root {
  --bg: #101418;
  --surface: #1a2027;
  --surface-2: #232b34;
  --text: #e9eef3;
  --muted: #93a1af;
  --accent: #4ea1ff;
  --accent-text: #06131f;
  --error: #ff8a80;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }

.screen { max-width: 960px; margin: 0 auto; padding: env(safe-area-inset-top) 16px 32px; }
.screen.center { display: grid; place-items: center; min-height: 100dvh; }
.card { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 440px; }
.card h1 { margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 20px; cursor: pointer;
  background: var(--surface-2); text-decoration: none; color: var(--text); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; padding: 16px; font-size: 1.05rem; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:hover { background: rgba(255,255,255,.08); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 4px; }
.top h1 { font-size: 1.4rem; margin: 0; }
.top-actions { display: flex; gap: 4px; }

.quota { display: flex; flex-direction: column-reverse; gap: 4px; margin: 2px 0 8px; color: var(--muted); font-size: .85rem; }
.quota-bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.quota-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.quota.warn .quota-fill { background: var(--error); }
.quota.warn .quota-text { color: var(--error); }
.tools { align-items: center; flex-wrap: wrap; }
.ai-status { color: var(--muted); font-size: .9rem; margin-right: auto; }
.ai-status.done { color: #8fd18f; font-weight: 600; }
.ai-status.has-failed { cursor: pointer; text-decoration: underline dotted; }
.lib-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lib-row p { margin: 6px 0; }
.lib-buttons { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.link-btn { border: 0; background: none; padding: 2px 0; color: var(--accent); cursor: pointer; font-size: .85rem; }
.link-btn:disabled { color: var(--muted); cursor: default; }
.ai-search { display: flex; gap: 8px; margin-bottom: 6px; }
.ai-search input { flex: 1; min-width: 0; border: 0; border-radius: 10px; background: var(--surface); padding: 11px 12px; }
.ai-search .btn { margin: 0; }
.ai-result:not(:empty) { margin: 8px 0 16px; }
.card-note { background: var(--surface); border-radius: var(--radius); padding: 4px 14px 8px; margin-bottom: 16px; }
.link-danger { border: 0; background: none; padding: 0; color: var(--error); text-decoration: underline; cursor: pointer; }
.seg { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.seg button { border: 0; border-radius: 999px; padding: 7px 14px; background: var(--surface); cursor: pointer; }
.seg button.active { background: var(--surface-2); outline: 2px solid var(--accent); }
.clusters { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.cluster { background: var(--surface); border-radius: var(--radius); padding: 12px; }
.cluster.done { opacity: .7; }
.cluster .faces { display: flex; flex-wrap: wrap; gap: 6px; }
.face { width: 72px; height: 72px; border: 0; padding: 0; border-radius: 10px; background: var(--surface-2) no-repeat; cursor: pointer; transition: opacity .2s; }
.face.gone { opacity: .15; }
.cluster-head { margin: 8px 0 6px; }
.cluster-form { display: flex; gap: 6px; flex-wrap: wrap; }
.cluster-form input { flex: 1 1 160px; min-width: 0; border: 0; border-radius: 10px; background: var(--surface-2); padding: 9px 12px; }
.cluster-form .btn { margin: 0; }
.tabs { display: flex; gap: 8px; margin: 8px 0 12px; }
.tab { flex: 1; min-width: 0; padding-inline: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; border-radius: 999px; padding: 10px; background: var(--surface); cursor: pointer; font-weight: 600; }
.tab.active { background: var(--accent); color: var(--accent-text); }

.toolbar { display: flex; gap: 8px; margin: 0 0 12px; }
.toolbar input, .toolbar select { border: 0; border-radius: 10px; background: var(--surface); padding: 9px 12px; min-width: 0; }
.toolbar input { flex: 1; }
.toolbar select { flex: 0 0 auto; max-width: 45%; }
.lazy-thumb { display: block; width: 100%; height: 100%; }
.lazy-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 12px; color: var(--muted); }
.crumbs:empty { display: none; }
.crumbs button { border: 0; background: none; padding: 4px 2px; cursor: pointer; color: var(--accent); }
.crumbs span.current { color: var(--text); font-weight: 600; }

.loading, .empty { color: var(--muted); padding: 32px 0; text-align: center; }
.loading.more { padding: 8px 0 16px; font-size: .9em; }
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; border-radius: var(--radius); padding: 12px; background: var(--surface); cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row .ico { width: 48px; height: 48px; flex: none; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.row .ico svg { width: 26px; height: 26px; fill: var(--accent); }
.row .ico img { width: 100%; height: 100%; object-fit: cover; }
.row .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .count { color: var(--muted); font-size: .9rem; }

.play-wrap { margin: 4px 0 16px; display: flex; flex-direction: column; gap: 8px; }
.cast-btn google-cast-launcher { width: 26px; height: 26px; cursor: pointer; --disconnected-color: currentColor; --connected-color: var(--accent); }
#show .push { margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
.grid button { border: 0; padding: 0; aspect-ratio: 1; background: var(--surface); border-radius: 6px; overflow: hidden; cursor: pointer; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid button { position: relative; }
.grid button.vid::after {
  content: '▶'; position: absolute; right: 6px; bottom: 6px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; color: #fff; background: rgba(0,0,0,.55);
}

dialog {
  border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; color: var(--muted); }
.field select, .field input { padding: 10px; border-radius: 10px; border: 0; background: var(--surface-2); }
.tools { display: flex; justify-content: flex-end; gap: 8px; margin: -4px 0 12px; }
.btn.small { padding: 8px 16px; font-size: .95rem; }
.section-title { font-size: 1rem; color: var(--muted); margin: 20px 0 8px; }
.row-wrap { display: flex; align-items: center; gap: 4px; }
.row-wrap .row { flex: 1; min-width: 0; }
.share-entry { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--surface-2); }
.share-entry span { min-width: 0; overflow-wrap: anywhere; }
#share-current:not(:empty) { margin-top: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
dialog .btn { width: 100%; margin-top: 8px; }

/* Slaidiesitlus */
#show { position: fixed; inset: 0; background: #000; z-index: 10; overflow: hidden; touch-action: none; user-select: none; }
#show .layer { position: absolute; inset: 0; opacity: 0; transition: opacity 1s ease; }
#show .layer.on { opacity: 1; }
#show[data-effect="none"] .layer { transition: none; }
#show[data-effect="slide"] .layer { opacity: 1; transform: translateX(100%); transition: transform .8s ease; }
#show[data-effect="slide"] .layer.on { transform: none; }
#show[data-effect="slide"] .layer.out:not(.on) { transform: translateX(-100%); }
#show .layer img.kb { animation-timing-function: linear; animation-fill-mode: both; will-change: transform; }
#show .layer img.kb1 { animation-name: kb1; }
#show .layer img.kb2 { animation-name: kb2; }
#show .layer img.kb3 { animation-name: kb3; }
#show .layer img.kb4 { animation-name: kb4; }
@keyframes kb1 { from { transform: scale(1); } to { transform: scale(1.15) translate(-3%, -2%); } }
@keyframes kb2 { from { transform: scale(1); } to { transform: scale(1.15) translate(3%, -2%); } }
@keyframes kb3 { from { transform: scale(1.15) translate(-3%, 2%); } to { transform: scale(1); } }
@keyframes kb4 { from { transform: scale(1.15) translate(3%, 2%); } to { transform: scale(1); } }
#show .layer img, #show .layer video { width: 100%; height: 100%; display: block; background: #000; }
#show .layer .contain { object-fit: contain; }
#show .layer .cover { object-fit: cover; }
#caption {
  position: absolute; left: 0; right: 0; bottom: max(16px, env(safe-area-inset-bottom));
  text-align: center; font-size: .95rem; color: #fff; text-shadow: 0 1px 4px #000; pointer-events: none;
}
#show-count {
  position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  font-size: .9rem; color: #fff; text-shadow: 0 1px 4px #000; pointer-events: none; font-variant-numeric: tabular-nums;
}
#show-count:empty { display: none; }
#show .bar {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  opacity: 0; transition: opacity .3s; pointer-events: none; color: #fff;
}
#show.ui .bar { opacity: 1; pointer-events: auto; }
#show .top-bar { top: 0; background: linear-gradient(rgba(0,0,0,.6), transparent); }
#show .bottom-bar {
  bottom: 0; justify-content: center; gap: 32px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
#show .icon-btn { color: #fff; }
#show .icon-btn.big { width: 60px; height: 60px; background: rgba(255,255,255,.12); }
#show .icon-btn.big svg { width: 32px; height: 32px; }
#show .i-play { display: none; }
#show.paused .i-play { display: block; }
#show.paused .i-pause { display: none; }
#counter { font-variant-numeric: tabular-nums; }
#show-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 16px; }

/* Haldus */
.small { font-size: .9rem; }
.wide-link { display: flex; width: 100%; margin-top: 8px; }
a.tab { text-align: center; text-decoration: none; color: var(--text); }
.card-list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.item .name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.item .body { margin: 6px 0; white-space: pre-wrap; }
.badge { border-radius: 999px; padding: 3px 10px; font-size: .85rem; background: var(--surface-2); white-space: nowrap; }
.badge.role-owner { background: var(--accent); color: var(--accent-text); }
.badge.role-admin { background: #2f4a2f; color: #c8f0c8; }
.badge.role-blocked { background: #4a2626; color: var(--error); }
.item-tools { display: flex; align-items: center; gap: 10px; }
.ai-toggle { display: flex; align-items: center; gap: 4px; font-size: .9rem; cursor: pointer; }
.ai-toggle input { accent-color: var(--accent); width: 18px; height: 18px; }
.role-select { padding: 6px 8px; border-radius: 10px; border: 0; background: var(--surface-2); }
.filter { width: 100%; padding: 10px 12px; margin-bottom: 12px; border-radius: 10px; border: 0; background: var(--surface); }
.notice { background: #4a3b1a; color: #ffe2a8; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
h2.day { font-size: 1rem; color: var(--muted); margin: 20px 0 8px; }
