/* Meme creator — layout on top of style.css (masthead, content, footer, font picker are shared) */

.meme-app {
  width: min(1140px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3rem 0 2.5rem;
  scroll-margin-top: 70px;
}

.meme-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.72fr);
  gap: 1.25rem;
  align-items: start;
  animation: in 0.5s 0.05s ease both;
}

.meme-card {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 18px;
  box-shadow: 8px 8px 0 var(--ink);
  min-width: 0;
}

/* —— Canvas side —— */
.meme-stage {
  padding: 0.9rem;
}

.canvas-frame {
  display: grid;
  place-items: center;
  background: #f3f3f1;
  border-radius: 12px;
  min-height: 280px;
  overflow: hidden;
}

#meme {
  display: block;
  max-width: 100%;
  max-height: min(72vh, 760px);
  width: auto;
  height: auto;
  touch-action: none;
  cursor: grab;
}

#meme.is-drag {
  cursor: grabbing;
}

/* —— Canvas toolbar —— */
.stage-bar {
  margin-top: 0.85rem;
  padding: 0.75rem;
  background: #f6f6f3;
  border: 1.5px solid var(--line, #e3e3df);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stage-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 36px;
  margin: 0;
}

.tool-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted, #666);
  white-space: nowrap;
  line-height: 1;
}

.stage-tools .btn {
  padding: 0 0.85rem;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  gap: 0.4rem;
}

.stage-tools .btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted, #666);
}

.stage-tools .btn.ghost:hover:not(:disabled) {
  background: #fff;
  border-color: var(--ink);
  color: var(--ink);
}

.stage-tools .btn.accent {
  background: var(--ink);
  color: #fff;
}

.stage-bar .dl-wrap {
  width: 100%;
  margin: 0;
}

.stage-bar .dl-wrap > .btn {
  width: 100%;
  height: 52px;
  gap: 0.6rem;
  font-size: 1.02rem;
  font-weight: 800;
  border-radius: 14px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.25);
}

.stage-bar .dl-wrap > .btn:hover {
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.35);
}

.stage-bar .dl-wrap > .btn .dl-caret {
  opacity: 0.7;
  margin-left: 0.15rem;
}

.stage-bar .dl-menu {
  left: 0;
  right: 0;
  min-width: 0;
}

.brush-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.75rem;
  padding-top: 0.15rem;
}

.brush-bar .seg-ctrl button {
  font-size: 0.78rem;
}

.brush-size-wrap input[type="range"] {
  width: 96px;
}

#meme.is-brush-remove,
#meme.is-brush-paint {
  cursor: crosshair;
}

