:root {
  color-scheme: light;
  --ink: #333333;
  --muted: #666666;
  --bg: #f5f5f5;
  --panel: #ffffff;
  --accent: #333333;
  --accent-hover: #555555;
  --accent-light: #e8e8e8;
  --line: #d9d9d9;
  --mask: rgba(70, 130, 180, 0.50);
  --shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Header */
.hero {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-link {
  display: inline-flex;
}

.logo {
  height: 40px;
  width: auto;
}

.badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 2px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 3.5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.lede {
  margin: 0;
  max-width: 650px;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.6;
}

/* Panel */
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field input,
.field textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  transition: border-color 0.15s;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Carpet swatches */
.carpet-swatches {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 4px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.swatch:hover {
  border-color: var(--line);
  transform: translateY(-1px);
}

.swatch.active {
  border-color: var(--accent);
}

.swatch img {
  width: 52px;
  height: 52px;
  border-radius: 2px;
  object-fit: cover;
}

.swatch span {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  max-width: 60px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swatch-hint {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  min-height: 20px;
}

/* Mask area */
.mask-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mask-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mask-header p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.mask-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
}

.mask-tools label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--muted);
}

.mask-tools input[type="range"] {
  accent-color: var(--accent);
}

.mask-tools button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

.mask-tools button:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 280px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fafafa;
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

#baseCanvas,
#maskCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#maskCanvas {
  cursor: crosshair;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

/* Actions */
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#generateBtn {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}

#generateBtn:hover {
  background: var(--accent-hover);
}

#generateBtn:disabled {
  background: #b0b0b0;
  cursor: not-allowed;
}

.status {
  font-size: 13px;
  color: var(--muted);
}

/* Result */
.result {
  display: grid;
  gap: 12px;
}

.result p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.result-frame {
  min-height: 260px;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.result-frame img {
  width: 100%;
  height: auto;
  display: none;
}

/* Footer */
.page-footer {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 12px;
}

.page-footer p {
  margin: 0;
  font-size: 12px;
  color: #999;
}

@media (max-width: 720px) {
  .panel {
    padding: 20px;
  }

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

  .swatch img {
    width: 40px;
    height: 40px;
  }
}
