:root {
  --blue: #1687d9;
  --blue-dark: #075c9f;
  --teal: #007f89;
  --teal-dark: #005c64;
  --green: #76dd55;
  --ink: #17323f;
  --muted: #5e7480;
  --line: #d7e6ea;
  --panel: #ffffff;
  --surface: #f4f9fa;
  --shadow: 0 18px 50px rgba(10, 62, 82, 0.12);
  color: var(--ink);
  background: var(--surface);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--surface);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.upload-control:focus-within {
  outline: 3px solid rgba(22, 135, 217, 0.24);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  height: 100svh;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(10, 62, 82, 0.08);
}

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

.brand-logo {
  width: clamp(120px, 18vw, 220px);
  height: 58px;
  object-fit: contain;
  object-position: left center;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header h1,
.preview-header h2,
.section-heading h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: 34px;
  line-height: 1.08;
}

.header-status,
.quality-note {
  flex: 0 0 auto;
  border: 1px solid #c7eeda;
  border-radius: 999px;
  padding: 7px 12px;
  color: #135d38;
  background: #effcf4;
  font-size: 13px;
  font-weight: 800;
}

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

.controls-panel,
.preview-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.control-section {
  display: grid;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.control-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-heading h2 {
  font-size: 18px;
  line-height: 1.2;
}

.step-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--blue);
  font-size: 14px;
  font-weight: 900;
}

.upload-control,
.upload-drop-zone,
.fit-toggle,
.primary-action,
.secondary-action,
.folder-action,
.platform-grid button,
.fit-grid button,
.color-grid button,
.segmented-row button,
.segmented-grid button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid #bed8df;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

.upload-control {
  gap: 10px;
  width: 100%;
  padding: 13px 14px;
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
}

.upload-control:hover,
.primary-action:hover:not(:disabled) {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.upload-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.upload-drop-zone {
  gap: 12px;
  width: 100%;
  min-height: 88px;
  padding: 14px;
  border: 2px dashed #92c9d9;
  color: var(--ink);
  background: #f5fbfd;
  text-align: left;
}

.upload-drop-zone:hover,
.upload-drop-zone.drag-active {
  border-color: var(--teal);
  background: #eefafa;
}

.upload-drop-zone span:last-child {
  display: grid;
  gap: 3px;
}

.upload-drop-zone small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.drop-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--teal);
  font-size: 26px;
  line-height: 1;
}

.file-summary,
.logo-status,
.output-summary,
.text-summary,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.logo-status {
  border-left: 4px solid var(--green);
  padding: 8px 10px;
  background: #f1fbf4;
  color: #254d38;
  font-weight: 700;
}

.control-group {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  border: 0;
}

