*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --cream: #faf6ef;
  --cream2: #f0e8d8;
  --white: #ffffff;
  --coral: #f25c54;
  --coral-lt: #fff0ef;
  --teal: #0faa7a;
  --teal-lt: #e0faf2;
  --amber: #e8960a;
  --amber-lt: #fff8e1;
  --violet: #7048e8;
  --violet-lt: #eeebff;
  --rose: #e03e7c;
  --rose-lt: #ffedf5;
  --ink: #1c1814;
  --ink2: #463f38;
  --ink3: #9a8f86;
  --ink4: #cec5bc;
  --shadow-sm: 0 1px 4px rgba(28, 24, 20, 0.07);
  --shadow-md: 0 4px 16px rgba(28, 24, 20, 0.10);
  --shadow-lg: 0 8px 36px rgba(28, 24, 20, 0.14);
  --r: 14px;
  --r-sm: 8px;
  --mono: 'JetBrains Mono', monospace;
  --disp: 'Playfair Display', serif;
  --sans: 'Cabinet Grotesk', sans-serif;
}

html,
body {
  min-height: 100%;
  background: var(--cream);
  font-family: var(--sans);
  color: var(--ink);
  overflow-x: hidden;
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.bg-dots {
  background-image:
    radial-gradient(circle, rgba(242, 92, 84, 0.18) 1.5px, transparent 1.5px),
    radial-gradient(circle, rgba(15, 170, 122, 0.15) 1.5px, transparent 1.5px),
    radial-gradient(circle, rgba(232, 150, 10, 0.14) 1.5px, transparent 1.5px),
    radial-gradient(circle, rgba(112, 72, 232, 0.13) 1.5px, transparent 1.5px);
  background-size: 52px 52px, 52px 52px, 52px 52px, 52px 52px;
  background-position: 0 0, 26px 26px, 13px 39px, 39px 13px;
}

.bg-grid {
  background-image:
    linear-gradient(rgba(242, 92, 84, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 170, 122, 0.05) 1px, transparent 1px);
  background-size: 104px 104px;
}

.bg-stripes {
  background-image: repeating-linear-gradient(-55deg,
      transparent 0px, transparent 28px,
      rgba(232, 150, 10, 0.04) 28px, rgba(232, 150, 10, 0.04) 29px);
}

.bg-blobs {
  overflow: hidden;
}

.bg-blobs::before,
.bg-blobs::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
}

.bg-blobs::before {
  width: 420px;
  height: 420px;
  top: -120px;
  left: -80px;
  background: radial-gradient(circle, rgba(242, 92, 84, 0.09), transparent 70%);
}

.bg-blobs::after {
  width: 380px;
  height: 380px;
  bottom: -100px;
  right: -60px;
  background: radial-gradient(circle, rgba(112, 72, 232, 0.10), transparent 70%);
}

header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(250, 246, 239, 0.88);
  backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 2px solid var(--cream2);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-family: var(--disp);
  font-size: 21px;
  font-weight: 900;
  letter-spacing: -0.4px;
  line-height: 1;
}

.logo .c {
  color: var(--coral);
}

.logo .t {
  color: var(--teal);
}

.logo-badge {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  background: var(--violet-lt);
  color: var(--violet);
  border: 1.5px solid rgba(112, 72, 232, 0.2);
  border-radius: 4px;
  padding: 2px 7px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.status-tag {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--white);
  border: 1.5px solid var(--cream2);
  border-radius: 20px;
  padding: 5px 13px;
  color: var(--ink2);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.hl {
  font-weight: 700;
}

.c1 {
  color: var(--coral);
}

.c2 {
  color: var(--teal);
}

.c3 {
  color: var(--amber);
}

.c4 {
  color: var(--violet);
}

.c5 {
  color: var(--rose);
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100svh - 57px);
}

@media (min-width: 800px) {
  .app {
    flex-direction: row;
    height: calc(100svh - 57px);
    overflow: clip;
  }
}

