:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #667085;
  --line: #d8dee9;
  --surface: #ffffff;
  --soft: #f5f7fb;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #e85d75;
  --gold: #d89a1f;
  --shadow: 0 18px 60px rgba(31, 42, 68, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f9fbff 0%, #eef6f5 48%, #fff8f0 100%);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid rgba(216, 222, 233, 0.82);
  backdrop-filter: blur(16px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 5vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.15;
}

.eyebrow,
.section-label {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.segmented-control button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 750;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--soft);
  color: var(--ink);
}

.primary-button {
  background: var(--brand);
  color: white;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  background: #fff;
  border-color: var(--brand);
  color: var(--brand);
}

.ghost-button {
  background: transparent;
  color: var(--ink);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

main {
  padding: clamp(18px, 4vw, 48px);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 34px);
  align-items: start;
}

.tool-panel,
.pattern-stage {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel {
  position: sticky;
  top: 104px;
  display: grid;
  gap: 22px;
  padding: 22px;
}

.panel-head,
.stage-toolbar,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 188px;
  padding: 22px;
  text-align: center;
  background: var(--soft);
  border: 2px dashed #b8c4d6;
  border-radius: 8px;
}

.upload-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.upload-zone small,
.section-heading p,
.empty-state span,
.plaza-card p {
  color: var(--muted);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #dff4f1;
  color: var(--brand);
  font-size: 34px;
  font-weight: 500;
}

.control-block {
  display: grid;
  gap: 10px;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

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

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 4px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented-control button {
  background: transparent;
  color: var(--muted);
}

.segmented-control button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(31, 42, 68, 0.1);
}

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

.pattern-stage {
  min-width: 0;
  padding: clamp(16px, 3vw, 26px);
}

.stage-toolbar {
  margin-bottom: 18px;
}

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

.preview-tools output {
  display: grid;
  place-items: center;
  min-width: 58px;
  min-height: 42px;
  padding: 0 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.stats span,
.plaza-meta span {
  padding: 6px 10px;
  background: var(--soft);
  border-radius: 999px;
}

.canvas-shell {
  position: relative;
  width: 100%;
  min-height: min(70vh, 720px);
  overflow: hidden;
  background:
    linear-gradient(45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef1f6 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.canvas-viewport {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: min(70vh, 720px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.canvas-viewport.is-dragging {
  cursor: grabbing;
}

canvas {
  width: min(100%, 78vh);
  max-width: none;
  max-height: none;
  aspect-ratio: 1;
  display: block;
  flex: 0 0 auto;
  box-shadow: 0 12px 36px rgba(31, 42, 68, 0.12);
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 22px;
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
}

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

.palette-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-top: 16px;
}

.palette-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 10px 5px 6px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.palette-item strong {
  margin-right: 5px;
  color: var(--ink);
}

.swatch {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(29, 36, 51, 0.16);
}

.plaza-section {
  margin-top: clamp(28px, 6vw, 72px);
}

.section-heading {
  margin-bottom: 18px;
}

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

.plaza-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.plaza-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--soft);
  border-radius: 6px;
}

.plaza-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account-dialog {
  width: min(92vw, 420px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.account-dialog::backdrop {
  background: rgba(29, 36, 51, 0.38);
  backdrop-filter: blur(4px);
}

.account-form {
  position: relative;
  display: grid;
  gap: 16px;
  padding: 24px;
}

.account-form label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.account-form input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: var(--soft);
  color: var(--ink);
}

.pattern-stage:fullscreen,
.pattern-stage.is-faux-fullscreen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: 18px;
  overflow: hidden;
  background: var(--surface);
  border: 0;
  border-radius: 0;
}

.pattern-stage.is-faux-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100vw;
  height: 100vh;
}

.pattern-stage:fullscreen {
  width: 100vw;
  height: 100vh;
}

.pattern-stage:fullscreen .canvas-shell,
.pattern-stage:fullscreen .canvas-viewport,
.pattern-stage.is-faux-fullscreen .canvas-shell,
.pattern-stage.is-faux-fullscreen .canvas-viewport {
  min-height: 0;
  height: 100%;
}

.pattern-stage:fullscreen canvas,
.pattern-stage.is-faux-fullscreen canvas {
  width: min(86vw, 86vh);
}

.pattern-stage:fullscreen .palette-strip,
.pattern-stage.is-faux-fullscreen .palette-strip {
  max-height: 92px;
  overflow: auto;
}

@media (max-width: 920px) {
  .app-header,
  .panel-head,
  .stage-toolbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

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

  .tool-panel {
    position: static;
  }

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

@media (max-width: 560px) {
  main,
  .app-header {
    padding-inline: 14px;
  }

  .top-actions,
  .button-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .canvas-shell {
    min-height: auto;
    aspect-ratio: 1;
  }

  .canvas-viewport {
    min-height: auto;
    aspect-ratio: 1;
    padding: 10px;
  }

  canvas {
    width: 100%;
    max-height: none;
  }

  .pattern-stage:fullscreen,
  .pattern-stage.is-faux-fullscreen {
    padding: 12px;
  }

  .pattern-stage:fullscreen .canvas-shell,
  .pattern-stage:fullscreen .canvas-viewport,
  .pattern-stage.is-faux-fullscreen .canvas-shell,
  .pattern-stage.is-faux-fullscreen .canvas-viewport {
    aspect-ratio: auto;
  }
}
