:root {
  color-scheme: light;
  --ink: #17181a;
  --muted: #62666d;
  --faint: #8b9098;
  --paper: #f4f5f6;
  --panel: #ffffff;
  --panel-alt: #eceef1;
  --line: #d6d9dd;
  --stage: #17191c;
  --stage-raised: #22252a;
  --accent: #e53263;
  --accent-hover: #c72251;
  --accent-soft: #ffe4ec;
  --focus: #087ea4;
  --success: #1f7a4d;
  --danger: #b42318;
  --z-sticky: 40;
  --z-toast: 80;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans TC",
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button,
label[for="fileInput"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
label[for="fileInput"]:focus-within,
input:focus-visible,
.canvas-stage:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px 0 104px;
  background: var(--ink);
  color: #ffffff;
}

.app-identity {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 720;
  letter-spacing: -0.01em;
}

.app-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 70% 30%, #ffd44d 0 18%, transparent 19%),
    radial-gradient(circle at 32% 68%, #00a7c7 0 21%, transparent 22%),
    var(--accent);
}

.privacy-note {
  margin: 0;
  color: #d3d5d8;
  font-size: 13px;
}

.workspace {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(0, 1fr);
}

.control-rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.intro,
.source-panel,
.control-panel {
  padding: 24px;
}

.intro {
  padding-top: 30px;
  padding-bottom: 22px;
}

.intro h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 760;
  letter-spacing: -0.025em;
  line-height: 1.18;
  text-wrap: balance;
}

.intro p {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  text-wrap: pretty;
}

