:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #121417;
  --muted: #68717d;
  --line: #d9e0e6;
  --coral: #ff4f64;
  --cyan: #13c8e5;
  --lime: #bdff35;
  --shadow: 0 18px 60px rgba(22, 26, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(18, 20, 23, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 20, 23, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 78px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--lime);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button,
.tab {
  border: 0;
  border-radius: 8px;
  transition:
    transform 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 22px;
}

.primary-button {
  min-height: 42px;
  padding: 0 18px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  font-size: 14px;
}

.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 750;
  font-size: 13px;
}

.danger-button {
  min-height: 42px;
  padding: 0 14px;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 800;
  font-size: 13px;
}

.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:not(:disabled):hover,
.icon-button:hover,
.tab:hover {
  transform: translateY(-1px);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 390px;
  gap: 22px;
  padding: 22px;
}

.stage-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  gap: 12px;
}

.canvas-frame {
  width: min(100%, 52vh);
  min-width: 300px;
  max-width: 470px;
  aspect-ratio: 9 / 16;
  padding: 10px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #15181c;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: white;
  touch-action: none;
  cursor: grab;
}

canvas.dragging {
  cursor: grabbing;
}

.trash-zone {
  width: min(100%, 470px);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px dashed #b9c2cc;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.trash-zone.visible {
  border-color: #6b7280;
  color: var(--ink);
  transform: translateY(-1px);
}

.trash-zone.armed {
  border-color: #ff4f64;
  background: rgba(255, 79, 100, 0.12);
  color: #b91c1c;
}

.trash-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  color: currentColor;
  font-size: 18px;
}

