:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #fbfcff;
  --text: #111827;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-soft: #eef2ff;
  --success-bg: #ecfdf3;
  --success-text: #067647;
  --warning-bg: #fffaeb;
  --warning-text: #b54708;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
  --shadow-soft: 0 12px 30px rgba(17, 24, 39, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, 0.10), transparent 34rem),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 34rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.84);
  border-bottom: 1px solid rgba(228, 231, 236, 0.88);
  backdrop-filter: blur(16px);
}

.header-inner {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.24);
}

.brand-text {
  font-size: 1rem;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-text span {
  color: var(--muted);
  font-weight: 700;
}

.header-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.header-link,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease, background 160ms ease;
}

.header-link:hover,
.secondary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(79, 70, 229, 0.38);
  color: var(--primary);
  background: #ffffff;
}

.header-link[aria-current="page"] {
  border-color: rgba(79, 70, 229, 0.18);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.main-content {
  min-height: calc(100vh - 158px);
}

.hero-section {
  position: relative;
  z-index: 1;
  padding: 64px 0 44px;
  overflow: hidden;
  isolation: isolate;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(320px, 0.72fr);
  align-items: center;
  gap: 52px;
  min-height: 340px;
}

.hero-copy {
  max-width: 690px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(2.5rem, 5.4vw, 5rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.lead {
  max-width: 650px;
  margin: 22px 0 0;
  color: #344054;
  font-size: clamp(1.15rem, 2vw, 1.42rem);
  line-height: 1.5;
  font-weight: 650;
}

.supporting-text {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.hero-preview {
  display: flex;
  justify-content: center;
  align-self: center;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.device-preview {
  width: min(100%, 380px);
  max-width: 380px;
  padding: 16px;
  border: 1px solid rgba(208, 213, 221, 0.88);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.device-top {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px;
}

.device-top span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #d0d5dd;
}

.device-top span:first-child {
  background: #f97316;
}

.device-top span:nth-child(2) {
  background: #facc15;
}

.device-top span:nth-child(3) {
  background: #22c55e;
}

.device-frame {
  height: 300px;
  display: grid;
  grid-template-columns: 0.78fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(79, 70, 229, 0.08), transparent 42%),
    #ffffff;
  overflow: hidden;
}

.preview-post {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(79, 70, 229, 0.14);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(79, 70, 229, 0.18), transparent 52%),
    linear-gradient(150deg, #dbeafe, #ffffff 52%, #ecfdf3);
  box-shadow: var(--shadow-soft);
}

.preview-post.square {
  aspect-ratio: auto;
}

.preview-post.portrait {
  grid-row: 1 / 3;
  grid-column: 2;
  aspect-ratio: auto;
}

.preview-post.story {
  aspect-ratio: auto;
}

.tool-section {
  position: relative;
  z-index: 2;
  margin-top: 24px;
  padding: 28px 0 22px;
}

.mode-section {
  position: relative;
  z-index: 2;
  padding: 0 0 8px;
}

.mode-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
}

.mode-toggle {
  width: min(100%, 640px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
}

.mode-button {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  background: transparent;
  color: #475467;
  cursor: pointer;
  font-weight: 850;
}

.mode-button.is-active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.22);
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.control-panel {
  display: grid;
  gap: 18px;
  width: 100%;
  min-width: 0;
  padding: 22px;
}

.mode-fields {
  display: grid;
  gap: 18px;
}

.is-hidden {
  display: none !important;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--text);
  font-weight: 820;
}

.upload-box {
  display: grid;
  gap: 8px;
  padding: 20px;
  border: 2px dashed #b8c0d8;
  border-radius: 18px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.upload-box:hover,
.upload-box.is-dragover {
  transform: translateY(-1px);
  border-color: var(--primary);
  background: #ffffff;
}

.upload-box:focus-within {
  border-color: var(--primary);
  outline: 3px solid rgba(79, 70, 229, 0.16);
}

.upload-box input[type="file"] {
  width: 100%;
  margin-top: 6px;
}

.upload-title {
  font-size: 1.08rem;
  font-weight: 820;
}

.upload-help,
.file-summary,
.range-meta,
.canvas-help {
  color: var(--muted);
  font-size: 0.94rem;
}

.file-summary {
  min-height: 24px;
  padding-top: 4px;
  color: #475467;
  font-weight: 720;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
}

.segment {
  min-height: 38px;
  border-radius: 999px;
  background: transparent;
  color: #475467;
  cursor: pointer;
  font-weight: 820;
}

.segment.is-active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.22);
}

select {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #ffffff;
  color: var(--text);
}

select:focus,
input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(79, 70, 229, 0.16);
}

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

