/* Oddsprig Meme Generator — theme and layout.
   Mobile-first, accessible, self-hosted SIL OFL fonts only. Do not load a font CDN.
   Visual tokens follow the live image tools and the site theme toggle.
   Dark is the default. Light tokens apply when html[data-oddsprig-theme="light"].
   Scope lives under body.mg-tool so the shared header keeps its own styles. */

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("./fonts/source-serif-4-latin-wght-normal.woff2") format("woff2-variations"),
       url("./fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("./fonts/source-sans-3-latin-wght-normal.woff2") format("woff2-variations"),
       url("./fonts/source-sans-3-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Source Sans 3";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("./fonts/source-sans-3-latin-wght-italic.woff2") format("woff2-variations"),
       url("./fonts/source-sans-3-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/anton-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root,
html[data-oddsprig-theme="dark"] {
  color-scheme: dark;
  --mg-bg: #152227;
  --mg-panel: #1c2d31;
  --mg-soft: #24383c;
  --mg-ink: #edf2e9;
  --mg-muted: #b9c9c8;
  --mg-line: #38494b;
  --mg-dash: #82998d;
  --mg-lime: #c8e6a0;
  --mg-lime-hover: #ddf1bf;
  --mg-gold: #e5ce8e;
  --mg-focus: #e5ce8e;
  --mg-accent: #c8e6a0;
  --mg-accent-ink: #152227;
  --mg-danger: #f3b98e;
  --mg-ok: #c8e6a0;
  --mg-drag: #31483d;
  --mg-check-a: #3a4c4a;
  --mg-check-b: #2a3b3e;
  --mg-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mg-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mg-impact: "Anton", "Arial Black", "Helvetica Neue", sans-serif;
  --mg-radius: 15px;
  --mg-radius-sm: 9px;
  --mg-gutter: 16px;
  --mg-content: 1502px;
}

html[data-oddsprig-theme="light"] {
  color-scheme: light;
  --mg-bg: #eeece4;
  --mg-panel: #f4f0e6;
  --mg-soft: #e2ebed;
  --mg-ink: #20383e;
  --mg-muted: #50686c;
  --mg-line: #a1b3af;
  --mg-dash: #6d8979;
  --mg-lime: #256358;
  --mg-lime-hover: #2e7769;
  --mg-gold: #9a5018;
  --mg-focus: #9a5018;
  --mg-accent: #256358;
  --mg-accent-ink: #eeece4;
  --mg-danger: #8a3410;
  --mg-ok: #1c5349;
  --mg-drag: #d3e5da;
  --mg-check-a: #d7ddd4;
  --mg-check-b: #eef1ea;
}

@media (min-width: 650px) {
  :root,
  html[data-oddsprig-theme="light"],
  html[data-oddsprig-theme="dark"] { --mg-gutter: 32px; }
}

@media (min-width: 651px) {
  body.mg-tool.oddsprig-shared-shell { --mg-gutter: 48px; }
}

body.mg-tool {
  margin: 0;
  min-width: 0;
  background: var(--mg-bg);
  color: var(--mg-ink);
  font: 16px/1.55 var(--mg-sans);
  overflow-wrap: break-word;
}

body.mg-tool *,
body.mg-tool *::before,
body.mg-tool *::after { box-sizing: border-box; }

body.mg-tool img,
body.mg-tool svg,
body.mg-tool canvas { max-width: 100%; }

body.mg-tool h1,
body.mg-tool h2,
body.mg-tool h3,
body.mg-tool p { margin: 0; }

body.mg-tool h1,
body.mg-tool h2 {
  font-family: var(--mg-serif);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

body.mg-tool a { color: var(--mg-accent); text-underline-offset: 0.2em; }
body.mg-tool a:hover { color: var(--mg-gold); }

body.mg-tool :focus-visible {
  outline: 3px solid var(--mg-focus);
  outline-offset: 3px;
}

body.mg-tool button,
body.mg-tool .mg-button,
body.mg-tool select,
body.mg-tool textarea,
body.mg-tool input:not([type="range"]):not([type="color"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
  font: inherit;
  color: var(--mg-ink);
  background: var(--mg-soft);
  border: 1px solid var(--mg-line);
  border-radius: var(--mg-radius-sm);
  padding: 8px 12px;
}

body.mg-tool button,
body.mg-tool .mg-button,
body.mg-tool select { cursor: pointer; }

body.mg-tool button,
body.mg-tool .mg-button,
body.mg-tool select,
body.mg-tool input[type="radio"],
body.mg-tool input[type="checkbox"] {
  min-height: 44px;
  touch-action: manipulation;
}

body.mg-tool button:hover:not(:disabled),
body.mg-tool .mg-button:hover { border-color: var(--mg-lime); }

body.mg-tool button:disabled,
body.mg-tool .mg-button[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
}

body.mg-tool .mg-primary,
body.mg-tool button.mg-primary {
  background: var(--mg-lime);
  color: var(--mg-accent-ink);
  border-color: var(--mg-lime);
  font-weight: 750;
}

body.mg-tool .mg-primary:hover:not(:disabled) {
  background: var(--mg-lime-hover);
  border-color: var(--mg-lime-hover);
}

body.mg-tool [hidden] { display: none !important; }

.mg-sr,
.mg-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.mg-skip {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 100;
  min-height: 44px;
  padding: 0.6rem 1rem;
  background: var(--mg-lime);
  color: var(--mg-accent-ink);
  font-weight: 650;
  text-decoration: none;
}

.mg-skip:focus { top: 0.5rem; }

body.mg-tool.oddsprig-shared-shell main#main,
body.mg-tool:not(.oddsprig-shared-shell) main#main {
  box-sizing: border-box;
  width: calc(100% - var(--mg-gutter));
  max-width: var(--mg-content);
  margin-inline: auto;
  padding: 24px 0 48px;
}

.mg-intro { margin-bottom: 16px; padding-block: 4px; }
.mg-intro h1 { font-size: clamp(1.65rem, 3vw, 2.15rem); color: var(--mg-ink); }
.mg-eyebrow {
  margin: 0 0 6px;
  color: var(--mg-gold);
  font-size: 0.69rem;
  font-weight: 650;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.mg-explainer {
  max-width: 85ch;
  margin: 0.4rem 0 0;
  color: var(--mg-muted);
  font-size: 1rem;
  line-height: 1.45;
}
.mg-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.mg-trust li {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--mg-line);
  border-radius: 999px;
  background: var(--mg-panel);
  color: var(--mg-ink);
  font-size: 0.8125rem;
  font-weight: 650;
}

.mg-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.mg-panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--mg-line);
  border-radius: var(--mg-radius);
  background: var(--mg-panel);
}

.mg-panel h2 {
  margin: 0 0 12px;
  color: var(--mg-gold);
  font-size: 1.15rem;
}

.mg-panel h3 {
  margin: 16px 0 8px;
  font-family: var(--mg-serif);
  font-size: 1rem;
  font-weight: 600;
}

.mg-help,
.mg-panel .mg-help {
  margin: 10px 0 0;
  color: var(--mg-muted);
  font-size: 14px;
}

#mg-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 168px;
  padding: 20px 16px;
  border: 2px dashed var(--mg-dash);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  background: var(--mg-bg);
}

#mg-drop:hover,
#mg-drop.is-dragging,
#mg-drop[data-state="dragging"] {
  border-color: var(--mg-lime);
  background: var(--mg-drag);
}