.stage-footer {
  width: min(100%, 470px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.inspector {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 40px rgba(22, 26, 31, 0.08);
  overflow: hidden;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tab {
  min-height: 38px;
  padding: 0 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tab.active {
  background: var(--ink);
  color: white;
}

.tab-panel {
  display: none;
  padding: 18px;
}

.tab-panel.active {
  display: block;
}

.template-filters {
  display: flex;
  gap: 7px;
  margin: -4px 0 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.save-format {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin: -4px 0 12px;
}

.save-format input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 11px;
  font-size: 13px;
}

.filter-chip {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.filter-chip.active {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.panel-head {
  margin-bottom: 16px;
}

.panel-head.small {
  margin: 4px 0 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tool-section {
  margin: 16px 0 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.text-layer-list {
  display: flex;
  gap: 7px;
  margin: -4px 0 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.text-layer-button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.text-layer-button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  max-height: calc(100vh - 250px);
  overflow: auto;
  padding-right: 3px;
}

.template-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.template-card.active {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.template-thumb {
  height: 120px;
  border-radius: 7px;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
}

.template-thumb::before,
.template-thumb::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.template-thumb::before {
  width: 86px;
  height: 86px;
  right: -18px;
  top: 12px;
  background: rgba(255, 255, 255, 0.32);
}

.template-thumb::after {
  width: 72%;
  height: 16px;
  left: 12px;
  bottom: 22px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 22px 0 rgba(255, 255, 255, 0.72);
}

.template-card strong {
  display: block;
  font-size: 13px;
  line-height: 1.2;
}

.template-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input[type="text"],
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.field select {
  min-height: 42px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 18px / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 12px) 18px / 6px 6px no-repeat,
    white;
}

.field textarea {
  resize: vertical;
}

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

.field input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.check-field {
  min-height: 42px;
  margin-bottom: 14px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.check-field input {
  width: 17px;
  height: 17px;
  accent-color: var(--ink);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.upload-box {
  min-height: 118px;
  margin-bottom: 12px;
  display: grid;
  place-items: center;
  border: 1px dashed #9ba6b2;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
}

.upload-box input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.wide {
  width: 100%;
}

.export-actions {
  display: grid;
  gap: 10px;
}

.export-note {
  margin-top: 14px;
  padding: 14px;
  display: grid;
  gap: 6px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.5;
}

.export-note.compact {
  margin-top: 2px;
}

.export-note span {
  color: var(--muted);
}

.payment-card {
  margin-bottom: 12px;
  padding: 14px;
  display: grid;
  gap: 12px;
  border: 1px solid #111318;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(22, 26, 31, 0.08);
}

.payment-card strong,
.payment-card span,
.payment-card small {
  display: block;
}

.payment-card strong {
  font-size: 16px;
  line-height: 1.35;
}

.payment-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.payment-card small {
  margin-top: 6px;
  color: #8a5a00;
  font-size: 11px;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .canvas-frame {
    width: min(100%, 440px);
    min-width: 0;
  }

  .inspector {
    order: 2;
  }
}

@media (max-width: 560px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
    background-size: 18px 18px;
  }

  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    grid-template-rows: 48px 1fr;
    overflow: hidden;
  }

  .topbar {
    height: 48px;
    padding: 6px 10px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 4;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    font-size: 12px;
  }

  .brand h1 {
    font-size: 14px;
  }

  .brand p {
    display: none;
  }

  .topbar-actions {
    width: auto;
    gap: 6px;
    margin-left: auto;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .topbar .primary-button {
    min-height: 34px;
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .workspace {
    height: calc(100dvh - 48px);
    min-height: 0;
    display: block;
    padding: 8px 10px calc(45dvh + 14px);
    overflow: hidden;
    position: relative;
  }

  .stage-panel {
    height: 100%;
    grid-template-rows: minmax(0, 1fr) auto auto;
    align-content: start;
    gap: 7px;
  }

  .canvas-frame {
    width: min(100%, calc((55dvh - 74px) * 9 / 16));
    max-width: 100%;
    max-height: calc(55dvh - 74px);
    min-width: 0;
    padding: 6px;
    border-radius: 10px;
    align-self: start;
  }

  canvas {
    border-radius: 6px;
  }

  .trash-zone {
    width: min(100%, 330px);
    min-height: 34px;
    gap: 6px;
    font-size: 11px;
    border-radius: 8px;
  }

  .trash-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: 14px;
  }

  .stage-footer {
    width: min(100%, 330px);
    flex-direction: row;
    align-items: center;
    font-size: 10px;
  }

  .inspector {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    height: 45dvh;
    min-height: 300px;
    max-height: 430px;
    display: grid;
    grid-template-rows: 58px minmax(0, 1fr);
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -18px 50px rgba(22, 26, 31, 0.18);
    overflow: hidden;
  }

  .tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: white;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    min-width: 88px;
    min-height: 38px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: 12px;
  }

  .tab.active {
    background: var(--ink);
  }

  .tab-panel {
    min-height: 0;
    overflow-y: auto;
    padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .panel-head {
    margin-bottom: 12px;
  }

  .panel-head h2 {
    font-size: 16px;
  }

  .panel-head p {
    font-size: 11px;
  }

  .template-grid {
    max-height: none;
    overflow: visible;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding-right: 0;
  }

  .template-thumb {
    height: 84px;
  }

  .template-card {
    padding: 8px;
  }

  .template-card strong {
    font-size: 12px;
  }

  .template-card span {
    font-size: 10px;
  }

  .template-filters,
  .text-layer-list {
    gap: 6px;
    margin-bottom: 10px;
  }

  .filter-chip,
  .text-layer-button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 12px;
  }

  .save-format {
    grid-template-columns: 1fr auto auto;
    gap: 6px;
  }

  .save-format input {
    min-height: 38px;
  }

  .two-col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .field {
    gap: 6px;
    margin-bottom: 11px;
  }

  .field span {
    font-size: 11px;
  }

  .field input[type="text"],
  .field textarea,
  .field select {
    min-height: 42px;
    padding: 10px 11px;
    font-size: 16px;
    border-radius: 8px;
  }

  .field textarea {
    min-height: 86px;
  }

  .field input[type="range"] {
    min-height: 34px;
  }

  .check-field {
    min-height: 42px;
    margin-bottom: 11px;
    font-size: 12px;
  }

  .primary-button,
  .secondary-button,
  .danger-button {
    min-height: 42px;
    font-size: 13px;
  }

  .tool-section {
    margin: 12px 0;
    padding: 12px;
  }

  .upload-box {
    min-height: 78px;
    margin-bottom: 10px;
  }

  .export-note {
    margin-top: 10px;
    padding: 11px;
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .topbar .primary-button {
    max-width: 116px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand h1 {
    max-width: 124px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
