:root {
  --bg: #f5f2ec;
  --text: #171717;
  --muted: #68645d;
  --card: #ffffff;
  --border: #ded8ce;
  --accent: #111111;
  --accent-hover: #333333;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff7de 0, transparent 32%), var(--bg);
  color: var(--text);
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0;
}

.hero {
  max-width: 760px;
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 76px);
  line-height: 0.92;
  letter-spacing: -0.06em;
}

h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.intro {
  margin: 24px 0 0;
  font-size: 20px;
  line-height: 1.45;
  color: #2c2b28;
}

.notice {
  display: inline-block;
  margin: 20px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.card {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.upload-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: stretch;
  margin-bottom: 24px;
  transition: 180ms ease;
}

.upload-card.is-compact {
  grid-template-columns: 180px 1fr;
  align-items: center;
  padding: 16px;
}

.upload-area {
  min-height: 190px;
  border: 2px dashed #c8beb0;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: 180ms ease;
  text-align: center;
  padding: 24px;
}

.upload-card.is-compact .upload-area {
  min-height: 94px;
  padding: 14px;
  gap: 4px;
}

.upload-card.is-compact .upload-icon {
  width: 34px;
  height: 34px;
  font-size: 22px;
}

.upload-card.is-compact .upload-title {
  font-size: 14px;
}

.upload-card.is-compact .upload-hint {
  font-size: 11px;
}

.upload-area:hover {
  border-color: var(--accent);
  background: #faf7f1;
}

.upload-area input {
  display: none;
}

.upload-icon {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  font-size: 34px;
  line-height: 1;
}

.upload-title {
  font-size: 20px;
  font-weight: 750;
}

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

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
}

.settings-intro {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.settings-intro strong {
  color: var(--text);
  font-size: 15px;
}

.action-field {
  justify-content: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls label {
  font-weight: 700;
  font-size: 13px;
}

select,
input[type="number"] {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  background: white;
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  gap: 24px;
  align-items: start;
}

.image-card {
  position: sticky;
  top: 0;
  align-self: start;
  z-index: 2;
}

.result-card {
  max-height: calc(100vh - 24px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.result-card .section-header {
  flex: 0 0 auto;
}

.result-card .loading {
  flex: 0 0 auto;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-header.stacked {
  align-items: flex-start;
  flex-direction: column;
  gap: 6px;
}

.primary-button {
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
  transition: 180ms ease;
  width: 100%;
}

.primary-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

.image-stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--uploaded-aspect, 16 / 10);
  line-height: 0;
  margin: 0 auto;
  border-radius: 20px;
  background: #eee9df;
  overflow: hidden;
}

#imagePreview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 20px;
  background: #eee9df;
  display: block;
}

.highlight-canvas {
  position: absolute;
  pointer-events: none;
  border-radius: 20px;
  mix-blend-mode: multiply;
}

.color-hover-cursor {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid #111;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.color-magnifier {
  position: absolute;
  width: 108px;
  height: 108px;
  border-radius: 999px;
  border: 2px solid #111;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.24), 0 0 0 3px rgba(255, 255, 255, 0.86);
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 3;
}

.color-magnifier::before,
.color-magnifier::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(17, 17, 17, 0.72);
  transform: translate(-50%, -50%);
}

.color-magnifier::before {
  width: 22px;
  height: 1px;
}

.color-magnifier::after {
  width: 1px;
  height: 22px;
}

.palette {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
  scroll-behavior: smooth;
}

.color-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.color-row.is-active,
.color-row:hover {
  border-color: #111;
  box-shadow: 0 0 0 1px #111;
}

.swatch {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 7px;
}

.swatch-percentage {
  font-size: 12px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.22);
}

.row-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.main-result {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  min-width: 0;
}

.main-result strong {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.main-result span {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.dose-count {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.03em;
  text-align: right;
  white-space: nowrap;
  color: var(--text);
}

.sub-result,
.analysis-result {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 6px;
}

.sub-result span,
.analysis-result span {
  color: var(--muted);
  font-size: 12px;
}

.analysis-result {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.percentage {
  font-size: 20px;
  font-weight: 850;
}

.loading {
  padding: 14px;
  border-radius: 14px;
  background: #f4efe6;
  color: var(--muted);
  margin-bottom: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding: 32px 0;
  }

  .upload-card,
  .upload-card.is-compact,
  .grid {
    grid-template-columns: 1fr;
  }

  .image-card {
    position: static;
  }

  .result-card {
    max-height: none;
  }

  .palette {
    overflow-y: visible;
  }

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

  .settings-intro {
    flex-direction: column;
    gap: 4px;
  }

  .action-field {
    grid-column: 1 / -1;
  }

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