.sidebar {
  order: 2;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(14px);
  border-top: 2px solid var(--cream2);
}

@media (min-width: 800px) {
  .sidebar {
    order: 1;
    width: 282px;
    flex-shrink: 0;
    border-top: none;
    border-right: 2px solid var(--cream2);
    padding: 18px 16px 24px;
    height: calc(100svh - 57px);
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
}

.sidebar::-webkit-scrollbar {
  width: 3px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--ink4);
  border-radius: 3px;
}

.card {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  border: 1.5px solid var(--cream2);
  overflow: visible;
  animation: cardIn 0.4s ease both;
  isolation: isolate;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r);
  pointer-events: none;
}

.card:nth-child(1) {
  animation-delay: .04s
}

.card:nth-child(2) {
  animation-delay: .10s
}

.card:nth-child(3) {
  animation-delay: .16s
}

.card:nth-child(4) {
  animation-delay: .22s
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

.card-hd {
  padding: 9px 14px;
  border-bottom: 1.5px solid var(--cream2);
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--r) var(--r) 0 0;
  overflow: hidden;
}

.card-pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-lbl {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ink3);
}

.card-bd {
  padding: 12px;
  border-radius: 0 0 var(--r) var(--r);
}

.kb-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-inp {
  flex: 1;
  background: var(--cream);
  border: 1.5px solid var(--cream2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color 0.14s, background 0.14s;
  -moz-appearance: textfield;
}

.kb-inp::-webkit-inner-spin-button,
.kb-inp::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.kb-inp:focus {
  border-color: var(--teal);
  background: var(--teal-lt);
}

.kb-tag {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  background: var(--teal-lt);
  border: 1.5px solid rgba(15, 170, 122, 0.3);
  border-radius: var(--r-sm);
  padding: 9px 10px;
  line-height: 1;
  flex-shrink: 0;
}

.info-list {
  display: flex;
  flex-direction: column;
}

.irow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed var(--cream2);
}

.irow:last-child {
  border-bottom: none;
}

.ik {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.iv {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink);
}

.prog {
  display: none;
  flex-direction: column;
  gap: 6px;
}

.prog.on {
  display: flex;
}

.prog-track {
  height: 6px;
  background: var(--cream2);
  border-radius: 6px;
  overflow: hidden;
}

.prog-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--coral), var(--amber), var(--teal), var(--violet));
  background-size: 300% 100%;
  transition: width 0.3s ease;
  animation: sweep 2s linear infinite;
}

@keyframes sweep {
  0% {
    background-position: 0%
  }

  100% {
    background-position: 300%
  }
}

.prog-txt {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink3);
}

.btn-go {
  width: 100%;
  padding: 13px;
  border-radius: var(--r);
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 800;
  color: var(--white);
  letter-spacing: 0.2px;
  background: linear-gradient(130deg, var(--coral) 0%, var(--rose) 45%, var(--violet) 100%);
  background-size: 200% 200%;
  background-position: 0% 0%;
  box-shadow: 0 4px 18px rgba(242, 92, 84, 0.3);
  transition: all 0.22s;
}

.btn-go:hover {
  background-position: 100% 100%;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(224, 62, 124, 0.38);
}

.btn-go:active {
  transform: translateY(0);
}

.btn-go:disabled {
  opacity: .32;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-ghost {
  width: 100%;
  padding: 9px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11.5px;
  background: transparent;
  border: 1.5px solid var(--ink4);
  color: var(--ink3);
  transition: all 0.14s;
  margin-top: 6px;
}

.btn-ghost:hover {
  border-color: var(--ink2);
  color: var(--ink);
}

.canvas-area {
  order: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 52vw;
  position: relative;
  overflow: hidden;
}

@media (min-width:800px) {
  .canvas-area {
    order: 2;
    min-height: unset;
    height: calc(100svh - 57px);
    overflow: hidden;
  }
}

#upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: min(400px, 100%);
  aspect-ratio: 4/3;
  background: var(--white);
  border-radius: 22px;
  border: 2.5px dashed var(--ink4);
  box-shadow: var(--shadow-md);
  padding: 32px;
  transition: all 0.2s;
}