.tr-history {
  border-top: 1px solid var(--line, #e3e3df);
  padding-top: 0.7rem;
}

.tr-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.tr-history-clear {
  border: 0;
  background: transparent;
  color: var(--muted, #666);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
}

.tr-history-clear:hover {
  color: var(--ink, #111);
  text-decoration: underline;
}

.tr-history-list {
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: thin;
}

.tr-history-item {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border: 2px solid #111;
  border-radius: 10px;
  padding: 0;
  background: #111;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.18);
}

.tr-history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tr-history-item:hover,
.tr-history-item.is-on {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.tool-divider {
  width: 1px;
  height: 22px;
  background: var(--line, #ddd);
  flex: none;
}

/* Segmented toggle (Fill | Fit) */
.seg-ctrl {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 11px;
}

.seg-ctrl button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  height: 28px;
  padding: 0 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-ctrl button:hover:not(.is-on) {
  background: #efefec;
}

.seg-ctrl button.is-on {
  background: var(--ink);
  color: #fff;
}

.seg-ctrl button:focus-visible,
.size-chip:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Background colour chip */
.color-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 36px;
  padding: 0 0.7rem 0 0.35rem;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 11px;
  cursor: pointer;
}

.color-chip:hover {
  box-shadow: 2px 2px 0 var(--ink);
}

.color-chip input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1.5px solid rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  flex: none;
  -webkit-appearance: none;
  appearance: none;
}

.color-chip input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-chip input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color-chip input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }

.color-hex {
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Canvas size presets */
.size-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.size-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 36px;
  padding: 0 0.8rem 0 0.6rem;
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 11px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.size-chip small {
  font-size: 0.68rem;
  font-weight: 600;
  opacity: 0.6;
}

.size-chip:hover:not(.is-on) {
  transform: translateY(-1px);
  box-shadow: 2px 2px 0 var(--ink);
}

.size-chip.is-on {
  background: var(--ink);
  color: #fff;
}

.size-ico {
  display: inline-block;
  border: 1.6px solid currentColor;
  border-radius: 2px;
  flex: none;
}

.size-ico.r-1-1 { width: 14px; height: 14px; }
.size-ico.r-4-5 { width: 12px; height: 15px; }
.size-ico.r-16-9 { width: 18px; height: 10px; }
.size-ico.r-9-16 { width: 9px; height: 16px; }

.stage-hint {
  margin: 0;
  font-size: 0.74rem;
  color: var(--muted, #666);
}

.visually-hidden-select {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* —— Controls side —— */
.meme-panel {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.meme-panel .row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meme-panel .field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  min-width: 0;
}

.field-label {
  display: block;
}

.meme-panel .pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 0.75rem;
  width: 100%;
}

#textControls,
#imageControls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.slider-val {
  flex: none;
  min-width: 2.6rem;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted, #666);
  font-variant-numeric: tabular-nums;
}

.image-edit-actions {
  width: 100%;
}

.image-edit-actions .btn {
  flex: 1 1 auto;
  min-width: 4.2rem;
}

/* Caption box: override the converter textarea defaults from style.css */
.meme-panel textarea#text {
  min-height: 96px;
  height: auto;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  padding: 0.6rem 0.75rem;
  font-family: var(--font-sinhala);
  font-size: 1.05rem;
  line-height: 1.5;
  resize: vertical;
}

.meme-panel textarea#text.lang-en {
  font-family: var(--font-ui);
  font-size: 0.98rem;
}

.meme-panel textarea#text:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.meme-select {
  width: 100%;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}

.tool-field .meme-select {
  width: auto;
  height: 36px;
  padding: 0 0.55rem;
  line-height: 33px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
}

input[type="color"] {
  width: 46px;
  height: 32px;
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.icon-btn.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.icon-btn svg {
  display: block;
  flex: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.seg {
  display: flex;
  gap: 0.35rem;
}

.seg .btn.is-on {
  background: var(--ink);
  color: #fff;
}

.swatch {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  min-height: 40px;
  padding: 0.15rem 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.5rem;
  padding-top: 0.15rem;
}

.check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
}

.meme-panel [hidden] {
  display: none !important;
}

.meme-panel .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.45;
}

/* Font picker: full width in the panel, menu hangs below with previews */
.meme-panel .font-picker-btn {
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 42px;
  padding: 0 0.75rem 0 0.6rem;
  font-size: 0.9rem;
}

.meme-panel .font-picker-sample {
  width: 1.7rem;
  height: 1.7rem;
  font-size: 1.05rem;
}

.meme-panel .font-picker-label {
  font-size: 1rem;
  font-weight: 600;
}

.meme-panel .font-picker-menu {
  left: 0;
  right: 0;
  width: auto;
  max-height: 24rem;
}

.meme-panel .font-picker-option-sample {
  width: 2.3rem;
  height: 2.3rem;
  font-size: 1.2rem;
}

.meme-panel .font-picker-option-name {
  font-size: 1rem;
  font-weight: 600;
}

.meme-panel .font-picker-option-preview {
  font-size: 0.86rem;
}

/* Download menu */
.dl-wrap {
  position: relative;
}

.dl-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 30;
  min-width: 150px;
  padding: 0.3rem;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 3px 3px 0 var(--ink);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.dl-menu[hidden] {
  display: none !important;
}

.dl-menu button {
  appearance: none;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  text-align: left;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}

.dl-menu button:hover {
  background: var(--ink);
  color: #fff;
}

/* SEO sections */
.meme-font-list {
  margin-top: 0.75rem;
}

.content .split > div > h3 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.foot-inner a {
  color: var(--muted);
  text-decoration: none;
}

.foot-inner a:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* Picture and canvas are not draggable / savable via right-click (contextmenu blocked in JS) */
.meme-page img,
.meme-page canvas {
  -webkit-user-drag: none;
  user-select: none;
}