#mg-drop strong { font-size: 1.05rem; }
#mg-drop .mg-drop-hint { color: var(--mg-muted); font-size: 14px; }

.mg-drop-actions,
.mg-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.mg-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  position: relative;
}

.mg-button input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  opacity: 0;
}

.mg-button:focus-within { outline: 3px solid var(--mg-focus); outline-offset: 3px; }

#mg-filename {
  display: block;
  margin-top: 8px;
  color: var(--mg-muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}
#mg-filename:empty { display: none; }

#mg-status {
  margin: 10px 0 0;
  color: var(--mg-ok);
  font-size: 14px;
  overflow-wrap: anywhere;
}
#mg-status.is-warn,
#mg-error { color: var(--mg-danger); }
#mg-error { margin: 10px 0 0; font-size: 14px; }

.mg-field { margin-top: 10px; }
.mg-field-label,
.mg-panel label.mg-field-label {
  display: block;
  margin-bottom: 4px;
  color: var(--mg-muted);
  font-size: 13px;
  font-weight: 650;
}

body.mg-tool textarea {
  width: 100%;
  min-height: 44px;
  resize: vertical;
}

body.mg-tool input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
  accent-color: var(--mg-lime);
  background: transparent;
}

body.mg-tool input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--mg-line);
  border-radius: var(--mg-radius-sm);
  background: var(--mg-soft);
  cursor: pointer;
}

body.mg-tool .mg-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

#mg-templates,
#mg-sticker-list,
#mg-emoji-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

#mg-templates {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}

.mg-thumb {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin: 0;
  padding: 6px;
  text-align: left;
  min-height: 44px;
}

.mg-thumb img {
  display: block;
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--mg-bg);
}

