:root {
  color-scheme: light;
  --background: #ffffff;
  --workspace: #f7f8fa;
  --surface: #ffffff;
  --text: #15171a;
  --muted: #68707d;
  --border: #dce0e6;
  --border-strong: #c8ced8;
  --accent: #0d52d6;
  --accent-hover: #0a43b5;
  --success: #149653;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 16px 40px rgba(24, 31, 45, 0.08);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--workspace);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  height: 76px;
  padding: 0 clamp(22px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--text);
  text-decoration: none;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--accent);
}

.runtime-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa1ac;
}

.runtime-status.is-ready .status-dot {
  background: var(--success);
}

.runtime-status.is-error .status-dot {
  background: var(--danger);
}

.workspace {
  width: min(1440px, 100%);
  min-height: calc(100vh - 76px);
  margin: 0 auto;
  padding: clamp(24px, 3.4vw, 54px);
  display: grid;
  grid-template-columns: minmax(560px, 1.05fr) minmax(420px, 0.95fr);
  gap: clamp(28px, 3vw, 48px);
  align-items: start;
}

.control-panel {
  padding: 26px 0 0;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 2.4vw, 38px);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.panel-heading p,
.result-heading p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.upload-rail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.upload-field input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  margin-bottom: 8px;
}

.upload-label label {
  font-size: 14px;
  font-weight: 700;
}

.upload-label label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.source-toggle {
  width: 100%;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 8px;
  background: #edf0f4;
}

.source-toggle button {
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.source-toggle button.is-active {
  background: white;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(20, 28, 42, 0.11);
}

.upload-check {
  display: none;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--success);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.upload-field.has-file .upload-check {
  display: inline-flex;
}

.dropzone {
  position: relative;
  width: 100%;
  aspect-ratio: 0.76;
  padding: 0;
  overflow: hidden;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--accent);
  background: #f7faff;
  transform: translateY(-1px);
}

.dropzone:focus-visible,
.generate-button:focus-visible,
.change-image:focus-visible,
.preset-selector input:focus-visible + span,
.download-button:focus-visible {
  outline: 3px solid rgba(13, 82, 214, 0.22);
  outline-offset: 2px;
}

.dropzone-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.dropzone-empty svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone-empty strong {
  color: var(--text);
  font-size: 13px;
}

.dropzone-empty small {
  color: var(--muted);
  font-size: 11px;
}

.preview {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: white;
}

.upload-field.has-file .preview {
  display: block;
}

.upload-field.has-file .dropzone-empty {
  display: none;
}

.change-image {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  visibility: hidden;
}

.upload-field.has-file .change-image {
  visibility: visible;
}

.change-image:hover {
  color: var(--accent);
}

.url-source {
  position: relative;
  min-height: 200px;
  aspect-ratio: 0.76;
  padding: 16px;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: white;
}

.url-entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.url-source:not([hidden]) {
  display: flex;
}

.url-source input {
  width: 100%;
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
}

.url-source input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(13, 82, 214, 0.14);
}

.preview-url-button {
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #f8f9fb;
  color: var(--text);
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.preview-url-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #f4f7ff;
  color: var(--accent);
}

.preview-url-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.preview-url-button:focus-visible {
  outline: 3px solid rgba(13, 82, 214, 0.18);
  outline-offset: 2px;
}

.url-preview-frame {
  position: relative;
  flex: 1;
  min-height: 98px;
  overflow: hidden;
  border-radius: 8px;
  background: #f4f5f7;
}

.url-preview-frame:not([hidden]) {
  display: flex;
}

.url-source.has-preview {
  padding: 0;
}

.url-source.has-preview .url-entry,
.url-source.has-preview .url-preview-status {
  display: none;
}

.url-source.has-preview .url-preview-frame {
  min-height: 100%;
  border-radius: 11px;
}

.url-preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.remove-url-preview {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 32px;
  height: 32px;
  padding: 0 0 2px;
  border: 1px solid rgba(21, 23, 26, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow: 0 3px 12px rgba(24, 31, 45, 0.14);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.remove-url-preview:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.remove-url-preview:focus-visible {
  outline: 3px solid rgba(13, 82, 214, 0.22);
  outline-offset: 2px;
}

.url-source small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.url-source small.is-error {
  color: var(--danger);
}

.upload-field.is-url .dropzone,
.upload-field.is-url .change-image {
  display: none;
}

.upload-field.is-url.has-file .upload-check {
  display: inline-flex;
}

.preset-fieldset {
  margin: 30px 0 0;
  padding: 26px 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.preset-fieldset legend {
  padding: 0;
  font-size: 14px;
  font-weight: 750;
}

.preset-fieldset legend span {
  color: var(--muted);
  font-weight: 450;
}

.preset-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.preset-selector label {
  cursor: pointer;
}

.preset-selector input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.preset-selector span {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: white;
  color: #4d5562;
  font-size: 14px;
  font-weight: 700;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.preset-selector small {
  font-size: 11px;
  font-weight: 550;
}

.preset-selector input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  box-shadow: 0 0 0 2px rgba(13, 82, 214, 0.14);
}

.generate-button {
  width: 100%;
  min-height: 56px;
  margin-top: 20px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 760;
  cursor: pointer;
  transition:
    background 150ms ease,
    transform 150ms ease;
}

.generate-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.generate-button:disabled {
  background: #8da7d8;
  cursor: progress;
  transform: none;
}

.generate-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.progress-panel {
  margin-top: 14px;
  padding: 16px 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  border: 1px solid #bfd0f3;
  border-radius: 10px;
  background: #f8faff;
}

.spinner {
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  margin-top: 1px;
  border: 3px solid #cfdbf3;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.progress-copy {
  flex: 1;
  display: grid;
  gap: 3px;
}

.progress-copy strong {
  font-size: 14px;
}

.progress-copy > span {
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 3px;
  background: #dfe5ef;
}

.progress-track span {
  display: block;
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 900ms ease;
}

.form-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 650;
}

.result-panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.result-heading {
  min-height: 50px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.result-heading h2 {
  font-size: 17px;
  letter-spacing: -0.02em;
}

.download-button {
  padding: 9px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.download-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.result-canvas {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 9 / 16;
  margin: 16px auto 0;
  overflow: hidden;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: #fbfcfd;
}

.empty-state,
.result-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 34px;
}

.empty-state svg {
  width: 68px;
  height: 88px;
  margin-bottom: 24px;
  fill: none;
  stroke: #959eab;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state strong,
.result-loading strong {
  font-size: 15px;
}

.empty-state span,
.result-loading small {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

#resultImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: white;
}

.result-pulse {
  width: 78%;
  aspect-ratio: 9 / 13;
  margin-bottom: 24px;
  border-radius: 8px;
  background: #edf1f7;
  animation: pulse 1.35s ease-in-out infinite;
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.42;
  }
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 1fr;
    max-width: 780px;
  }

  .result-panel {
    order: 2;
  }
}

@media (max-width: 640px) {
  .app-header {
    height: 66px;
    padding: 0 18px;
  }

  .brand {
    font-size: 18px;
  }

  .runtime-status span:last-child {
    display: none;
  }

  .workspace {
    min-height: calc(100vh - 66px);
    padding: 22px 16px 36px;
  }

  .control-panel {
    padding-top: 8px;
  }

  .upload-rail {
    grid-template-columns: 1fr;
  }

  .dropzone {
    aspect-ratio: 16 / 10;
  }

  .url-source {
    min-height: 140px;
    aspect-ratio: 16 / 7;
  }

  .preset-selector span {
    min-height: 64px;
    flex-direction: column;
    gap: 1px;
  }

  .result-panel {
    padding: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