.range-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.range-meta strong {
  color: var(--primary);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(79, 70, 229, 0.22);
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--primary-dark);
  box-shadow: 0 16px 32px rgba(79, 70, 229, 0.28);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
  box-shadow: none;
}

.full-width {
  width: 100%;
}

.preview-panel {
  width: 100%;
  min-width: 0;
  padding: 22px;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.preview-head h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  line-height: 1.2;
}

.ratio-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 900;
  white-space: nowrap;
}

.canvas-stage {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: calc(var(--display-height, 560px) + 36px);
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, #eef2ff 25%, transparent 25%),
    linear-gradient(-45deg, #eef2ff 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2ff 75%),
    linear-gradient(-45deg, transparent 75%, #eef2ff 75%);
  background-color: #ffffff;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  overflow: hidden;
}

.canvas-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, var(--display-width, 560px));
  height: var(--display-height, 560px);
  max-width: 100%;
  margin: 0 auto;
  min-width: 0;
}

.mosaic-frame canvas,
.carousel-frame canvas {
  cursor: grab;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 20px 46px rgba(17, 24, 39, 0.16);
  cursor: grab;
  touch-action: none;
}

canvas.is-dragging {
  cursor: grabbing;
}

.crop-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.94);
  border-radius: 14px;
  box-shadow:
    0 0 0 1px rgba(79, 70, 229, 0.62),
    inset 0 0 0 1px rgba(79, 70, 229, 0.36);
  pointer-events: none;
}

.grid-outline,
.mosaic-outline {
  border-color: rgba(79, 70, 229, 0.72);
}

.empty-state {
  position: absolute;
  inset: 18px;
  display: grid;
  place-content: center;
  gap: 8px;
  border: 1px dashed rgba(79, 70, 229, 0.38);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.empty-state strong {
  color: var(--text);
  font-size: 1.16rem;
}

.empty-state.is-hidden {
  display: none;
}

.canvas-help {
  margin: 14px 0 0;
}

.info-section {
  padding: 10px 0 72px;
}

.output-section {
  padding: 10px 0 72px;
}

.notice-section {
  padding: 0 0 72px;
}

.usage-notice-card {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 28px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f8faff 100%);
  box-shadow: var(--shadow-soft);
}

.usage-notice-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  line-height: 1.2;
}

.usage-notice-content {
  display: grid;
  gap: 10px;
}

.usage-notice-content p {
  margin: 0;
  color: #475467;
}

.output-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.order-panel,
.result-panel {
  min-width: 0;
  padding: 22px;
}

.order-panel h2,
.result-panel h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.45rem, 2.2vw, 2rem);
  line-height: 1.2;
}

.order-panel p {
  margin: 12px 0 0;
  color: #475467;
}

