:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #1e2528;
  --muted: #667174;
  --line: #dde4e5;
  --accent: #0f9f8f;
  --accent-2: #ff5a5f;
  --accent-soft: rgba(15, 159, 143, 0.12);
  --shadow: 0 18px 45px rgba(31, 43, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 159, 143, 0.14), transparent 32rem),
    linear-gradient(135deg, #f8fbfb 0%, #edf3f3 100%);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  min-height: 100vh;
}

.control-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(20px);
}

.brand-header,
.preview-topbar,
.section-title,
.quick-actions,
.filter-row,
.toolbar,
.button-grid,
.sticker-row {
  display: flex;
  align-items: center;
}

.brand-header {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 1.75rem;
}

.brand-header h1 {
  letter-spacing: -0.02em;
}

.quick-actions {
  gap: 10px;
  margin-bottom: 18px;
}

.quick-actions .primary {
  flex: 1;
}

.panel-section {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(31, 43, 45, 0.06);
}

.section-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 0.94rem;
  font-weight: 800;
}

.section-title span {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.section-title.compact {
  margin-top: 14px;
}

textarea,
select,
input[type="number"],
input[type="search"] {
  width: 100%;
  color: var(--ink);
  background: #fbfdfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  min-height: 138px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

select,
input[type="number"],
input[type="search"] {
  min-height: 42px;
  padding: 0 11px;
}

textarea:focus,
select:focus,
input[type="number"]:focus,
input[type="search"]:focus {
  background: #ffffff;
  border-color: rgba(15, 159, 143, 0.78);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

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

input[type="color"] {
  width: 100%;
  min-height: 42px;
  padding: 4px;
  background: #fbfdfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[type="file"] {
  width: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
  padding: 4px;
  background: #eef4f4;
  border-radius: 8px;
}

.bullet-label {
  margin-top: 12px;
}

.segment,
.toggle,
.small-button,
.action-button,
.icon-button,
.sticker-button,
.filter-chip {
  border: 0;
  border-radius: 8px;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.segment {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.segment.active,
.filter-chip.active,
.toggle.active {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 20px rgba(15, 159, 143, 0.22);
}

.control-grid {
  display: grid;
  gap: 12px;
}

.control-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.toolbar {
  flex-wrap: wrap;
  gap: 8px;
  margin: 13px 0;
}

.toggle {
  min-width: 42px;
  height: 36px;
  color: var(--ink);
  background: #edf4f3;
  font-weight: 800;
}

.effect-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.effect-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 8px;
  color: var(--ink);
  background: #f4f7f7;
  border-radius: 8px;
}

.preset-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(126px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.text-preset-card {
  min-height: 70px;
  padding: 10px;
  color: #ffffff;
  background: #1e2528;
  border: 0;
  border-radius: 8px;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.text-preset-card span {
  display: block;
  overflow: hidden;
  font-size: 1.1rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-preset-card small {
  display: block;
  margin-top: 7px;
  color: rgba(255, 255, 255, 0.78);
}

.search-input {
  margin-bottom: 10px;
}

.filter-row {
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.filter-chip {
  padding: 7px 10px;
  color: var(--muted);
  background: #eef4f4;
  font-size: 0.78rem;
  font-weight: 800;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 14px;
}

.theme-card {
  position: relative;
  min-height: 96px;
  overflow: hidden;
  color: #ffffff;
  border: 0;
  border-radius: 8px;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.theme-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.42));
}

.theme-card-content {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  z-index: 1;
}

.theme-card strong {
  display: block;
  overflow: hidden;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-card span {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.slider-list {
  display: grid;
  gap: 10px;
  margin-top: 13px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 13px;
}

.action-button,
.icon-button,
.small-button {
  min-height: 40px;
  padding: 0 13px;
  color: var(--ink);
  background: #edf4f3;
  font-weight: 800;
}

.action-button.primary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), #15c5a9);
  box-shadow: 0 12px 28px rgba(15, 159, 143, 0.26);
}

.action-button.danger {
  color: #9b1d27;
  background: #ffe8ea;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.75rem;
}

.icon-button {
  min-height: 38px;
  background: #1e2528;
  color: #ffffff;
}

.action-button:hover,
.icon-button:hover,
.small-button:hover,
.toggle:hover,
.segment:hover,
.filter-chip:hover,
.sticker-button:hover,
.theme-card:hover,
.text-preset-card:hover {
  transform: translateY(-1px);
}

.sticker-row {
  flex-wrap: wrap;
  gap: 8px;
}

.sticker-button {
  width: 38px;
  height: 38px;
  background: #f0f5f5;
  border: 1px solid var(--line);
  font-size: 1.1rem;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  padding: 28px;
}

.preview-block {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0;
  min-width: 0;
}

.inline-preview-slot {
  display: none;
}

.preview-topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.preview-topbar h2 {
  font-size: 1.45rem;
}

.status-pill {
  min-width: 92px;
  padding: 9px 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.preview-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(30, 37, 40, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(30, 37, 40, 0.04) 1px, transparent 1px);
  background-size: 22px 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.artboard-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.artboard {
  position: relative;
  width: min(74vh, 100%);
  max-width: 760px;
  overflow: hidden;
  isolation: isolate;
  background: #101417;
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(30, 37, 40, 0.24);
  transition: aspect-ratio 180ms ease, width 180ms ease;
  touch-action: none;
}

.background-layer,
.custom-bg-layer,
.pattern-layer,
.overlay-layer,
.frame-layer,
.sticker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.background-layer {
  z-index: 0;
}

.custom-bg-layer {
  z-index: 1;
  background-position: center;
  background-size: cover;
}

.pattern-layer {
  z-index: 2;
  opacity: 0.32;
  mix-blend-mode: screen;
}

.overlay-layer {
  z-index: 3;
}

.frame-layer {
  z-index: 6;
}

.text-box {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: 78%;
  color: #ffffff;
  cursor: grab;
  line-height: 1.02;
  overflow-wrap: anywhere;
  transform: translate(-50%, -50%);
  user-select: none;
  white-space: pre-wrap;
  touch-action: none;
}

.text-box:active,
.logo-preview:active {
  cursor: grabbing;
}

.text-box.dragging,
.logo-preview.dragging {
  outline: 2px dashed rgba(255, 255, 255, 0.78);
  outline-offset: 5px;
}

.logo-preview {
  position: absolute;
  z-index: 7;
  object-fit: contain;
  cursor: grab;
  transform: translate(-50%, -50%);
  touch-action: none;
}

.logo-preview.circle,
.logo-preview.badge {
  border-radius: 50%;
}

.logo-preview.square {
  border-radius: 0;
}

.logo-preview.rounded {
  border-radius: 16%;
}

.logo-preview.circle,
.logo-preview.square,
.logo-preview.rounded {
  padding: 12%;
  background: rgba(255, 255, 255, 0.88);
}

.logo-preview.badge {
  padding: 12%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.68));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.logo-preview.watermark {
  filter: grayscale(1);
  mix-blend-mode: screen;
}

.sticker {
  position: absolute;
  z-index: 8;
  font-size: clamp(1.4rem, 5vw, 4rem);
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.22));
  transform: translate(-50%, -50%);
}

.hidden {
  display: none !important;
}

.export-loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(245, 247, 248, 0.72);
  backdrop-filter: blur(8px);
}

.loader-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.loader-card p {
  margin: 0;
  font-weight: 800;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(15, 159, 143, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Mobile nav (hidden on desktop) ─────────────────────────── */
.mobile-nav {
  display: none;
}

/* ── Tablet (≤ 1040 px) ──────────────────────────────────────── */
@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-panel {
    min-height: 70vh;
  }

  .theme-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 320px;
  }
}

/* ── Mobile (≤ 768 px) ───────────────────────────────────────── */
@media (max-width: 768px) {

  /* Reserve space for sticky bottom nav */
  body {
    padding-bottom: 64px;
  }

  .app-shell {
    display: block;
  }

  /* ─ Bottom nav bar ─ */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 24px rgba(30, 37, 40, 0.10);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: none;
    cursor: pointer;
    transition: color 150ms ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-download-btn {
    width: 100%;
    min-height: 52px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--accent), #15c5a9);
    border-radius: 12px;
    margin: 6px 12px;
    box-shadow: 0 10px 24px rgba(15, 159, 143, 0.28);
  }

  .mobile-download-btn svg {
    width: 20px;
    height: 20px;
    color: #ffffff;
  }

  .mobile-nav-btn svg {
    width: 22px;
    height: 22px;
    transition: transform 150ms ease, color 150ms ease;
  }

  /* ─ Inline preview below Post Text ─ */
  .inline-preview-slot {
    display: block;
    margin-bottom: 10px;
  }

  .inline-preview-slot .preview-block {
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(31, 43, 45, 0.06);
  }

  .inline-preview-slot .preview-topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
  }

  .inline-preview-slot .preview-topbar h2 {
    font-size: 1rem;
  }

  .inline-preview-slot .preview-stage {
    min-height: 52vw;
    padding: 8px;
  }

  .inline-preview-slot .artboard-wrap {
    min-height: 48vw;
  }

  .inline-preview-slot .artboard {
    width: 100%;
    max-width: 100%;
  }

  .preview-panel.preview-panel--empty {
    display: none;
  }

  /* ─ Panel layout ─ */
  .control-panel {
    position: relative;
    height: auto;
    overflow-y: visible;
    padding: 16px 14px 80px;
    border-right: 0;
    border-bottom: 0;
  }

  .preview-panel {
    padding: 0;
    min-height: 0;
  }

  /* ─ Typography ─ */
  h1 {
    font-size: 1.45rem;
  }

  .preview-topbar h2 {
    font-size: 1.1rem;
  }

  /* ─ Brand header ─ */
  .brand-header {
    flex-direction: row;
    align-items: center;
    margin-bottom: 14px;
  }

  /* ─ Quick actions ─ */
  .quick-actions {
    gap: 8px;
    margin-bottom: 14px;
  }

  /* ─ Sections ─ */
  .panel-section {
    padding: 14px;
    margin-bottom: 10px;
  }

  /* ─ Grids – keep 2 columns on mobile where it makes sense ─ */
  .control-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .effect-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .theme-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 260px;
  }

  /* ─ Preview ─ */
  .preview-topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
  }

  .status-pill {
    font-size: 0.76rem;
    padding: 6px 10px;
  }

  .preview-stage {
    padding: 10px;
    min-height: 52vw;
  }

  .artboard-wrap {
    min-height: 52vw;
  }

  .artboard {
    width: min(88vw, 440px);
    max-width: 100%;
  }

  /* ─ Touch-friendly targets (≥ 44 px) ─ */
  select,
  input[type="number"],
  input[type="search"] {
    min-height: 44px;
  }

  input[type="color"] {
    min-height: 44px;
  }

  .toggle {
    min-width: 44px;
    height: 42px;
  }

  .segment {
    min-height: 40px;
  }

  .action-button,
  .icon-button {
    min-height: 44px;
  }

  .sticker-button {
    width: 42px;
    height: 42px;
  }

  .filter-chip {
    padding: 8px 11px;
    font-size: 0.80rem;
  }

  .text-preset-card {
    min-height: 66px;
  }
}

/* ── Small phones (≤ 480 px) ─────────────────────────────────── */
@media (max-width: 480px) {
  .control-panel {
    padding: 12px 10px;
  }

  h1 {
    font-size: 1.28rem;
  }

  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 230px;
  }

  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preview-stage {
    min-height: 60vw;
  }

  .artboard-wrap {
    min-height: 60vw;
  }

  .artboard {
    width: 94vw;
    max-width: 100%;
  }

  .effect-grid {
    gap: 6px;
  }

  .toolbar {
    gap: 6px;
  }
}
