:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: #181818;
  --panel-2: #232323;
  --panel-3: #2c2c2c;
  --text: #f3f3f3;
  --muted: #adadad;
  --subtle: #7f7f7f;
  --line: #3a3a3a;
  --accent: #b8bec8;
  --accent-strong: #d6dae1;
  --warn: #c8c8c8;
  --danger: #e0e0e0;
  --shadow: 0 24px 80px rgba(20, 21, 24, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(190, 195, 204, 0.16), transparent 26rem),
    linear-gradient(135deg, #111111 0%, #181818 52%, #121212 100%);
}

button,
input,
select,
.file-button {
  font: inherit;
}

button,
.file-button {
  min-height: 2.5rem;
  border: 1px solid rgba(205, 210, 218, 0.28);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  color: var(--text);
  background: linear-gradient(180deg, rgba(196, 201, 210, 0.22), rgba(196, 201, 210, 0.08));
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: rgba(215, 219, 226, 0.74);
  background: linear-gradient(180deg, rgba(205, 210, 218, 0.32), rgba(205, 210, 218, 0.14));
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

input[type="url"],
select {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  background: #131313;
  outline: none;
}

input[type="url"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(205, 210, 218, 0.14);
}

select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 3rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.15rem;
  background: #131313;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1.25rem;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.brand-logo {
  width: clamp(3rem, 7vw, 4.75rem);
  height: clamp(3rem, 7vw, 4.75rem);
  border-radius: 8px;
  object-fit: contain;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0.85rem;
  font-size: 0.92rem;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.control-panel,
.canvas-stage {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(24, 24, 24, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-panel {
  display: grid;
  gap: 0.85rem;
  border-radius: 8px;
  padding: 1rem;
}

.control-panel section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.95rem;
}

.control-panel section:last-of-type {
  border-bottom: 0;
  padding-bottom: 0;
}

.advanced-panel {
  color: var(--muted);
}

.advanced-panel summary {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.advanced-content {
  padding-top: 0.95rem;
}

.field,
.slider-field {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.inline-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.image-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.image-actions input {
  display: none;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
  cursor: pointer;
}

.section-break {
  height: 1px;
  margin: 0.95rem 0;
  background: var(--line);
}

.hint {
  margin: 0;
  color: var(--subtle);
  font-size: 0.8rem;
  line-height: 1.4;
}

.slider-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.slider-field input {
  grid-column: 1 / -1;
}

output {
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.toggle-row,
.color-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.toggle-row input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.stats {
  display: grid;
  gap: 0.55rem;
  margin: 0;
}

.stats div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: rgba(255, 255, 255, 0.04);
}

.stats dt {
  color: var(--muted);
  font-size: 0.8rem;
}

.stats dd {
  margin: 0;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
}

.status {
  min-height: 2.5rem;
  margin: 0;
  border-radius: 8px;
  padding: 0.7rem;
  color: var(--muted);
  background: #141414;
  font-size: 0.82rem;
  line-height: 1.4;
}

.status.is-warning {
  color: var(--warn);
}

.status.is-error {
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 1rem;
  top: 1rem;
  z-index: 10;
  max-width: min(22rem, calc(100vw - 2rem));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.8rem 0.95rem;
  color: var(--text);
  background: rgba(20, 20, 20, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.5rem);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 0.5;
  transform: translateY(0);
}

.pattern-info {
  border-top: 1px solid var(--line);
  padding: 1rem;
  background: rgba(24, 24, 24, 0.62);
}

.pattern-info h2 {
  margin-bottom: 0.75rem;
}

.canvas-stage {
  min-height: calc(100vh - 8.5rem);
  border-radius: 8px;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 1rem;
  background: rgba(34, 34, 34, 0.76);
}

.canvas-toolbar h2 {
  margin-bottom: 0.25rem;
  font-size: 1rem;
}

.canvas-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.toolbar-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.toolbar-toggle input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-actions button[aria-pressed="true"] {
  border-color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.2);
}

#patternCanvas.is-cropping {
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

#patternCanvas.is-clearing {
  cursor: cell;
}

.canvas-wrap {
  min-height: calc(100vh - 14rem);
  overflow: auto;
  padding: 1rem;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    #111111;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

#patternCanvas,
#stitchPreviewCanvas {
  display: block;
  width: min(100%, 1100px);
  height: auto;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #ffffff;
}

#patternCanvas {
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 0.85rem;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1 1 6rem;
  }

  .workspace {
    display: grid;
  }

  .canvas-stage {
    min-height: 60vh;
  }

  .canvas-wrap {
    min-height: 52vh;
    padding: 0.7rem;
  }

  .canvas-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .inline-input {
    grid-template-columns: 1fr;
  }

  .image-actions {
    grid-template-columns: 1fr;
  }

  .slider-field {
    grid-template-columns: 1fr;
  }

  output {
    justify-self: start;
  }
}