.source-panel,
.control-panel {
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.source-panel h2,
.control-panel h2,
.control-panel legend {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 720;
  line-height: 1.25;
}

.source-label {
  max-width: 50%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.source-actions input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.file-limit {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.35;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button-primary {
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button-secondary {
  background: #34373c;
  color: #ffffff;
}

.button-secondary:hover:not(:disabled) {
  background: #484c53;
}

.button:disabled {
  background: #b7bbc1;
  color: #f3f4f5;
  cursor: not-allowed;
}

.sample-list {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.sample-button {
  min-width: 0;
  flex: 1 1 0;
  display: grid;
  gap: 7px;
  justify-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 6px 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.sample-button:hover {
  background: var(--panel-alt);
  color: var(--ink);
}

.sample-button.is-active {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 700;
}

.sample-swatch {
  width: 100%;
  height: 36px;
  border-radius: 6px;
}

.sample-portrait {
  background:
    radial-gradient(circle at 50% 48%, #f2be91 0 19%, transparent 20%),
    linear-gradient(120deg, #1e2e73 0 49%, #f0cb2c 50% 100%);
}

.sample-geometry {
  background:
    radial-gradient(circle at 68% 38%, #f13c63 0 16%, transparent 17%),
    linear-gradient(135deg, #0da3ba 0 46%, #f4d64c 47% 72%, #25282c 73%);
}

.sample-city {
  background:
    linear-gradient(90deg, transparent 0 12%, #1d2329 13% 28%, transparent 29% 35%, #1d2329 36% 58%, transparent 59% 68%, #1d2329 69% 88%, transparent 89%),
    linear-gradient(#e54b71 0 48%, #e5d9bc 49%);
}

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

.pattern-button {
  min-width: 0;
  display: grid;
  gap: 7px;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 4px 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.pattern-button:hover {
  border-color: var(--faint);
  color: var(--ink);
}

.pattern-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #821638;
  font-weight: 720;
}

.pattern-preview {
  position: relative;
  width: 34px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background-color: #ffffff;
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
}

.preview-dots {
  background:
    radial-gradient(circle, var(--ink) 0 2px, transparent 2.4px) 1px 1px / 8px 8px,
    #ffffff;
}

.preview-lines::before,
.preview-lines::after {
  content: "";
  position: absolute;
  width: 38px;
  height: 3px;
  background: var(--ink);
  transform: rotate(-25deg);
}

.preview-lines::after {
  transform: translateY(9px) rotate(-25deg);
}

.preview-cmyk::before,
.preview-cmyk::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  mix-blend-mode: multiply;
}

.preview-cmyk::before {
  translate: -5px -2px;
  background: #00a8d6;
  box-shadow: 10px 0 #ed3d8f;
}

.preview-cmyk::after {
  translate: 0 6px;
  background: #f4d338;
  box-shadow: 4px -7px #202124;
}

.tuning-panel {
  display: grid;
  gap: 20px;
}

.text-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-hover);
  font-size: 12px;
  font-weight: 720;
  cursor: pointer;
}

.text-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.range-control {
  display: grid;
  gap: 7px;
}

.range-control.is-disabled {
  opacity: 0.45;
}

.range-label,
.range-ends {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.range-label label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.range-label output {
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.range-ends {
  color: var(--faint);
  font-size: 10px;
}

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

input[type="range"]:disabled {
  cursor: not-allowed;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.switch-row span {
  display: grid;
  gap: 2px;
}

.switch-row strong {
  font-size: 12px;
}

.switch-row small {
  color: var(--faint);
  font-size: 10px;
}

.switch-row input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.palette-panel {
  min-width: 0;
  margin: 0;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
}

.palette-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 14px;
}

.palette-button {
  min-width: 0;
  display: grid;
  gap: 6px;
  justify-items: center;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 7px 3px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}

.palette-button:hover {
  background: var(--panel-alt);
  color: var(--ink);
}

.palette-button.is-active {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 720;
}

.palette-pair {
  width: 31px;
  height: 20px;
  border-radius: 5px;
  box-shadow: inset -12px 0 var(--palette-paper);
  background: var(--palette-ink);
}

.palette-carbon {
  --palette-ink: #151515;
  --palette-paper: #f5f5f2;
}

.palette-cobalt {
  --palette-ink: #1737c8;
  --palette-paper: #eef2ff;
}

.palette-vermilion {
  --palette-ink: #d9381e;
  --palette-paper: #fff0e9;
}

.palette-pine {
  --palette-ink: #174a37;
  --palette-paper: #edf5ef;
}

.palette-panel:disabled .palette-list {
  opacity: 0.35;
}

.palette-panel:disabled .palette-button {
  cursor: not-allowed;
}

.palette-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.preview-region {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--stage);
  color: #ffffff;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid #34373c;
  background: var(--stage-raised);
}

.preview-toolbar h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 720;
}

.render-status {
  margin: 3px 0 0;
  color: #adb1b8;
  font-size: 12px;
}

.render-status.is-error {
  color: #ff9b91;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.canvas-stage {
  position: relative;
  min-height: 560px;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 46px;
  background: var(--stage);
}

.canvas-stage.is-dragging {
  box-shadow: inset 0 0 0 4px var(--accent);
}

.canvas-shell {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
  background: #ffffff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
}

.canvas-shell canvas {
  grid-area: 1 / 1;
  display: block;
  max-width: 100%;
  max-height: min(68vh, 760px);
  width: auto;
  height: auto;
}

#sourceCanvas {
  opacity: 1;
}

#effectCanvas {
  opacity: 1;
  transition: opacity 160ms ease;
}

.canvas-stage.is-comparing #effectCanvas {
  opacity: 0;
}

.processing-indicator {
  position: absolute;
  top: 18px;
  left: 50%;
  min-width: 180px;
  translate: -50% 0;
  display: grid;
  gap: 7px;
  padding: 10px 14px;
  border-radius: 9px;
  background: #2a2d32;
  color: #ffffff;
  font-size: 12px;
  text-align: center;
}

.processing-indicator[hidden] {
  display: none;
}

.processing-bar {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: #4b4f56;
}

.processing-bar::after {
  content: "";
  display: block;
  width: 45%;
  height: 100%;
  background: var(--accent);
  animation: processing 900ms ease-in-out infinite alternate;
}

@keyframes processing {
  from {
    translate: -15% 0;
  }

  to {
    translate: 140% 0;
  }
}

.drop-hint {
  position: absolute;
  right: 18px;
  bottom: 14px;
  margin: 0;
  color: #8d929a;
  font-size: 11px;
}

.output-bar {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 12px 24px;
  border-top: 1px solid #34373c;
  background: var(--stage-raised);
}

.output-bar > div:not(.local-badge) {
  display: grid;
  gap: 2px;
}

.output-bar span {
  color: #969ba3;
  font-size: 10px;
}

.output-bar strong {
  color: #ffffff;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.local-badge {
  margin-left: auto;
  border: 1px solid #46594e;
  border-radius: 999px;
  padding: 5px 10px;
  color: #9fe0ba;
  font-size: 11px;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  border-radius: 10px;
  padding: 12px 16px;
  background: #2b2e33;
  color: #ffffff;
  font-size: 13px;
}

.toast.is-error {
  background: var(--danger);
}

.toast[hidden] {
  display: none;
}

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

  .control-rail {
    border-right: 0;
  }

  .intro,
  .source-panel,
  .control-panel {
    padding-right: clamp(20px, 5vw, 48px);
    padding-left: clamp(20px, 5vw, 48px);
  }

  .source-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 0.8fr);
    column-gap: 28px;
  }

  .source-panel .section-heading {
    grid-column: 1 / -1;
  }

  .source-actions {
    align-self: center;
  }

  .sample-list {
    margin-top: 16px;
  }

  .pattern-grid,
  .palette-list {
    max-width: 520px;
  }

  .canvas-stage {
    min-height: 520px;
  }
}

@media (max-width: 640px) {
  .app-bar {
    min-height: 52px;
    padding: 0 16px 0 92px;
  }

  .privacy-note {
    max-width: 128px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .intro,
  .source-panel,
  .control-panel {
    padding: 20px;
  }

  .intro h1 {
    font-size: 1.45rem;
  }

  .source-panel {
    display: block;
  }

  .source-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .sample-list {
    margin-top: 18px;
  }

  .pattern-grid,
  .palette-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .canvas-stage {
    min-height: 430px;
    padding: 28px 14px 48px;
  }

  .canvas-shell canvas {
    max-height: 54vh;
  }

  .drop-hint {
    right: 14px;
    bottom: 12px;
    left: 14px;
    text-align: center;
  }

  .output-bar {
    flex-wrap: wrap;
    gap: 12px 24px;
    padding: 12px 16px;
  }

  .local-badge {
    width: 100%;
    margin-left: 0;
    text-align: center;
  }
}

@media (max-height: 620px) and (min-width: 760px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .control-rail {
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    border-right: 1px solid var(--line);
  }

  .intro,
  .source-panel,
  .control-panel {
    padding: 18px 20px;
  }

  .source-panel {
    display: block;
  }

  .canvas-stage {
    min-height: 400px;
    padding: 28px;
  }

  .canvas-shell canvas {
    max-height: calc(100vh - 190px);
  }
}

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