
:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  color: #161616;
  background: #f3f3f5;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(255,255,255,.95), rgba(243,243,245,1) 45%);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 900px);
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top))
    16px
    calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  color: #777;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 6vw, 34px);
  letter-spacing: -0.04em;
}

h2 {
  margin: 0;
  font-size: 18px;
}

.ghost-btn,
.primary-btn,
.secondary-btn,
.layout-option,
.format-option,
.action-btn,
.small-btn,
.icon-btn {
  border: 0;
  cursor: pointer;
}

.ghost-btn {
  background: rgba(255,255,255,.85);
  border: 1px solid #dedee3;
  border-radius: 999px;
  padding: 10px 15px;
}

.workspace-card,
.controls {
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(220,220,226,.9);
  box-shadow: 0 18px 55px rgba(0,0,0,.07);
  backdrop-filter: blur(18px);
}

.workspace-card {
  border-radius: 28px;
  overflow: hidden;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  overflow: hidden;
  touch-action: none;
}

.ratio-1-1 { aspect-ratio: 1 / 1; }
.ratio-4-5 { aspect-ratio: 4 / 5; }
.ratio-16-9 { aspect-ratio: 16 / 9; }
.ratio-9-16 { aspect-ratio: 9 / 16; }

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 28px;
  text-align: center;
  color: #6f6f75;
  pointer-events: none;
}

.empty-state.hidden { display: none; }
.empty-state strong { color: #252529; font-size: 19px; }

.empty-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255,255,255,.92);
  border: 1px solid #dddde2;
  font-size: 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,.07);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
}

.primary-btn,
.secondary-btn {
  min-height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-weight: 750;
}