.control-group legend {
  margin-bottom: 9px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.segmented-row,
.segmented-grid,
.platform-grid,
.fit-grid,
.color-grid {
  display: grid;
  gap: 8px;
}

.segmented-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

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

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

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

.platform-grid button,
.fit-grid button,
.color-grid button,
.segmented-row button,
.segmented-grid button {
  min-width: 0;
  padding: 8px 10px;
  color: var(--ink);
  background: #f7fbfc;
}

.platform-grid button,
.fit-grid button {
  display: grid;
  gap: 3px;
  min-height: 62px;
}

.color-option {
  gap: 8px;
}

.color-swatch {
  display: block;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(23, 50, 63, 0.28);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.platform-grid button small,
.fit-grid button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.platform-grid button.selected small,
.fit-grid button.selected small {
  color: rgba(255, 255, 255, 0.86);
}

.advanced-controls,
.manual-crop-controls,
.text-position-controls {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbfc;
}

.advanced-controls[hidden],
.manual-crop-controls[hidden] {
  display: none;
}

.advanced-controls {
  border-color: #bfe3ea;
  background: #f2fbfb;
}

.advanced-mode-toggle-row {
  border-color: rgba(0, 127, 137, 0.42);
  background: #eefafa;
}

.advanced-mode-toggle-row:has(input:checked) {
  border-color: var(--teal);
  background: #e2f8f8;
}

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

.range-control {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.range-control span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.range-control output {
  color: var(--muted);
  font-weight: 800;
}

.range-control input {
  width: 100%;
  accent-color: var(--teal);
}

.manual-crop-reset,
.text-position-reset {
  width: 100%;
  background: #ffffff;
}

.fit-toggle {
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 12px;
  color: var(--ink);
  background: #f7fbfc;
}

.fit-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.fit-toggle span {
  display: grid;
  gap: 2px;
}

.fit-toggle small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.platform-grid button:hover,
.fit-grid button:hover,
.color-grid button:hover,
.segmented-row button:hover,
.segmented-grid button:hover {
  border-color: var(--teal);
}

.platform-grid button.selected,
.fit-grid button.selected,
.color-grid button.selected,
.segmented-row button.selected,
.segmented-grid button.selected {
  border-color: var(--teal);
  color: #ffffff;
  background: var(--teal);
}

.text-field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.text-stack {
  display: grid;
  gap: 10px;
}

.text-field textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid #bed8df;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #f7fbfc;
  font: inherit;
  font-weight: 700;
  line-height: 1.4;
}

.text-field textarea.text-headline-input,
.text-field textarea.text-emphasis-input {
  min-height: 72px;
}

.text-field textarea.text-emphasis-input {
  border-color: rgba(255, 49, 49, 0.42);
  background: #fff8f8;
}

.text-field textarea:focus {
  outline: 3px solid rgba(22, 135, 217, 0.24);
  outline-offset: 2px;
}

.text-field textarea.text-emphasis-input:focus {
  outline-color: rgba(255, 49, 49, 0.22);
}

.actions-section {
  margin-top: auto;
}

.action-row {
  display: grid;
  grid-template-columns: 0.75fr 1.4fr;
  gap: 10px;
}

.primary-action,
.secondary-action,
.folder-action {
  padding: 11px 12px;
}

.primary-action {
  border-color: var(--blue);
  color: #ffffff;
  background: var(--blue);
}

.primary-action:disabled {
  cursor: not-allowed;
  border-color: #cfdee3;
  color: #6a808b;
  background: #e9f1f3;
}

.secondary-action {
  color: var(--teal-dark);
  background: #ffffff;
}

.folder-action {
  width: 100%;
  color: var(--teal-dark);
  background: #eefafa;
}

.secondary-action:hover,
.folder-action:hover {
  border-color: var(--teal);
  background: #f2fbfb;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.preview-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.preview-header h2 {
  font-size: 22px;
  line-height: 1.15;
}

.mobile-preview-toggle {
  display: none;
  min-height: 36px;
  border: 1px solid #bed8df;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--teal-dark);
  background: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.preview-frame {
  position: relative;
  display: grid;
  height: 100%;
  place-items: center;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(45deg, #e0eef2 25%, transparent 25%),
    linear-gradient(-45deg, #e0eef2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0eef2 75%),
    linear-gradient(-45deg, transparent 75%, #e0eef2 75%);
  background-color: #f8fcfd;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.preview-frame.drag-active {
  outline: 4px solid rgba(22, 135, 217, 0.34);
  outline-offset: -8px;
}

.drop-overlay {
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--blue);
  border-radius: 8px;
  color: var(--blue-dark);
  background: rgba(255, 255, 255, 0.78);
  font-size: 24px;
  font-weight: 900;
  pointer-events: none;
  z-index: 3;
}

canvas {
  display: block;
  max-width: 100%;
  max-height: min(68vh, 720px);
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 14px 36px rgba(10, 62, 82, 0.16);
}

canvas[width="0"] {
  box-shadow: none;
}

.preview-frame.crop-drag-ready canvas {
  cursor: grab;
}

.preview-frame.crop-dragging canvas {
  cursor: grabbing;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 360px;
  padding: 28px;
  text-align: center;
  color: #3f5965;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 2px solid var(--blue);
  border-radius: 8px;
  color: var(--blue);
  background: #ffffff;
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}

.empty-state h2 {
  font-size: 26px;
  line-height: 1.15;
}

.empty-state p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
}

.mobile-save-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background: rgba(23, 50, 63, 0.44);
}

.mobile-save-dialog {
  display: grid;
  gap: 14px;
  width: min(100%, 520px);
  max-height: min(820px, 92svh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(10, 62, 82, 0.28);
  -webkit-overflow-scrolling: touch;
}

.mobile-save-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.mobile-save-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.save-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid #bed8df;
  border-radius: 50%;
  color: var(--ink);
  background: #ffffff;
  font-weight: 900;
}

.mobile-save-image {
  display: block;
  width: 100%;
  max-height: 52svh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e0eef2 25%, transparent 25%),
    linear-gradient(-45deg, #e0eef2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0eef2 75%),
    linear-gradient(-45deg, transparent 75%, #e0eef2 75%);
  background-color: #f8fcfd;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.mobile-save-actions {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 10px;
}

.mobile-download-link {
  text-decoration: none;
}

.mobile-save-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
    overflow: visible;
  }

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

  .controls-panel {
    overflow: visible;
  }

  .preview-panel {
    min-height: 520px;
  }

  .preview-frame {
    height: auto;
    min-height: 520px;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    gap: 12px;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .brand-logo {
    width: min(70vw, 220px);
    height: 54px;
  }

  .app-header h1 {
    font-size: 28px;
  }

  .header-status,
  .quality-note {
    max-width: 100%;
    white-space: normal;
  }

  .workspace {
    gap: 12px;
  }

  .controls-panel {
    order: 2;
    padding: 14px;
  }

  .actions-section {
    margin-top: 0;
  }

  .preview-panel {
    position: sticky;
    top: 0;
    order: 1;
    z-index: 8;
    min-height: 0;
    box-shadow: 0 10px 32px rgba(10, 62, 82, 0.18);
  }

  .preview-header {
    align-items: center;
    flex-direction: row;
    gap: 8px;
    padding: 9px 10px;
  }

  .preview-header > div:first-child {
    min-width: 0;
  }

  .preview-header .eyebrow {
    margin-bottom: 2px;
    font-size: 10px;
  }

  .preview-header h2 {
    font-size: 17px;
  }

  .preview-meta {
    flex: 0 0 auto;
  }

  .quality-note {
    display: none;
  }

  .mobile-preview-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

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

  .platform-grid {
    grid-template-columns: 1fr;
  }

  .fit-grid {
    grid-template-columns: 1fr;
  }

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

  .segmented-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .preview-frame {
    height: 180px;
    min-height: 180px;
    max-height: 34svh;
    overflow: hidden;
    padding: 8px;
  }

  body.mobile-preview-large .preview-frame {
    height: min(52svh, 420px);
    min-height: min(52svh, 420px);
    max-height: none;
    overflow: auto;
    padding: 12px;
  }

  canvas {
    max-height: 156px;
  }

  body.mobile-preview-large canvas {
    max-height: 48svh;
  }

  .empty-state {
    gap: 6px;
    padding: 10px;
  }

  .empty-state h2 {
    font-size: 18px;
  }

  .empty-state p {
    font-size: 13px;
    line-height: 1.35;
  }

  .empty-icon {
    width: 38px;
    height: 38px;
    font-size: 26px;
  }

  .mobile-save-dialog {
    padding: 14px;
  }

  .mobile-save-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) and (max-height: 520px) and (orientation: landscape) {
  .app-shell {
    gap: 10px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .app-header {
    align-items: center;
    flex-direction: row;
    gap: 12px;
    padding: 10px 12px;
  }

  .brand-lockup {
    align-items: center;
    flex-direction: row;
    gap: 10px;
  }

  .brand-logo {
    width: min(30vw, 160px);
    height: 42px;
  }

  .app-header h1 {
    font-size: 22px;
  }

  .header-status,
  .quality-note {
    display: none;
  }

  .workspace {
    gap: 10px;
  }

  .controls-panel {
    order: 2;
    padding: 14px;
  }

  .preview-panel {
    position: sticky;
    top: 0;
    order: 1;
    z-index: 8;
    min-height: 0;
    box-shadow: 0 10px 32px rgba(10, 62, 82, 0.18);
  }

  .preview-header {
    align-items: center;
    flex-direction: row;
    gap: 8px;
    padding: 8px 10px;
  }

  .preview-header > div:first-child {
    min-width: 0;
  }

  .preview-header .eyebrow {
    margin-bottom: 2px;
    font-size: 10px;
  }

  .preview-header h2 {
    font-size: 16px;
  }

  .preview-meta {
    flex: 0 0 auto;
  }

  .mobile-preview-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .preview-frame {
    height: clamp(132px, 34svh, 170px);
    min-height: clamp(132px, 34svh, 170px);
    max-height: 36svh;
    overflow: hidden;
    padding: 8px;
  }

  body.mobile-preview-large .preview-frame {
    height: min(62svh, 320px);
    min-height: min(62svh, 320px);
    max-height: none;
    overflow: auto;
    padding: 10px;
  }

  canvas {
    max-height: 30svh;
  }

  body.mobile-preview-large canvas {
    max-height: 58svh;
  }

  .empty-state {
    gap: 6px;
    padding: 10px;
  }

  .empty-state h2 {
    font-size: 17px;
  }

  .empty-state p {
    font-size: 13px;
    line-height: 1.35;
  }

  .empty-icon {
    width: 36px;
    height: 36px;
    font-size: 24px;
  }
}

@media (max-width: 360px) {
  .action-row,
  .segmented-row {
    grid-template-columns: 1fr;
  }
}