.mg-thumb span {
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
}

.mg-thumb[aria-pressed="true"] { border-color: var(--mg-lime); background: var(--mg-drag); }

#mg-sticker-list,
#mg-emoji-list {
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
}

.mg-sticker-btn,
.mg-emoji-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 4px;
  aspect-ratio: 1;
}

.mg-sticker-btn img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.mg-emoji-btn { font-size: 22px; line-height: 1; }

#mg-stage {
  position: relative;
}

#mg-stage-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 8px;
  border-radius: 12px;
  background-color: var(--mg-check-b);
  background-image:
    linear-gradient(45deg, var(--mg-check-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--mg-check-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--mg-check-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--mg-check-a) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#mg-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  touch-action: none;
  cursor: default;
}

#mg-canvas.is-ready { cursor: grab; }
#mg-canvas.is-ready:active { cursor: grabbing; }

.mg-stage-empty {
  margin: 0;
  color: var(--mg-muted);
  text-align: center;
  padding: 24px 12px;
}

#mg-stage[data-ready] .mg-stage-empty { display: none; }

.mg-crop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.mg-props {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--mg-line);
}

.mg-swatch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.mg-guide {
  margin: 1.5rem 0 2rem;
  max-width: 78ch;
}

.mg-guide h2 {
  margin: 1.2rem 0 0.6rem;
  color: var(--mg-gold);
  font-size: 1.35rem;
}

.mg-guide h3 {
  margin: 1rem 0 0.4rem;
  font-family: var(--mg-serif);
  font-size: 1.05rem;
  font-weight: 600;
}

.mg-guide ol,
.mg-guide ul { margin: 0.4rem 0 0.8rem; padding-left: 1.25rem; }
.mg-guide li { margin: 0.4rem 0; }
.mg-guide p { margin: 0.4rem 0 0.8rem; max-width: 78ch; }

body.mg-tool .mg-page-footer {
  border-top: 1px solid var(--mg-line);
  margin-top: 35px;
  padding-top: 20px;
  font-size: 14px;
  color: var(--mg-muted);
}

body.mg-tool .mg-page-footer p { margin: 0.4rem 0; }

body.mg-tool .mg-page-footer .wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--mg-ink);
  font: 600 1rem/1.5 var(--mg-serif);
  text-decoration: none;
}

body.mg-tool .mg-license-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 14px;
}
body.mg-tool .mg-license-table th,
body.mg-tool .mg-license-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--mg-line);
  vertical-align: top;
}

@media (min-width: 851px) {
  .mg-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 16px 20px;
  }
  .mg-input-panel { grid-column: 1; grid-row: 1 / span 2; }
  .mg-stage-panel {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 15px;
  }
  .mg-edit-panel { grid-column: 2; grid-row: 2; }
  #mg-stage-frame { min-height: 280px; }
}

@media (min-width: 1100px) {
  #mg-drop { min-height: 200px; }
}

@media (prefers-reduced-motion: no-preference) {
  #mg-drop,
  body.mg-tool button,
  body.mg-tool .mg-button,
  .mg-thumb,
  .mg-sticker-btn,
  .mg-emoji-btn {
    transition: border-color 0.15s ease, background-color 0.15s ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.mg-tool *,
  body.mg-tool *::before,
  body.mg-tool *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  #mg-drop,
  .mg-panel,
  .mg-thumb,
  body.mg-tool button,
  body.mg-tool .mg-button {
    border: 2px solid CanvasText;
  }
  body.mg-tool .mg-primary,
  body.mg-tool button[aria-pressed="true"] {
    background: Highlight;
    color: HighlightText;
  }
  #mg-stage-frame { background: Canvas; }
}

@media print {
  .mg-skip,
  .oddsprig-nav-header,
  .oddsprig-theme-actions,
  .oddsprig-theme-dock,
  #mg-drop,
  .mg-drop-actions,
  .mg-edit-panel,
  .mg-guide,
  .mg-page-footer { display: none !important; }
  body.mg-tool,
  body.mg-tool .mg-panel {
    background: #fff !important;
    color: #111 !important;
  }
  .mg-workspace { display: block; }
  .mg-stage-panel { position: static; }
}

@media (max-width: 650px) {
  body.mg-tool.oddsprig-shared-shell main#main,
  body.mg-tool:not(.oddsprig-shared-shell) main#main {
    padding: 16px 0 36px;
  }
  .mg-panel { padding: 16px; }
  .mg-drop-actions button,
  .mg-drop-actions .mg-button,
  .mg-toolbar-row button,
  .mg-toolbar-row .mg-button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
}