.order-list {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding-left: 22px;
  color: #344054;
  font-weight: 720;
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.result-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-button {
  min-height: 36px;
  padding: 7px 13px;
  font-size: 0.92rem;
}

.slice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.slice-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.slice-card canvas {
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  border-radius: 12px;
  box-shadow: none;
  cursor: default;
}

.slice-card strong {
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.35;
}

.slice-card span,
.slice-empty {
  color: var(--muted);
  font-size: 0.92rem;
}

.slice-actions {
  display: grid;
  gap: 8px;
}

.upload-status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.upload-status a {
  color: var(--primary);
  font-weight: 750;
  text-decoration: none;
}

.upload-status.is-error {
  color: #b42318;
}

.upload-status.is-success {
  color: #047857;
}

.slice-empty {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px dashed rgba(79, 70, 229, 0.3);
  border-radius: 16px;
  background: #fbfcff;
  text-align: center;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.info-card {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.info-card span {
  color: var(--muted);
  font-size: 0.92rem;
}

.info-card strong {
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.35;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.footer-inner {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 0.94rem;
}

.footer-brand {
  display: grid;
  gap: 4px;
}

.footer-brand strong {
  color: var(--text);
  font-size: 0.96rem;
}

.footer-brand span {
  color: var(--muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 16px;
  font-weight: 800;
}

.footer-links a {
  color: var(--muted);
}

.footer-links a:hover {
  color: var(--primary);
}

@media (max-width: 900px) {
  .tool-layout,
  .output-layout {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .control-panel,
  .preview-panel,
  .panel {
    width: 100%;
    max-width: 100%;
  }

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

@media (max-width: 980px) {
  .hero-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .hero-preview {
    justify-content: flex-start;
  }

  .canvas-stage {
    min-height: calc(var(--display-height, 500px) + 36px);
  }

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

@media (max-width: 768px) {
  .hero-preview {
    display: none;
  }

  .hero-section {
    padding-bottom: 18px;
  }

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

@media (max-width: 680px) {
  .container {
    width: min(100% - 24px, 1120px);
  }

  .header-inner {
    min-height: 66px;
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0;
  }

  .brand-text {
    font-size: 0.94rem;
    white-space: normal;
  }

  .header-nav {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  .header-link {
    min-height: 38px;
    padding: 8px 11px;
    font-size: 0.9rem;
  }

  .hero-section {
    padding: 42px 0 24px;
  }

  .hero-copy h1 {
    font-size: clamp(2.15rem, 12vw, 3.2rem);
  }

  .device-preview {
    width: 100%;
    border-radius: 22px;
  }

  .device-frame {
    height: 240px;
    padding: 14px;
    border-radius: 18px;
  }

  .control-panel,
  .preview-panel,
  .order-panel,
  .result-panel {
    padding: 16px;
    border-radius: 20px;
  }

  .mode-card {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-toggle {
    width: 100%;
    border-radius: 18px;
    grid-template-columns: 1fr;
  }

  .mode-button {
    border-radius: 14px;
    font-size: 0.92rem;
  }

  .segmented-control {
    border-radius: 18px;
  }

  .segment {
    border-radius: 14px;
  }

  .button-row,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .slice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .slice-card {
    gap: 7px;
    padding: 10px;
    border-radius: 16px;
  }

  .slice-card canvas {
    border-radius: 10px;
  }

  .slice-card strong {
    font-size: 0.9rem;
  }

  .slice-card span {
    font-size: 0.82rem;
  }

  .slice-card .secondary-button {
    min-height: 38px;
    padding: 6px 8px;
    font-size: 0.9rem;
  }

  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  .result-actions {
    justify-content: space-between;
  }

  .compact-button {
    width: auto;
    flex: 1 1 150px;
  }

  .usage-notice-card {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 20px;
  }

  .secondary-button,
  .primary-button {
    width: 100%;
  }

  .result-actions .compact-button {
    width: auto;
  }

  .preview-head {
    align-items: stretch;
    flex-direction: column;
  }

  .ratio-badge {
    width: fit-content;
  }

  .canvas-stage {
    min-height: calc(var(--display-height, 380px) + 20px);
    padding: 10px;
    border-radius: 18px;
  }

  canvas,
  .crop-outline {
    border-radius: 10px;
  }

  .footer-inner {
    min-height: 96px;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    padding: 18px 0;
  }

  .footer-links {
    justify-content: flex-start;
  }
}