.primary-btn { background: #111; color: white; }
.secondary-btn { background: #ececf1; color: #151515; }

.controls {
  margin-top: 16px;
  border-radius: 24px;
  padding: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-gap { margin-top: 22px; }
.section-head span { font-size: 13px; color: #777; }

.format-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.format-option {
  min-height: 44px;
  border-radius: 13px;
  background: #f2f2f5;
  font-weight: 750;
}

.format-option.active {
  background: #171717;
  color: white;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.layout-option {
  padding: 9px;
  background: #f5f5f7;
  border: 2px solid transparent;
  border-radius: 16px;
  min-width: 0;
}

.layout-option.active {
  background: white;
  border-color: #151515;
}

.layout-option b {
  display: block;
  margin-top: 7px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-layout {
  height: 56px;
  display: grid;
  gap: 3px;
  background: white;
  border-radius: 9px;
  overflow: hidden;
  padding: 3px;
}

.mini-layout i { background: #c9c9ce; border-radius: 3px; }
.mini-layout.grid4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.mini-layout.leftBig { grid-template-columns: 1.2fr .8fr; grid-template-rows: 1fr 1fr; }
.mini-layout.leftBig i:first-child { grid-row: 1 / 3; }
.mini-layout.topBig { grid-template-columns: 1fr 1fr; grid-template-rows: 1.15fr .85fr; }
.mini-layout.topBig i:first-child { grid-column: 1 / 3; }
.mini-layout.strips { grid-template-columns: repeat(4, 1fr); }

.selection-panel {
  margin-top: 18px;
  padding: 14px;
  border-radius: 18px;
  background: #f4f4f7;
  transition: opacity .2s ease;
}

.selection-panel.disabled {
  opacity: .45;
  pointer-events: none;
}

.selection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-label {
  display: block;
  font-size: 12px;
  color: #777;
  margin-bottom: 3px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: white;
  border: 1px solid #dedee3;
  font-size: 20px;
}

.selection-actions,
.order-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.selection-actions { grid-template-columns: 1fr 1fr; }
.order-actions { grid-template-columns: 1fr 1fr; }

.action-btn,
.small-btn {
  min-height: 42px;
  border-radius: 12px;
  background: white;
  border: 1px solid #dedee3;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.action-btn.danger { color: #b42318; }

.zoom-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  color: #555;
  font-size: 13px;
  font-weight: 650;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 16px;
  margin-top: 20px;
}

.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #555;
  font-size: 13px;
  font-weight: 650;
}

input[type="range"] { width: 100%; }

input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 3px;
  border: 1px solid #d6d6dc;
  border-radius: 10px;
  background: white;
}

.hint {
  margin: 17px 0 0;
  color: #727279;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 560px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .layout-grid { gap: 6px; }
  .layout-option { padding: 6px; border-radius: 13px; }
  .mini-layout { height: 48px; }
  .layout-option b { font-size: 10px; }
}


.toolbar-3 {
  grid-template-columns: 1.2fr 1fr 1fr;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.history-btn {
  min-height: 42px;
  border: 1px solid #dedee3;
  background: #f5f5f7;
  border-radius: 12px;
  font-weight: 700;
}

.history-btn:disabled {
  opacity: .4;
  cursor: default;
}

.slot-plus {
  position: absolute;
  pointer-events: none;
}

@media (max-width: 560px) {
  .toolbar-3 { grid-template-columns: 1fr 1fr; }
  .toolbar-3 .file-label { grid-column: 1 / 3; }
}


.drag-ghost {
  position: absolute;
  width: 92px;
  height: 92px;
  border-radius: 18px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 16px 40px rgba(0,0,0,.25);
  border: 3px solid rgba(255,255,255,.96);
  transform: translate(-50%, -50%) scale(.92);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transition: opacity .12s ease, transform .12s ease;
}

.drag-ghost.visible {
  opacity: .92;
  transform: translate(-50%, -50%) scale(1);
}

.drag-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%) translateY(8px);
  background: rgba(20,20,22,.84);
  color: white;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: .15s ease;
  backdrop-filter: blur(10px);
}

.drag-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.canvas-wrap.reorder-mode {
  cursor: grabbing;
}

.canvas-wrap.reorder-mode canvas {
  filter: saturate(.92) brightness(.98);
}

.layout-grid-12 {
  grid-template-columns: repeat(4, 1fr);
}
.layout-option { position: relative; }
.layout-badge {
  position: absolute; top: 5px; right: 5px; z-index: 2;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 999px; background: #171717; color: #fff;
  font-size: 10px; font-weight: 800;
}
.mini-layout.split2 { grid-template-columns:1fr 1fr; }
.mini-layout.split2asym { grid-template-columns:1.7fr .9fr; }
.mini-layout.heroLeft3 { grid-template-columns:1.5fr 1fr; grid-template-rows:1fr 1fr; }
.mini-layout.heroLeft3 i:first-child { grid-row:1/3; }
.mini-layout.heroTop3 { grid-template-columns:1fr 1fr; grid-template-rows:1.2fr .8fr; }
.mini-layout.heroTop3 i:first-child { grid-column:1/3; }
.mini-layout.hero4 { grid-template-columns:1.5fr 1fr; grid-template-rows:repeat(3,1fr); }
.mini-layout.hero4 i:first-child { grid-row:1/4; }
.mini-layout.strips4 { grid-template-columns:repeat(4,1fr); }
.mini-layout.hero5 { grid-template-columns:1.45fr 1fr 1fr; grid-template-rows:1fr 1fr; }
.mini-layout.hero5 i:first-child { grid-row:1/3; }
.mini-layout.mosaic5 { grid-template-columns:1.2fr .8fr 1fr; grid-template-rows:1fr 1fr; }
.mini-layout.mosaic5 i:first-child { grid-row:1/3; }
.mini-layout.grid6 { grid-template-columns:repeat(3,1fr); grid-template-rows:1fr 1fr; }
.mini-layout.hero6 { grid-template-columns:1.5fr 1fr 1fr; grid-template-rows:1fr 1fr 1fr; }
.mini-layout.hero6 i:first-child { grid-row:1/4; }
.mini-layout.mosaic6 { grid-template-columns:1.2fr .8fr 1fr; grid-template-rows:1fr 1fr; }
@media (max-width:560px) {
  .layout-grid-12 { grid-template-columns:repeat(3,1fr); }
}


.mobile-tool-tabs {
  display: none;
}

@media (max-width: 560px) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-shell {
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    padding: 0 12px calc(10px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -10px 35px rgba(0,0,0,.12);
    max-height: min(47vh, 430px);
    overflow: hidden;
    background: rgba(248,248,250,.96);
    backdrop-filter: blur(22px);
  }

  .mobile-control-shell {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 -12px;
    padding: 8px 12px 6px;
    background: rgba(248,248,250,.97);
    border-bottom: 1px solid rgba(220,220,225,.85);
  }

  .mobile-tool-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .mobile-tool-tab {
    min-height: 38px;
    border: 0;
    border-radius: 11px;
    background: #ececf1;
    font-size: 13px;
    font-weight: 750;
  }

  .mobile-tool-tab.active {
    background: #171717;
    color: #fff;
  }

  .tool-panel {
    display: none;
    overflow-y: auto;
    padding: 10px 2px 2px;
    max-height: calc(min(47vh, 430px) - 58px);
    overscroll-behavior: contain;
  }

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

  #formatPanel .history-row {
    margin-bottom: 10px;
  }

  #formatPanel .section-head,
  #layoutPanel .section-head {
    margin-bottom: 8px;
  }

  .format-grid {
    gap: 6px;
  }

  .format-option {
    min-height: 38px;
    font-size: 13px;
  }

  .layout-grid-12 {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding: 2px 2px 8px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .layout-grid-12::-webkit-scrollbar {
    display: none;
  }

  .layout-option {
    flex: 0 0 86px;
    scroll-snap-align: start;
  }

  .mini-layout {
    height: 58px;
  }

  .selection-panel {
    margin-top: 0;
  }

  .settings-grid {
    grid-template-columns: 1fr 92px;
    margin-top: 12px;
  }

  .hint {
    display: none;
  }

  .workspace-card {
    margin-bottom: 0;
  }

  .toolbar {
    padding: 8px;
    gap: 7px;
  }

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

  .topbar {
    margin-bottom: 10px;
  }

  h1 {
    font-size: 26px;
  }
}
