:root {
  /* Samma palett som Frisnack (Kallmark) */
  --bg: #09090b;
  --surface: #18181b;
  --surface-2: #27272a;
  --border: #3f3f46;
  --text: #fafafa;
  --muted: #a1a1aa;
  --faint: #52525b;
  --accent: #8b5cf6;
  --accent-light: #a78bfa;
  --accent-text: #ffffff;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --heart: #f472b6;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  --r: 18px;
  --r-sm: 12px;
  --tabbar-h: 58px;
  --topbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-light); }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Topp & flikar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(9, 9, 11, 0.86);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid rgba(63, 63, 70, 0.5);
  transition: background 0.2s, border-color 0.2s;
}
.topbar.over-hero { background: transparent; border-color: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.topbar.over-hero h1 { opacity: 0; }
.topbar h1 { margin: 0; transition: opacity 0.2s; }
.logo-text {
  font-size: 28px; font-weight: 800; letter-spacing: -0.04em; line-height: 1;
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--accent);
}
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  display: grid; place-items: center;
  background: rgba(24, 24, 27, 0.72); color: var(--text);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  position: relative;
}
.icon-btn.on::after {
  content: ""; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}

main { padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
#favoritesView { padding-top: calc(env(safe-area-inset-top) + var(--topbar-h) + 8px); }

/* Hero (som Frisnacks startsida) */
.hero {
  position: relative; margin: 0 -16px 4px; height: min(52vh, 460px); min-height: 280px; overflow: hidden;
}
.hero img.hero-img { width: 100%; height: 100%; object-fit: cover; object-position: center 30%; display: block; }
.hero-mark {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 14px; z-index: 2;
  width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.hero-mark img { width: 100%; height: 100%; display: block; border-radius: 10px; }
.hero-overlay {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 64px 24px 16px; text-align: center;
  background: linear-gradient(to top, var(--bg) 0%, rgba(9, 9, 11, 0.7) 50%, transparent 100%);
}
.hero-overlay .logo-text { font-size: 3.6rem; display: inline-block; }
.hero-overlay .tagline { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.hero-support {
  margin-top: 10px; padding: 5px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  color: var(--muted); background: rgba(24, 24, 27, 0.55); border: 1px solid var(--border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); cursor: pointer; transition: all 0.15s;
}
.hero-support:hover { color: var(--accent-light); border-color: var(--accent); }
@media (max-height: 560px) { .hero { height: 200px; min-height: 160px; } .hero-overlay .logo-text { font-size: 2.4rem; } }

/* Diskret sidfot och copyright (som Frisnack) */
.copyright {
  font-size: 0.72rem; color: var(--faint); text-align: center; letter-spacing: 0.03em; margin: 4px 0 0;
}
.copyright a, .copyright .link-btn { color: inherit; text-decoration: none; }
.copyright a:hover, .copyright .link-btn:hover { color: var(--muted); }
.advanced { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 14px 12px; background: var(--surface); }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; padding: 10px 0 6px; }
.advanced[open] summary { margin-bottom: 2px; }
.advanced .btn { width: 100%; margin-top: 8px; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; }

/* Mjuk stötta-rad (favoriter, inställningar) */
.soft-support {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px 14px; color: var(--muted); font-size: 14px; cursor: pointer;
}
.soft-support .emoji { font-size: 22px; flex: none; }
.soft-support b { color: var(--text); font-weight: 600; }
.soft-support .arrow { margin-left: auto; color: var(--accent-light); font-weight: 700; flex: none; }
.soft-support.thanks { cursor: default; justify-content: center; }


.view { display: flex; flex-direction: column; gap: 12px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center; gap: 8px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(9, 9, 11, 0.9);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 0 1 160px; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600;
}
.tab.active { color: var(--accent-light); }
.tab.active[data-tab="favorites"] svg { fill: currentColor; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--heart); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; margin: 0 -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding-inline: 0; }
.chip {
  flex: none; border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px;
  background: transparent; color: var(--muted); font-size: 15px; font-weight: 600; white-space: nowrap;
  transition: all 0.15s;
}
.chip.on { border-color: var(--accent); color: var(--accent-light); background: var(--accent-soft); }
.modes .chip { font-weight: 600; }
.chip-group { display: flex; flex-direction: column; gap: 6px; }
.chip-group > .label { margin: 0; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }
.label {
  display: block; font-size: 0.7rem; font-weight: 600; color: var(--muted); margin: 14px 0 6px;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.attribution { text-align: center; font-size: 11px; color: var(--muted); margin: 8px 0 0; }

/* Fält & knappar */
.field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0 14px;
}
.field input, .field textarea { flex: 1; min-width: 0; border: 0; background: none; padding: 12px 0; outline: none; font-size: 16px; resize: none; }
.field:focus-within { border-color: var(--accent); }
.input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 13px 15px;
  background: var(--surface); font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.clear-btn { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 4px; }

.btn {
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px 14px;
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  transition: transform 0.12s ease, background 0.12s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-light); border-color: var(--accent-light); }
.btn.ghost { background: none; border-color: transparent; color: var(--accent-light); }
.btn.big { width: 100%; padding: 15px 20px; font-size: 16px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.fav-on { color: var(--heart); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row.end { justify-content: space-between; }
.row.end > * { flex: none; }

.mix { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.mix .plus { color: var(--muted); font-weight: 700; }
.panel { display: flex; flex-direction: column; gap: 8px; }

.moods { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.mood {
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); padding: 8px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mood .e { font-size: 30px; line-height: 1.1; }
.mood .n { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.mood.on { background: var(--accent-soft); border-color: var(--accent); }

.active-filters:empty { display: none; }
.active-filters { font-size: 13px; color: var(--muted); }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--danger-soft); border: 1px solid rgba(248, 113, 113, 0.3); color: var(--text);
  border-radius: var(--r-sm); padding: 12px; font-size: 15px;
}
.banner.info { background: var(--accent-soft); border-color: rgba(139, 92, 246, 0.35); }
.banner .btn { margin-left: auto; padding: 6px 12px; flex: none; }

.headline .label { color: #fbbf24; margin-top: 0; }

/* Masonry */
.masonry { display: flex; gap: 6px; align-items: flex-start; }
.masonry .col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tile {
  position: relative; border-radius: var(--r-sm); overflow: hidden; background: var(--surface);
  cursor: pointer; transform: translateZ(0);
}
.tile.sticker { background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; }
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile:active { transform: scale(0.98); }
.heart {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  display: grid; place-items: center; color: #fff;
  background: rgb(0 0 0 / 0.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.heart svg { width: 17px; height: 17px; stroke-width: 2.4; }
.heart.on { color: var(--heart); background: rgb(255 255 255 / 0.9); }
.heart.on svg { fill: currentColor; }
.src-badge {
  position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 6px; border-radius: 6px; background: rgb(0 0 0 / 0.5); color: #fff;
}
.cat-badge {
  position: absolute; left: 6px; bottom: 6px; font-size: 13px; padding: 2px 6px; border-radius: 8px;
  background: rgb(0 0 0 / 0.45); color: #fff;
}

.sentinel { height: 1px; }
.spinner { display: grid; place-items: center; padding: 16px; }
.spinner span {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty .big-emoji { font-size: 48px; }
.empty h3 { color: var(--text); margin: 8px 0 4px; }

/* Favoriter */
.fav-section { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.fav-section-head {
  display: flex; align-items: baseline; gap: 8px; border: 0; background: none; padding: 0; text-align: left;
}
.fav-section-head h3 { margin: 0; font-size: 20px; }
.fav-section-head .count { color: var(--muted); }
.fav-section-head .more { margin-left: auto; color: var(--accent-light); font-size: 14px; font-weight: 600; }
.fav-tools { display: flex; justify-content: center; }

/* Sheets */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92vh; max-height: 92dvh;
  background: var(--bg); color: var(--text); border: 1px solid #2c2c31; border-bottom: 0;
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow);
}
dialog.sheet[open] { animation: up 0.25s ease-out; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.65); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 24px; border-bottom: 1px solid #2c2c31; } }
.sheet-inner {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-inner h2 { margin: 4px 40px 0 0; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.025em; }
.close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-size: 14px; z-index: 1;
}
.detail-media {
  border-radius: 16px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; min-height: 160px; margin-top: 30px;
}
.detail-media img { display: block; max-width: 100%; max-height: 50vh; max-height: 50dvh; }
.test-result p { white-space: pre-line; margin: 4px 0; font-size: 15px; }
.test-result pre {
  white-space: pre-wrap; word-break: break-all; font-size: 11px; background: var(--surface-2);
  padding: 8px; border-radius: 8px; max-height: 240px; overflow: auto;
}
.test-result summary { font-size: 13px; color: var(--muted); cursor: pointer; }
/* GIF-studio */
.studio-stage {
  position: relative; border-radius: 16px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; min-height: 180px; margin-top: 4px;
}
.studio-stage canvas, .studio-stage img { display: block; max-width: 100%; max-height: 42vh; max-height: 42dvh; }
.studio-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; background: color-mix(in srgb, var(--surface) 75%, transparent); font-size: 14px; color: var(--muted);
}
.studio-loading[hidden] { display: none; }
.studio-loading .spinner { padding: 0; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); padding: 0;
  box-shadow: inset 0 0 0 2px var(--surface);
}
.swatch.on { border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 2px var(--accent); }
.studio-size { align-items: center; }
.studio-size .label { margin: 0; flex: none; }
.studio-size input { flex: 1; accent-color: var(--accent); }
.studio-size .chip { flex: none; }
#studioEditor .label { margin: 6px 0 0; }
/* Datorspecifika tips (mus/styrplatta) */
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) {
  .desktop-only { display: revert; }
  .btn.desktop-only { display: inline-flex; }
  .detail-media img, .studio-stage img { cursor: grab; }
}
.desktop-tip { text-align: center; }
/* Stötta Giffie */
.support-sheet { text-align: center; align-items: stretch; }
.support-sheet h2 { margin: 0; text-align: center; }
.support-hero { font-size: 44px; margin-top: 8px; }
.support-text { margin: 0; color: var(--muted); font-size: 15px; }
.support-amounts { justify-content: center; margin: 4px 0; }
.support-amounts .chip { min-width: 72px; font-weight: 700; }
.support-qr { margin: 4px auto 0; }
.support-qr svg { display: block; width: 180px; height: 180px; border-radius: 12px; }
@media (hover: hover) and (pointer: fine) { .support-qr.desktop-only { display: block; } }
.support-manual { text-align: center; }
.support-manual summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px; }
.support-manual .btn { margin: 4px auto; }
.support-number {
  font-size: 28px; font-weight: 800; letter-spacing: 0.02em; margin: 6px 0 2px;
  user-select: all; -webkit-user-select: all;
}
.support-steps { text-align: left; margin: 4px 0; padding-left: 22px; color: var(--muted); font-size: 15px; }
.support-steps li { margin: 3px 0; }
.center { text-align: center; }
.support-card {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: var(--accent-soft); border: 1px solid rgba(139, 92, 246, 0.35); border-radius: var(--r-sm); padding: 12px; margin-top: 4px;
}
.support-card .emoji { font-size: 26px; }
.support-card p { margin: 0; font-size: 14px; flex: 1; }
.support-card .btn { padding: 8px 12px; flex: none; }
.support-card .dismiss { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 4px; flex: none; }
.detail-source { margin: -4px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.detail-source a { color: var(--muted); }
#detailTitle { margin: 4px 0 0; text-align: center; font-size: 17px; }
.detail-category { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.detail-category select { width: auto; padding: 6px 12px; background: var(--accent-soft); color: var(--text); font-weight: 600; border-radius: 999px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 10px 16px; border-radius: 999px;
  font-size: 15px; font-weight: 500; box-shadow: var(--shadow); text-align: center;
}

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

/* Tomma behållare ska inte ge extra mellanrum */
.view > div:empty:not(.sentinel) { display: none; }

/* Dator: kortlayout som Frisnack */
@media (min-width: 600px) {
  body { background: #050507; }
  main { background: var(--bg); border-left: 1px solid #2c2c31; border-right: 1px solid #2c2c31; box-shadow: var(--shadow); }
  .topbar, .tabbar { left: 50%; right: auto; width: 560px; max-width: 100%; transform: translateX(-50%); }
  .tabbar { border-left: 1px solid #2c2c31; border-right: 1px solid #2c2c31; }
}