@media (max-width: 860px) {
  .meme-page {
    overflow-x: clip;
  }

  .meme-app {
    width: min(100% - 1rem, 1140px);
    padding: 1.25rem 0 2rem;
  }

  .meme-app > .intro {
    max-width: none;
    margin-bottom: 1.15rem;
  }

  .meme-app > .intro h1 {
    font-size: clamp(1.55rem, 7vw, 2.2rem);
  }

  .meme-app > .intro p {
    font-size: 0.95rem;
  }

  .meme-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .meme-card {
    box-shadow: 4px 4px 0 var(--ink);
    border-radius: 14px;
  }

  .meme-stage {
    padding: 0.65rem;
  }

  .canvas-frame {
    min-height: 220px;
    border-radius: 10px;
  }

  #meme {
    max-width: 100%;
    max-height: min(58vh, 520px);
    touch-action: none;
  }

  .stage-bar {
    padding: 0.65rem;
    gap: 0.65rem;
    border-radius: 12px;
  }

  .stage-tools {
    gap: 0.55rem;
  }

  .stage-tools .tool-divider {
    display: none;
  }

  .stage-tools .tool-group {
    display: flex;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .stage-tools .btn {
    flex: 1 1 calc(50% - 0.3rem);
    min-width: 0;
    justify-content: center;
    height: 42px;
    padding: 0 0.55rem;
    font-size: 0.78rem;
  }

  .stage-tools .seg-ctrl {
    flex: 1 1 auto;
  }

  .stage-tools .seg-ctrl button {
    flex: 1;
    min-height: 40px;
  }

  .stage-tools .color-chip {
    flex: 1 1 auto;
    min-width: 0;
  }

  .brush-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
  }

  .brush-bar > .tool-label {
    flex: 0 0 auto;
  }

  .brush-bar .seg-ctrl {
    flex: 1 1 auto;
  }

  .brush-bar .seg-ctrl button {
    flex: 1;
    min-height: 40px;
  }

  .brush-size-wrap {
    flex: 1 1 100%;
  }

  .brush-size-wrap input[type="range"] {
    width: min(100%, 180px);
    flex: 1;
  }

  .brush-bar > .btn {
    flex: 1 1 calc(50% - 0.3rem);
    justify-content: center;
    min-height: 42px;
  }

  .size-presets {
    gap: 0.4rem;
  }

  .size-presets > .tool-label {
    flex: 1 1 100%;
  }

  .size-chip {
    flex: 1 1 calc(50% - 0.25rem);
    justify-content: center;
    min-width: 0;
    height: 40px;
    padding: 0 0.45rem;
    font-size: 0.76rem;
  }

  .img-zoom {
    width: 100%;
  }

  .img-zoom input[type="range"] {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .stage-bar .dl-wrap > .btn {
    height: 48px;
    font-size: 0.95rem;
  }

  .meme-panel {
    padding: 0.9rem;
    gap: 0.85rem;
  }

  .meme-panel .row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .meme-panel .row .btn {
    width: 100%;
    justify-content: center;
    min-height: 42px;
  }

  .meme-panel .pair {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }

  .meme-panel .seg {
    width: 100%;
  }

  .meme-panel .seg .btn {
    flex: 1;
    justify-content: center;
  }

  .meme-panel textarea#text {
    min-height: 96px;
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  .meme-panel .meme-select,
  .meme-panel input[type="range"] {
    font-size: 16px;
  }

  .tr-history-item {
    width: 64px;
    height: 64px;
  }

  /* Nested share bar must not use 100vw + translate (overflows page) */
  .meme-app .share-bar {
    width: 100%;
    max-width: 100%;
    left: auto;
    translate: none;
    margin-left: 0;
  }

  .meme-app .share-bar-links {
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .meme-app {
    width: calc(100% - 0.75rem);
    padding-top: 1rem;
  }

  .meme-app > .intro .eyebrow {
    font-size: 0.65rem;
    padding: 0.28rem 0.65rem;
  }

  .stage-tools .btn {
    flex: 1 1 100%;
  }

  .color-chip {
    max-width: 100%;
  }

  .color-hex {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .size-chip small {
    display: none;
  }

  .meme-panel .pair {
    grid-template-columns: 1fr;
  }

  .meme-panel .swatch {
    width: 100%;
    justify-content: space-between;
  }

  .checks {
    gap: 0.75rem 1rem;
  }

  .dl-wrap .btn {
    width: 100%;
  }
}
