:root {
  --bg: #f5f5f2;
  --paper: rgba(255, 255, 255, 0.74);
  --ink: #111111;
  --muted: #6d6d72;
  --line: rgba(17, 17, 17, 0.08);
  --accent: #111111;
  --accent-strong: #000000;
  --shadow: 0 24px 80px rgba(18, 18, 24, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.92), transparent 24%),
    radial-gradient(circle at 85% 18%, rgba(214, 218, 232, 0.42), transparent 18%),
    linear-gradient(180deg, #fafaf8 0%, #f1f1ee 100%);
  font-family: "SF Pro Display", "PingFang SC", "Helvetica Neue", sans-serif;
}

.page-shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 40px;
}

.hero {
  display: block;
  padding: 36px 40px;
  border: 1px solid var(--line);
  border-radius: 34px;
  background: var(--paper);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  color: #8a8a90;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.28em;
}

.hero h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Noto Serif SC", Georgia, serif;
  font-size: clamp(38px, 5vw, 72px);
  line-height: 0.94;
  letter-spacing: -0.04em;
}

.hero-text {
  width: min(580px, 100%);
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(320px, 1fr) 280px;
  gap: 20px;
  margin-top: 22px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--paper);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.panel-header {
  padding: 24px 24px 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.panel-header p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.control-panel {
  padding-bottom: 24px;
}

.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 24px;
  min-height: 148px;
  border: 1px dashed rgba(17, 17, 17, 0.18);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.58);
  text-align: center;
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.upload-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.upload-subtitle {
  color: var(--muted);
  font-size: 14px;
}

.control-group {
  padding: 0 24px;
  margin-bottom: 18px;
}

.control-group label,
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.control-group strong {
  color: #18181b;
}

input[type="range"],
select {
  width: 100%;
}

input[type="range"] {
  accent-color: #1a1a1a;
}

select {
  appearance: none;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 24px;
  margin-bottom: 20px;
}

.toggle {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
}

.toggle input {
  margin: 0;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 24px;
}

.button {
  padding: 14px 16px;
  border: 1px solid transparent;
  border-radius: 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

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

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button.primary {
  background: linear-gradient(180deg, #1b1b1d, #111111);
  color: white;
  box-shadow: 0 12px 26px rgba(17, 17, 17, 0.16);
}

.button.secondary {
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  border-color: var(--line);
}

.hint-box {
  margin: 20px 24px 0;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(17, 17, 17, 0.04);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.preview-panel {
  padding-bottom: 24px;
}

.canvas-wrap {
  padding: 24px;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 24px;
  image-rendering: auto;
  background:
    linear-gradient(45deg, rgba(17, 17, 17, 0.03) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(17, 17, 17, 0.03) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(17, 17, 17, 0.03) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(17, 17, 17, 0.03) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0px;
}

.stats-panel {
  padding-bottom: 12px;
}

.stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 24px;
}

.stats-summary > div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stats-summary strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.palette-list {
  padding: 0 24px 24px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.palette-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(50, 37, 27, 0.08);
}

.palette-item:last-child {
  border-bottom: 0;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.palette-code {
  display: block;
  font-weight: 700;
}

.palette-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.palette-count {
  font-size: 14px;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 17, 17, 0.36);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  width: min(480px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 32px 90px rgba(17, 17, 17, 0.18);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.06);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-eyebrow {
  margin: 0 0 10px;
  color: #8a8a90;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.modal-card h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Noto Serif SC", Georgia, serif;
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.modal-copy {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.modal-card-image {
  display: block;
  width: 100%;
  margin-top: 18px;
  border: 1px solid rgba(50, 37, 27, 0.08);
  border-radius: 22px;
  box-shadow: 0 16px 34px rgba(41, 24, 17, 0.08);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}

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

  .stats-panel {
    order: 3;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding-top: 10px;
  }

  .hero,
  .panel {
    border-radius: 22px;
  }

  .hero {
    padding: 20px;
  }

  .panel-header,
  .canvas-wrap,
  .stats-summary,
  .palette-list,
  .control-group,
  .button-row,
  .toggle-row {
    padding-left: 18px;
    padding-right: 18px;
  }

  .upload-box {
    margin: 18px;
  }

  .toggle-row,
  .button-row,
  .stats-summary,
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
