:root {
  --bg: #0d0b16;
  --panel: #17142440;
  --panel-solid: #1b1730;
  --border: #2c2743;
  --text: #e9e6f5;
  --muted: #9a93bd;
  --accent: #ff5e7e;
  --accent2: #7b5cff;
  --accent3: #35d0ba;
  --ok: #35d0ba;
  --err: #ff6b6b;
  --radius: 16px;
}

/* bundled meme fonts (same TTFs the server renders with) */
@font-face { font-family: 'mf-impact';   src: url('../fonts/impact.ttf');   font-display: swap; }
@font-face { font-family: 'mf-archivo';  src: url('../fonts/archivo.ttf');  font-display: swap; }
@font-face { font-family: 'mf-bebas';    src: url('../fonts/bebas.ttf');    font-display: swap; }
@font-face { font-family: 'mf-bangers';  src: url('../fonts/bangers.ttf');  font-display: swap; }
@font-face { font-family: 'mf-luckiest'; src: url('../fonts/luckiest.ttf'); font-display: swap; }
@font-face { font-family: 'mf-marker';   src: url('../fonts/marker.ttf');   font-display: swap; }
@font-face { font-family: 'mf-comic';    src: url('../fonts/comic.ttf');    font-display: swap; }
@font-face { font-family: 'mf-lobster';  src: url('../fonts/lobster.ttf');  font-display: swap; }
@font-face { font-family: 'mf-pacifico'; src: url('../fonts/pacifico.ttf'); font-display: swap; }
@font-face { font-family: 'mf-sans';     src: url('../fonts/sans.ttf');     font-display: swap; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* animated background orbs */
.bg-orbs { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
.bg-orbs span {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: .35;
}
.bg-orbs span:nth-child(1){ width:420px;height:420px;background:var(--accent2);top:-120px;left:-100px; }
.bg-orbs span:nth-child(2){ width:360px;height:360px;background:var(--accent);bottom:-120px;right:-80px; }
.bg-orbs span:nth-child(3){ width:300px;height:300px;background:var(--accent3);top:40%;left:55%;opacity:.2; }

/* nav */
.nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(13,11,22,.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.3rem; text-decoration: none; color: var(--text); letter-spacing: -.02em; }
.brand .logo { margin-right: 4px; }
.accent { background: linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-links a { color: var(--muted); text-decoration: none; font-weight: 500; transition: color .15s; }
.nav-links a:hover { color: var(--text); }
.who { color: var(--muted); font-size: .9rem; }

.wrap { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 32px 24px 60px; }

/* headings */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
h1 { font-size: 2rem; margin: 0 0 4px; letter-spacing: -.03em; }
.sub, .tag { color: var(--muted); margin: 0; }

/* buttons */
button, .btn-primary, .btn-secondary, .btn-ghost { font-family: inherit; font-weight: 600; cursor: pointer; border-radius: 12px; border: none; font-size: .95rem; transition: transform .12s, box-shadow .2s, background .2s; }
.btn-primary { padding: 12px 20px; color: #fff; background: linear-gradient(90deg,var(--accent),var(--accent2)); box-shadow: 0 6px 20px -6px var(--accent2); text-decoration: none; display: inline-block; }
.btn-primary:hover { transform: translateY(-1px); }
.btn-secondary { padding: 12px 18px; color: var(--text); background: var(--panel-solid); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent2); }
.btn-ghost { padding: 9px 16px; background: transparent; color: var(--muted); border: 1px solid var(--border); text-decoration: none; display: inline-block; }
.btn-ghost:hover { color: var(--text); border-color: var(--accent2); }
.btn-ghost.sm { padding: 6px 12px; font-size: .85rem; }
.btn-ghost.danger:hover { color: var(--err); border-color: var(--err); }

/* landing */
.hero { position: relative; border-radius: 24px; overflow: hidden; padding: 0; margin-bottom: 42px; background: radial-gradient(120% 140% at 15% 0%, #2a2350 0%, #17142a 55%, #121022 100%); border: 1px solid var(--border); }
.hero-topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px 0; }
.hero-topbar .brand { font-size: 1.3rem; font-weight: 800; text-decoration: none; color: var(--text); }
.hero-inner { padding: 48px 28px 56px; text-align: center; max-width: 640px; margin: 0 auto; }
.hero-title { font-size: 2.8rem; line-height: 1.05; letter-spacing: -.03em; margin: 0 0 14px; }
.hero-sub { color: var(--muted); font-size: 1.05rem; margin: 0 auto 26px; max-width: 520px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.fresh { margin-top: 8px; }
.fresh-head { font-size: 1.2rem; margin: 0 0 18px; }

/* login */
.login-shell { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; background: var(--panel-solid); border: 1px solid var(--border); border-radius: 24px; padding: 36px 32px; box-shadow: 0 30px 80px -30px #000; }
.login-hero { text-align: center; margin-bottom: 24px; }
.logo-xl { font-size: 3rem; }
.login-hero h1 { font-size: 2.2rem; margin: 6px 0 2px; }
.form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 7px; font-size: .85rem; color: var(--muted); font-weight: 500; }
input, select, textarea { font-family: inherit; font-size: .95rem; color: var(--text); background: #120f20; border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px #7b5cff33; }
.hint { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 18px; }

.debug-box, .share-out { margin-top: 18px; background: #0a0812; border: 1px dashed var(--border); border-radius: 10px; padding: 12px; }
.debug-label { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 6px; }
.debug-box code { color: var(--accent3); font-size: .8rem; word-break: break-all; font-family: ui-monospace, monospace; }

/* flashes */
.flashes { margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px; }
.flash { padding: 12px 16px; border-radius: 10px; font-size: .9rem; border: 1px solid; }
.flash-error { background: #ff6b6b18; border-color: #ff6b6b55; color: #ffb3b3; }
.flash-ok { background: #35d0ba18; border-color: #35d0ba55; color: #a7f0e5; }

/* grid + tiles */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.tile { background: var(--panel-solid); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--text); display: flex; flex-direction: column; transition: transform .15s, border-color .15s, box-shadow .2s; }
.tile:hover { transform: translateY(-3px); border-color: var(--accent2); box-shadow: 0 14px 40px -18px var(--accent2); }
.tile-img { aspect-ratio: 1; overflow: hidden; background: #0a0812; display: block; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; }
.meme-thumb { background: #0a0812; }
.meme-thumb img { object-fit: contain; }
/* template previews: show the whole image, scaled to fit (letterboxed) */
.tpl-thumb { background: #0a0812; padding: 8px; }
.tpl-thumb img { object-fit: contain; }
.tile-name { padding: 12px 14px; font-weight: 600; }
.tile-meta { padding: 10px 14px 12px; }
.tile-meta .tile-name { padding: 0; display: block; color: var(--text); text-decoration: none; }
.tile-meta a.tile-name:hover { color: var(--accent); }

/* star rating widget */
.rating { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.rstars { display: inline-flex; line-height: 1; }
.rstar { background: none; border: none; padding: 0 1px; font-size: 1.05rem; line-height: 1; cursor: pointer; color: #40395e; -webkit-text-fill-color: #40395e; transition: transform .1s; }
.rating:not(.readonly) .rstar:hover { transform: scale(1.18); }
.rating.readonly .rstar { cursor: default; }
.rmeta { font-size: .74rem; color: var(--muted); white-space: nowrap; }
.tile-author { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.tile-name, .tile-author { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-date { font-size: .75rem; color: var(--muted); }
.tile-actions { display: flex; gap: 8px; padding: 10px 14px 14px; }
.tile-actions form { margin: 0; }

.count { color: var(--muted); }
.admin-tag { font-size: .6em; vertical-align: middle; text-transform: uppercase; letter-spacing: .08em; color: #fff; background: linear-gradient(90deg,var(--accent),var(--accent2)); padding: 3px 8px; border-radius: 999px; margin-left: 8px; font-weight: 700; }

.admin-flag-banner { position: relative; z-index: 5; text-align: center; padding: 11px 16px; font-size: .92rem; color: #fff; background: linear-gradient(90deg,var(--accent2),var(--accent)); }
.admin-flag-banner code { font-family: ui-monospace, monospace; font-weight: 700; background: rgba(0,0,0,.28); padding: 3px 9px; border-radius: 7px; margin-left: 4px; }

/* pagination */
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 30px; }
.pager .disabled { opacity: .35; pointer-events: none; }
.pager-page { min-width: 38px; text-align: center; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--muted); border: 1px solid var(--border); font-weight: 600; transition: color .15s, border-color .15s, background .15s; }
.pager-page:hover { color: var(--text); border-color: var(--accent2); }
.pager-page.current { color: #fff; background: linear-gradient(90deg,var(--accent),var(--accent2)); border-color: transparent; }

/* empty state */
.empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-emoji { font-size: 3.5rem; }
.empty h2 { color: var(--text); margin: 8px 0; }
.empty code { background: #0a0812; padding: 2px 8px; border-radius: 6px; color: var(--accent3); }

/* import panel */
.import-panel { margin-bottom: 22px; background: linear-gradient(180deg,#1b1730,#171326); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.import-head { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.import-title { font-weight: 700; }
.import-sub { color: var(--muted); font-size: .82rem; }
.import-form { display: flex; gap: 10px; flex-wrap: wrap; }
.import-input { flex: 1; min-width: 220px; font-family: ui-monospace, monospace; font-size: .82rem; }
.or-divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: .8rem; margin: 4px 0 22px; gap: 14px; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.or-divider span { text-transform: uppercase; letter-spacing: .1em; }

/* editor */
.editor { display: grid; grid-template-columns: 1fr 360px; gap: 28px; align-items: start; }
.preview-pane { position: sticky; top: 90px; }
.canvas-frame { background: #0a0812; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; place-items: center; }
#preview { max-width: 100%; max-height: 68vh; width: auto; height: auto; border-radius: 8px; display: block; }
.preview-actions { margin-top: 14px; display: flex; gap: 10px; }
.share-out { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.share-note { color: var(--muted); font-size: .8rem; margin: 0; }
.share-row { display: flex; flex-direction: column; gap: 5px; }
.copy-line { display: flex; gap: 8px; }
.copy-line input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .76rem; }

.controls { background: var(--panel-solid); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 16px; }
.row label { flex: 1; }
.range-val { color: var(--accent3); font-weight: 700; }
input[type=range] { accent-color: var(--accent); }
input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.btn-row { display: flex; gap: 12px; margin-top: 6px; }
.btn-row button { flex: 1; }

/* text fields */
.drag-hint { text-align: center; color: var(--muted); font-size: .78rem; margin: 10px 0 0; }
#preview { touch-action: none; cursor: grab; }
#preview.dragging { cursor: grabbing; }

.fields-head { display: flex; align-items: center; justify-content: space-between; font-size: .85rem; color: var(--muted); font-weight: 600; margin-top: 4px; }
#fields { display: flex; flex-direction: column; gap: 12px; }
.field { background: #120f20; border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, box-shadow .15s; }
.field.active { border-color: var(--accent); box-shadow: 0 0 0 3px #ff5e7e33; }
.field-head { display: flex; align-items: center; justify-content: space-between; }
.field-label { font-size: .78rem; font-weight: 700; color: var(--accent3); letter-spacing: .04em; }
.remove-field { background: transparent; border: none; color: var(--muted); font-size: 1rem; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.remove-field:hover { color: var(--err); background: #ff6b6b1a; }
.field-row { display: flex; gap: 12px; align-items: flex-end; }
.mini { flex: 0 0 auto; font-size: .72rem; gap: 5px; }
.mini:first-child { flex: 1; }
.mini input[type=color] { height: 34px; }
.i-size-val, .i-rot-val { color: var(--accent3); font-weight: 700; font-size: .8rem; }
.field > .mini { width: 100%; }
.i-font { width: 100%; }

/* public share page */
.share-page { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.share-brand { font-size: 1.4rem; font-weight: 800; text-decoration: none; color: var(--text); }
.share-title { margin: 0; text-align: center; }
.share-canvas { width: 100%; background: #0a0812; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; place-items: center; }
.share-canvas img { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.share-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.share-embeds { width: 100%; display: flex; flex-direction: column; gap: 14px; background: var(--panel-solid); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

.footer { position: relative; z-index: 1; text-align: center; color: var(--muted); font-size: .78rem; padding: 30px; opacity: .6; }

@media (max-width: 820px) {
  .editor { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
}
