/* =========================================================
   MemeForge — Design System
   A sticker-board aesthetic: cream corkboard light mode,
   ink-black dark mode, punchy marker-yellow + coral accents.
   ========================================================= */

:root{
  /* --- Brand palette --- */
  --ink:        #1B1B2F;
  --ink-soft:   #34344a;
  --paper:      #FBF6EC;
  --paper-dim:  #F1E9D8;
  --card:       #FFFFFF;
  --yellow:     #FFCF3F;
  --yellow-ink: #4A3800;
  --coral:      #FF5A5F;
  --violet:     #7C5CFC;
  --green:      #2FB380;
  --line:       #E7DFCB;
  --line-strong:#D8CBA8;

  --text:       #201F2B;
  --text-dim:   #6B6A7A;
  --text-on-ink:#FBF6EC;

  --shadow-pin: 0 10px 24px -12px rgba(27,27,47,.35);
  --shadow-card:0 2px 0 var(--line-strong), 0 14px 30px -18px rgba(27,27,47,.25);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --font-display: 'Space Grotesk', 'Poppins', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-meme: 'Anton', 'Space Grotesk', system-ui, sans-serif;

  --header-h: 72px;
  --focus-ring: 3px solid var(--violet);
}

html[data-theme="dark"]{
  --ink:        #FBF6EC;
  --paper:      #17151F;
  --paper-dim:  #1E1B28;
  --card:       #221F2E;
  --line:       #322D42;
  --line-strong:#3E3752;
  --text:       #F3F0FA;
  --text-dim:   #A9A3BE;
  --text-on-ink:#17151F;
  --shadow-pin: 0 10px 24px -12px rgba(0,0,0,.6);
  --shadow-card:0 2px 0 var(--line-strong), 0 14px 30px -18px rgba(0,0,0,.6);
}

*,*::before,*::after{ box-sizing: border-box; }
html{ scroll-behavior: smooth; }

body{
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  transition: background .25s ease, color .25s ease;
  overflow-x: hidden;
}

img{ max-width: 100%; display: block; }
a{ color: inherit; text-decoration: none; }
button{ font-family: inherit; cursor: pointer; }
input, select, textarea{ font-family: inherit; font-size: 1rem; }

h1,h2,h3,h4{
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.12;
  margin: 0 0 .5em;
  letter-spacing: -0.01em;
}
h1{ font-size: clamp(2.3rem, 5vw, 3.6rem); }
h2{ font-size: clamp(1.6rem, 3vw, 2.3rem); }
h3{ font-size: 1.25rem; }
p{ margin: 0 0 1em; color: var(--text-dim); }