#upload-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse at 20% 20%, rgba(242, 92, 84, 0.12), transparent 60%), radial-gradient(ellipse at 80% 80%, rgba(112, 72, 232, 0.10), transparent 60%), radial-gradient(ellipse at 50% 50%, rgba(15, 170, 122, 0.08), transparent 60%);
  transition: opacity 0.2s;
}

#upload-zone:hover::before,
#upload-zone.drag-over::before {
  opacity: 1;
}

#upload-zone:hover {
  border-color: var(--coral);
  border-style: solid;
  box-shadow: var(--shadow-lg);
}

#upload-zone.drag-over {
  border-color: var(--violet);
  border-style: solid;
  transform: scale(1.015);
}

.u-icon {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background: linear-gradient(135deg, var(--coral-lt), var(--violet-lt));
  border: 2px solid rgba(242, 92, 84, 0.15);
  box-shadow: 0 3px 12px rgba(28, 24, 20, 0.09);
  position: relative;
  z-index: 1;
}

.u-title {
  font-family: var(--disp);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  position: relative;
  z-index: 1;
  text-align: center;
}

.u-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
  text-align: center;
  line-height: 1.85;
  position: relative;
  z-index: 1;
}

.fmt-row {
  display: flex;
  gap: 5px;
  position: relative;
  z-index: 1;
  flex-wrap: wrap;
  justify-content: center;
}

.fmt {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.4px;
}

.fmt-1 {
  background: var(--coral-lt);
  color: var(--coral);
  border: 1px solid rgba(242, 92, 84, 0.22);
}

.fmt-2 {
  background: var(--teal-lt);
  color: var(--teal);
  border: 1px solid rgba(15, 170, 122, 0.22);
}

.fmt-3 {
  background: var(--amber-lt);
  color: var(--amber);
  border: 1px solid rgba(232, 150, 10, 0.22);
}

.fmt-4 {
  background: var(--violet-lt);
  color: var(--violet);
  border: 1px solid rgba(112, 72, 232, 0.22);
}

#file-input {
  display: none;
}

.preview-wrap {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(740px, 100%);
  padding: 16px;
}

.preview-wrap.show {
  display: flex;
}

.crop-stage {
  position: relative;
  width: min(640px, 100%);
  max-width: 100%;
  max-height: calc(100svh - 190px);
  overflow: hidden;
  border-radius: 18px;
  border: 2px solid var(--white);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, rgba(250, 246, 239, 0.9), rgba(240, 232, 216, 0.95));
  touch-action: none;
  user-select: none;
}

.crop-stage img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100svh - 190px);
  object-fit: contain;
}

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(15, 24, 34, 0.54);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.crop-box::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 1.5px dashed rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  pointer-events: none;
}

.crop-box.circle-mode::before {
  border-radius: 50%;
}

.crop-label {
  position: absolute;
  top: -31px;
  left: 0;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--white);
  background: rgba(28, 24, 20, 0.72);
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.crop-circle-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(15, 24, 34, 0.54);
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.crop-box.circle-mode .crop-circle-overlay {
  display: block;
}

.crop-box.circle-mode {
  box-shadow: none;
  border-color: transparent;
  border-radius: 0;
}

.crop-box.circle-mode::before {
  display: none;
}

.crop-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--white);
  border: 2px solid var(--coral);
  z-index: 5;
  transition: transform 0.12s, box-shadow 0.12s;
}

.crop-handle:hover {
  transform: scale(1.25);
  box-shadow: 0 0 8px rgba(242, 92, 84, 0.4);
}

