:root {
  color-scheme: light;
  --ink: #18211f;
  --muted: #5f6d67;
  --paper: #fbfaf6;
  --panel: #ffffff;
  --line: #d9ded8;
  --line-strong: #aab6ae;
  --teal: #16756f;
  --teal-dark: #0e5651;
  --coral: #d45d4c;
  --gold: #c4922f;
  --mint: #e7f3ef;
  --rose: #f8e5df;
  --shadow: 0 22px 60px rgba(24, 33, 31, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(22, 117, 111, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(212, 93, 76, 0.12), transparent 28%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1480px;
  margin: 0 auto 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3.4rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

.topbar-actions,
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
.icon-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 42px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 2px 0 rgba(24, 33, 31, 0.08);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(24, 33, 31, 0.12);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.button-primary {
  background: var(--teal);
  color: #fff;
}

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

.button-secondary {
  border-color: var(--line);
}

.full-width {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1480px;
  margin: 0 auto;
  align-items: start;
}

.control-panel,
.draft-area {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(217, 222, 216, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
  position: sticky;
  top: 18px;
}

.draft-area {
  min-width: 0;
  padding: 16px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 168px;
  padding: 18px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, rgba(22, 117, 111, 0.09), rgba(196, 146, 47, 0.09)),
    var(--panel);
  text-align: center;
  cursor: pointer;
}

.drop-zone.is-dragging {
  border-color: var(--teal);
  background: var(--mint);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--rose);
  color: var(--coral);
}

.upload-icon svg,
.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drop-title {
  font-weight: 850;
}

.drop-meta {
  max-width: 100%;
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: grid;
  gap: 16px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
}

.control-row label,
.switch,
.stats-panel span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.control-row output {
  min-width: 54px;
  text-align: right;
  font-weight: 850;
}

.control-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--teal);
}

.switch-row {
  justify-content: stretch;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.source-panel,
.stats-panel,
.palette-panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.panel-heading,
.draft-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading span,
.draft-toolbar span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

#sourceCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f1f4f1;
}

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

.stats-panel div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.stats-panel strong {
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.draft-toolbar {
  margin-bottom: 14px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  padding: 0;
  border-color: var(--line);
}

.canvas-frame {
  display: grid;
  align-items: start;
  justify-items: center;
  min-height: 54vh;
  max-height: 68vh;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(24, 33, 31, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 33, 31, 0.035) 1px, transparent 1px),
    #f7f8f5;
  background-size: 24px 24px;
}

#patternCanvas {
  display: block;
  max-width: none;
  border: 1px solid rgba(24, 33, 31, 0.18);
  background: #fff;
  box-shadow: 0 12px 34px rgba(24, 33, 31, 0.16);
  image-rendering: pixelated;
}

.canvas-frame.fit #patternCanvas {
  max-width: 100%;
  height: auto;
}

.palette-panel {
  margin-top: 16px;
}

.print-summary {
  display: none;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(174px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.palette-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.swatch {
  width: 34px;
  height: 32px;
  border: 1px solid rgba(24, 33, 31, 0.22);
  border-radius: 6px;
}

.palette-meta {
  min-width: 0;
}

.palette-meta strong,
.palette-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-meta strong {
  font-size: 0.88rem;
}

.palette-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

.symbol-pill {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--mint);
  color: var(--teal-dark);
  font-weight: 900;
}

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

  .control-panel {
    position: static;
  }

  .source-panel {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .button {
    padding: 0 10px;
  }

  .stats-panel {
    grid-template-columns: 1fr;
  }

  .canvas-frame {
    min-height: 42vh;
    padding: 10px;
  }
}

@media print {
  @page {
    margin: 0.45in;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  html,
  body {
    min-height: auto;
    background: #fff;
  }

  body {
    color: #111;
  }

  .app-shell {
    min-height: auto;
    padding: 0;
  }

  .topbar {
    align-items: flex-start;
    margin: 0 0 14px;
    max-width: none;
  }

  .topbar-actions,
  .control-panel {
    display: none;
  }

  .workspace {
    display: block;
    max-width: none;
    margin: 0;
  }

  .draft-area {
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }

  .draft-toolbar {
    margin-bottom: 10px;
  }

  .draft-toolbar .eyebrow {
    color: #333;
  }

  .print-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin: 0 0 12px;
    color: #333;
    font-size: 10pt;
  }

  .print-summary span {
    white-space: nowrap;
  }

  .canvas-frame {
    display: block;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
  }

  #patternCanvas {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 7.1in;
    margin: 0 auto;
    height: auto;
    border: 1px solid #444;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .palette-panel {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid #999;
    page-break-inside: avoid;
  }

  .palette-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .palette-item {
    min-height: 34px;
    grid-template-columns: 26px minmax(0, 1fr) 24px;
    gap: 7px;
    padding: 5px;
    border-color: #999;
    box-shadow: none;
  }

  .swatch {
    width: 26px;
    height: 24px;
  }

  .symbol-pill {
    width: 24px;
    height: 24px;
    color: #111;
    background: #eee;
  }
}