.container{
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

section{ padding: 72px 0; }

:focus-visible{ outline: var(--focus-ring); outline-offset: 2px; }
.skip-link{
  position:absolute; left:12px; top:-60px; background:var(--ink); color:var(--text-on-ink);
  padding:10px 16px; border-radius: var(--radius-sm); z-index: 999; transition: top .2s;
}
.skip-link:focus{ top:12px; }

/* ---------- Buttons ---------- */
.btn{
  display: inline-flex; align-items:center; justify-content:center; gap:.5em;
  padding: 13px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: .96rem;
  border: 2px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:active{ transform: scale(.97); }
.btn-primary{ background: var(--ink); color: var(--text-on-ink); box-shadow: var(--shadow-pin); }
.btn-primary:hover{ background: var(--violet); }
.btn-accent{ background: var(--yellow); color: var(--yellow-ink); box-shadow: var(--shadow-pin); }
.btn-accent:hover{ filter: brightness(1.05); transform: translateY(-2px); }
.btn-outline{ background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn-outline:hover{ border-color: var(--ink); }
.btn-ghost{ background: transparent; color: var(--text); padding: 10px 14px; }
.btn-ghost:hover{ background: var(--paper-dim); border-radius: var(--radius-sm); }
.btn-sm{ padding: 8px 14px; font-size: .85rem; }
.btn-icon{
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  display:inline-flex; align-items:center; justify-content:center;
  background: var(--paper-dim); color: var(--text); border: 1px solid var(--line);
}
.btn-icon:hover{ background: var(--line); }
.btn-block{ width: 100%; }
.btn[disabled]{ opacity:.45; cursor:not-allowed; }

/* ---------- Header ---------- */
.site-header{
  position: sticky; top:0; z-index: 200;
  height: var(--header-h);
  display:flex; align-items:center;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .container{ display:flex; align-items:center; justify-content:space-between; gap: 20px; }
.brand{ display:flex; align-items:center; gap:.55em; font-family: var(--font-display); font-weight:700; font-size:1.3rem; color: var(--ink); flex-shrink:0; }
.brand-mark{
  width:38px; height:38px; border-radius: 11px; background: var(--yellow);
  display:flex; align-items:center; justify-content:center; font-size:1.2rem;
  transform: rotate(-6deg); box-shadow: var(--shadow-pin);
}
.main-nav{ display:flex; align-items:center; gap: 4px; }
.main-nav a{
  padding: 10px 14px; border-radius: 999px; font-weight: 600; font-size:.94rem; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.main-nav a:hover, .main-nav a[aria-current="page"]{ background: var(--paper-dim); color: var(--ink); }
.header-actions{ display:flex; align-items:center; gap: 10px; }
.search-form{ position:relative; display:flex; align-items:center; }
.search-form input{
  width: 190px; padding: 9px 14px 9px 36px; border-radius: 999px; border:1px solid var(--line);
  background: var(--card); color: var(--text);
}
.search-form svg{ position:absolute; left:12px; width:16px; height:16px; color: var(--text-dim); pointer-events:none; }

.hamburger{ display:none; flex-direction:column; gap:5px; width:40px; height:40px; align-items:center; justify-content:center; border-radius: var(--radius-sm); background:transparent; border:1px solid var(--line); }
.hamburger span{ width:20px; height:2px; background: var(--ink); border-radius:2px; transition: transform .2s, opacity .2s; }
.mobile-panel{
  position: fixed; inset: var(--header-h) 0 0 0; background: var(--paper); z-index: 190;
  transform: translateX(100%); transition: transform .25s ease; padding: 24px; overflow-y:auto;
}
.mobile-panel.open{ transform: translateX(0); }
.mobile-panel a{ display:block; padding: 16px 4px; font-family: var(--font-display); font-size:1.3rem; border-bottom: 1px solid var(--line); color: var(--ink); }
.mobile-panel .search-form{ margin: 18px 0; }
.mobile-panel .search-form input{ width: 100%; }

/* ---------- Hero ---------- */
.hero{ padding: 60px 0 40px; position: relative; overflow: visible; }
.hero .container{ display:grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items:center; }
.hero-eyebrow{ display:inline-flex; align-items:center; gap:.5em; background: var(--card); border:1px solid var(--line); padding: 6px 14px; border-radius:999px; font-size:.85rem; font-weight:600; color: var(--text-dim); margin-bottom: 18px; box-shadow: var(--shadow-card); }
.hero h1{ margin-bottom: .3em; }
.hero h1 .pop{ color: var(--coral); }
.hero-desc{ font-size: 1.1rem; max-width: 46ch; }
.hero-ctas{ display:flex; gap:14px; flex-wrap:wrap; margin-top: 26px; }
.hero-stage{ position:relative; aspect-ratio: 1/1; }
.sticker-board{
  position:absolute; inset:0; background: var(--paper-dim);
  border-radius: var(--radius-lg); border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.floating-sticker{
  position:absolute; background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-pin);
  padding: 14px 18px; font-family: var(--font-display); font-weight:700; font-size:1.4rem;
  border: 1px solid var(--line); user-select:none;
}
.fs-1{ top:8%; left:8%; transform: rotate(-9deg); }
.fs-2{ bottom:14%; left:14%; transform: rotate(6deg); background: var(--yellow); color: var(--yellow-ink); }
.fs-3{ top:38%; right:6%; transform: rotate(4deg); font-size:2.6rem; padding: 10px 16px; }
.fs-4{ bottom:6%; right:16%; transform: rotate(-5deg); background: var(--coral); color:#fff; }
.fs-5{ top:6%; right:26%; transform: rotate(10deg); font-size: 1.8rem; padding: 8px 14px; }

/* ---------- Section headers ---------- */
.section-head{ display:flex; align-items:flex-end; justify-content:space-between; gap: 20px; margin-bottom: 34px; flex-wrap:wrap; }
.section-head p{ margin:0; max-width: 50ch; }

/* ---------- Category chips ---------- */
.chip-row{ display:flex; gap:10px; flex-wrap:wrap; margin-bottom: 30px; }
.chip{
  padding: 9px 16px; border-radius: 999px; border:1px solid var(--line); background: var(--card);
  font-weight:600; font-size:.9rem; color: var(--text-dim);
}
.chip:hover{ border-color: var(--ink); color: var(--ink); }
.chip.active{ background: var(--ink); color: var(--text-on-ink); border-color: var(--ink); }

/* ---------- Template / Gallery cards ---------- */
.grid{ display:grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); }
.template-card{
  background: var(--card); border-radius: var(--radius-md); border: 1px solid var(--line);
  overflow: hidden; box-shadow: var(--shadow-card); transition: transform .18s ease, box-shadow .18s ease;
  display:flex; flex-direction:column;
}
.template-card:hover{ transform: translateY(-4px) rotate(-.6deg); }
.template-thumb{ position:relative; aspect-ratio: 1/1; overflow:hidden; background: var(--paper-dim); }
.template-thumb img{ width:100%; height:100%; object-fit: cover; }
.fav-btn{
  position:absolute; top:10px; right:10px; width:36px; height:36px; border-radius:50%;
  background: rgba(255,255,255,.9); border:none; display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow-pin); font-size:1.05rem;
}
.fav-btn[aria-pressed="true"]{ background: var(--coral); }
.template-body{ padding: 14px 16px 18px; display:flex; flex-direction:column; gap:10px; flex:1; }
.template-body h3{ margin:0; font-size:1.02rem; }
.template-meta{ display:flex; align-items:center; justify-content:space-between; }
.badge{ font-size:.72rem; font-weight:700; padding: 4px 10px; border-radius:999px; background: var(--paper-dim); color: var(--text-dim); }
.empty-state{ text-align:center; padding: 60px 20px; color: var(--text-dim); }
.empty-state .big-emoji{ font-size: 3rem; margin-bottom: 12px; }

/* ---------- Footer ---------- */
.site-footer{ background: var(--ink); color: var(--text-on-ink); padding: 60px 0 30px; margin-top: 60px; }
.site-footer a{ color: color-mix(in srgb, var(--text-on-ink) 75%, transparent); }
.site-footer a:hover{ color: var(--text-on-ink); }
.footer-grid{ display:grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 32px; }
.footer-grid h4{ color: var(--text-on-ink); font-family: var(--font-display); font-size:.95rem; margin-bottom: 14px; }
.footer-grid ul{ list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:10px; font-size:.92rem; }
.footer-brand p{ color: color-mix(in srgb, var(--text-on-ink) 65%, transparent); max-width: 32ch; }
.footer-social{ display:flex; gap:10px; margin-top:14px; }
.footer-social a{ width:36px; height:36px; border-radius:50%; background: rgba(255,255,255,.08); display:flex; align-items:center; justify-content:center; }
.footer-bottom{ margin-top: 44px; padding-top: 22px; border-top: 1px solid rgba(255,255,255,.12); display:flex; justify-content:space-between; flex-wrap:wrap; gap:10px; font-size:.85rem; color: color-mix(in srgb, var(--text-on-ink) 55%, transparent); }

/* ---------- Toasts ---------- */
.toast-stack{ position: fixed; bottom: 22px; right: 22px; z-index: 500; display:flex; flex-direction:column; gap:10px; }
.toast{
  background: var(--ink); color: var(--text-on-ink); padding: 13px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pin); font-size:.92rem; font-weight:600; display:flex; align-items:center; gap:10px;
  animation: toast-in .22s ease;
  max-width: 320px;
}
.toast.toast-error{ background: var(--coral); }
@keyframes toast-in{ from{ opacity:0; transform: translateY(8px);} to{opacity:1; transform:translateY(0);} }

/* ---------- Page hero (inner pages) ---------- */
.page-hero{ padding: 56px 0 30px; text-align:center; }
.page-hero p{ max-width: 60ch; margin: 0 auto; }

/* ---------- Cards / generic ---------- */
.panel{ background: var(--card); border:1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: 22px; }

/* ---------- Forms ---------- */
.form-group{ margin-bottom: 18px; }
.form-group label{ display:block; font-weight:600; font-size:.9rem; margin-bottom:6px; color: var(--ink); }
.form-group input, .form-group textarea, .form-group select{
  width:100%; padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--paper); color: var(--text);
}
.form-group textarea{ resize: vertical; min-height: 120px; }
.form-hint{ font-size:.82rem; color: var(--text-dim); margin-top:4px; }

/* ---------- Accordion (FAQ) ---------- */
.accordion-item{ border-bottom: 1px solid var(--line); }
.accordion-trigger{
  width:100%; text-align:left; background:none; border:none; padding: 20px 4px;
  display:flex; justify-content:space-between; align-items:center; gap: 16px;
  font-family: var(--font-display); font-size: 1.05rem; color: var(--ink);
}
.accordion-trigger .plus{ transition: transform .2s ease; flex-shrink:0; }
.accordion-trigger[aria-expanded="true"] .plus{ transform: rotate(45deg); }
.accordion-panel{ overflow:hidden; max-height:0; transition: max-height .25s ease; }
.accordion-panel p{ padding: 0 4px 20px; margin:0; }

/* ---------- Utility ---------- */
.visually-hidden{ position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.text-center{ text-align:center; }
.mt-0{ margin-top:0; }
.stack{ display:flex; flex-direction:column; gap: 16px; }
.two-col{ display:grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.small-note{ font-size:.85rem; color: var(--text-dim); }
.divider{ height:1px; background: var(--line); border:none; margin: 40px 0; }
.legal-body h2{ margin-top: 1.6em; }
.legal-body ul{ color: var(--text-dim); }

/* =========================================================
   Editor layout
   ========================================================= */
.editor-shell{
  display:grid;
  grid-template-columns: 260px 1fr 300px;
  gap: 18px;
  padding: 18px 0 60px;
  min-height: calc(100vh - var(--header-h));
}
.editor-panel{ background: var(--card); border:1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: 16px; display:flex; flex-direction:column; gap: 14px; height: fit-content; max-height: calc(100vh - var(--header-h) - 36px); overflow-y:auto; }
.tool-tabs{ display:flex; flex-wrap:wrap; gap:6px; }
.tool-tab{ flex:1 1 auto; padding: 9px 10px; border-radius: var(--radius-sm); border:1px solid var(--line); background: var(--paper-dim); font-size:.82rem; font-weight:700; color: var(--text-dim); min-width: 64px; text-align:center; }
.tool-tab.active{ background: var(--ink); color: var(--text-on-ink); border-color:var(--ink); }
.tool-section{ display:none; flex-direction:column; gap: 12px; }
.tool-section.active{ display:flex; }
.upload-drop{
  border: 2px dashed var(--line-strong); border-radius: var(--radius-md); padding: 28px 14px; text-align:center;
  color: var(--text-dim); font-size:.88rem; cursor:pointer; transition: border-color .15s, background .15s;
}
.upload-drop:hover, .upload-drop.dragover{ border-color: var(--violet); background: var(--paper-dim); }
.upload-drop input{ display:none; }
.field-row{ display:flex; align-items:center; gap:10px; }
.field-row label{ flex-shrink:0; font-size:.82rem; font-weight:600; color: var(--text-dim); width: 86px; }
.field-row input[type="range"]{ flex:1; accent-color: var(--violet); }
.field-row input[type="color"]{ width: 40px; height:32px; border:1px solid var(--line); border-radius:6px; padding:0; background:none; }
.field-row input[type="text"], .field-row select, .field-row input[type="number"]{ flex:1; padding:7px 10px; border-radius:6px; border:1px solid var(--line); background: var(--paper); color:var(--text); font-size:.85rem; }
.mini-grid{ display:grid; grid-template-columns: repeat(6,1fr); gap:6px; }
.mini-grid button{ aspect-ratio:1; border-radius:8px; border:1px solid var(--line); background: var(--paper-dim); font-size:1.1rem; display:flex; align-items:center; justify-content:center; }
.mini-grid button:hover{ background: var(--line); }
.sticker-tabs{ display:flex; gap:6px; flex-wrap:wrap; margin-bottom:4px; }
.sticker-tabs button{ font-size:.75rem; padding:6px 10px; border-radius:999px; border:1px solid var(--line); background:var(--paper-dim); color:var(--text-dim); font-weight:600; }
.sticker-tabs button.active{ background: var(--ink); color: var(--text-on-ink); border-color:var(--ink); }
.color-swatches{ display:flex; gap:8px; flex-wrap:wrap; }
.color-swatches button{ width:26px; height:26px; border-radius:50%; border:2px solid var(--card); box-shadow:0 0 0 1px var(--line); }
.color-swatches button.active{ box-shadow:0 0 0 2px var(--ink); }
.shape-grid{ display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.shape-grid button{ padding:10px 4px; border-radius:8px; border:1px solid var(--line); background:var(--paper-dim); font-size:1.2rem; }
.shape-grid button.active{ background: var(--ink); color:var(--text-on-ink); }

.editor-center{ display:flex; flex-direction:column; align-items:center; gap: 16px; }
.canvas-toolbar{ display:flex; align-items:center; justify-content:space-between; width:100%; gap: 10px; flex-wrap:wrap; }
.canvas-toolbar .group{ display:flex; gap:8px; align-items:center; }
.canvas-frame{
  background: repeating-conic-gradient(var(--paper-dim) 0% 25%, var(--paper) 0% 50%) 0 0/20px 20px;
  border-radius: var(--radius-md); border: 1px solid var(--line); box-shadow: var(--shadow-card);
  padding: 18px; display:flex; align-items:center; justify-content:center; width:100%; max-width: 720px; min-height: 340px;
  position: relative; touch-action:none;
}
#memeCanvas{ max-width:100%; max-height: 62vh; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); background:#fff; }
.canvas-empty{ text-align:center; color: var(--text-dim); padding: 40px; }
.canvas-empty .big-emoji{ font-size:2.6rem; }
.dimension-row{ display:flex; gap:8px; flex-wrap:wrap; }
.dimension-row button{ padding:7px 12px; font-size:.8rem; border-radius:999px; border:1px solid var(--line); background:var(--paper-dim); font-weight:600; }
.dimension-row button.active{ background:var(--ink); color:var(--text-on-ink); }
.custom-dim{ display:flex; gap:8px; align-items:center; }
.custom-dim input{ width:80px; padding:6px 8px; border-radius:6px; border:1px solid var(--line); background:var(--paper); color:var(--text); }

.layer-list{ display:flex; flex-direction:column; gap:6px; max-height: 160px; overflow-y:auto; }
.layer-item{ display:flex; align-items:center; justify-content:space-between; padding:8px 10px; border-radius:8px; background: var(--paper-dim); font-size:.82rem; }
.layer-item.selected{ outline: 2px solid var(--violet); }
.layer-item .layer-name{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.layer-actions{ display:flex; gap:4px; }
.layer-actions button{ background:none; border:none; font-size:.9rem; padding:2px 4px; }

@media (max-width: 1080px){
  .editor-shell{ grid-template-columns: 1fr; }
  .editor-panel{ max-height:none; }
  #memeCanvas{ max-height: 50vh; }
}
@media (max-width: 900px){
  .hero .container{ grid-template-columns: 1fr; }
  .hero-stage{ order:-1; max-width: 340px; margin: 0 auto; }
  .two-col{ grid-template-columns: 1fr; }
  .footer-grid{ grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px){
  .main-nav, .header-actions .search-form{ display:none; }
  .hamburger{ display:flex; }
  .footer-grid{ grid-template-columns: 1fr; }
  section{ padding: 48px 0; }
}
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior:auto !important; }
}