.ch-tl {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

.ch-tr {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}

.ch-bl {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.ch-br {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.ratio-btn {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: var(--r-sm);
  background: var(--cream);
  border: 1.5px solid var(--cream2);
  color: var(--ink2);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  letter-spacing: 0.3px;
}

.ratio-btn:hover {
  border-color: var(--coral);
  color: var(--coral);
  background: var(--coral-lt);
}

.ratio-btn.active {
  background: linear-gradient(135deg, var(--coral), var(--rose));
  color: var(--white);
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(242, 92, 84, 0.3);
}

.circle-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: var(--cream);
  border: 1.5px solid var(--cream2);
  color: var(--ink2);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  transition: all 0.18s;
}

.circle-toggle:hover {
  border-color: var(--violet);
  color: var(--violet);
  background: var(--violet-lt);
}

.circle-toggle.active {
  background: linear-gradient(135deg, var(--violet), #5a34c8);
  color: var(--white);
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(112, 72, 232, 0.3);
}

.circle-icon {
  font-size: 16px;
  line-height: 1;
}

.preview-actions {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.preview-actions .btn-go,
.preview-actions .btn-ghost {
  width: auto;
  min-width: 140px;
  margin-top: 0;
}

.preview-actions .btn-ghost {
  padding: 10px 12px;
}

#result-sec {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
  width: 100%;
}

#result-sec.show {
  display: flex;
}

#result-img {
  max-width: min(460px, 100%);
  max-height: 52vh;
  border-radius: 12px;
  border: 3px solid var(--white);
  outline: 2px solid var(--cream2);
  box-shadow: var(--shadow-lg);
}

.rchips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.rchip {
  background: var(--white);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 8px 15px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink2);
  border: 1.5px solid var(--cream2);
}

.rchip b {
  font-weight: 700;
}

.btn-dl,
.btn-again {
  width: auto;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--cream2);
  background: var(--white);
  color: var(--ink2);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.btn-dl:hover,
.btn-again:hover {
  border-color: var(--coral);
  color: var(--coral);
}

.rbtns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-dl {
  padding: 13px 36px;
  border-radius: var(--r);
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 800;
  color: var(--white);
  background: linear-gradient(130deg, var(--teal), #0ca374);
  box-shadow: 0 4px 18px rgba(15, 170, 122, 0.32);
  transition: all 0.2s;
}

.btn-dl:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(15, 170, 122, 0.42);
}

.btn-again {
  padding: 13px 22px;
  border-radius: var(--r);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--white);
  border: 1.5px solid var(--ink4);
  color: var(--ink2);
  transition: all 0.14s;
}

.btn-again:hover {
  border-color: var(--ink2);
  color: var(--ink);
}

/* Custom ratio controls */
.custom-ratio-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 10px 0;
  padding: 8px 10px;
  background: var(--cream);
  border: 1.5px solid var(--cream2);
  border-radius: var(--r-sm);
  transition: border-color 0.14s;
}

.custom-ratio-row:focus-within {
  border-color: var(--rose);
}

.custom-ratio-label {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.custom-ratio-inp {
  width: 48px;
  background: var(--white);
  border: 1.5px solid var(--cream2);
  border-radius: 6px;
  padding: 5px 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  transition: border-color 0.14s;
}

.custom-ratio-inp::-webkit-inner-spin-button,
.custom-ratio-inp::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.custom-ratio-inp:focus {
  border-color: var(--rose);
}

.custom-ratio-inp::placeholder {
  color: var(--ink4);
  font-weight: 500;
}

.custom-ratio-sep {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink4);
  flex-shrink: 0;
}

.custom-ratio-apply {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1.5px solid var(--cream2);
  background: var(--cream);
  color: var(--ink3);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.18s;
  margin-left: auto;
}

.custom-ratio-apply:hover {
  background: linear-gradient(135deg, var(--rose), var(--coral));
  color: var(--white);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(224, 62, 124, 0.3);
  transform: scale(1.1);
}

/* Global scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: var(--cream2);
}

::-webkit-scrollbar-thumb {
  background: var(--ink4);
  border-radius: 4px;
}