:root {
  /* Palette from ittokku.com */
  --bg: #FBF5EC;          /* cream */
  --surface: #ffffff;
  --text: #1B0E1F;        /* ink */
  --muted: #6E5A67;
  --border: rgba(27, 14, 31, 0.13);
  --accent: #E2563D;      /* terracotta */
  --accent-soft: #F7E4DC; /* blush */
  --accent-text: #FBF5EC;
  --plum: #5C2A3E;
  --error: #B23A26;
  --warning: #8A5100;      /* amber text */
  --warning-soft: #FFF1D1; /* amber background */
  --warning-border: #F0B44C;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(27, 14, 31, 0.08);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: Newsreader, Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.app {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.brand { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.brand span { color: var(--accent); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}

.screen-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 500; margin: 0 0 4px; line-height: 1.2; letter-spacing: -0.01em; }
.screen-sub { color: var(--muted); margin: 0 0 16px; font-size: 0.9rem; }

/* Gender */
.gender-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.gender-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}
.gender-card svg { width: 52px; height: 52px; fill: var(--plum); }
.gender-card:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-2px); }

/* Progress */
.progress { margin-bottom: 14px; }
.progress-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 5px; }
.progress-track { height: 4px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.35s ease; }

/* Step */
.step.animate { animation: fadeIn 0.3s ease; }
.step-sub { color: var(--muted); margin: 0 0 12px; font-size: 0.85rem; }
.field-label { display: block; font-weight: 600; font-size: 0.85rem; margin: 10px 0 5px; }

/* Two fields side by side */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { min-width: 0; }

/* Unit toggle */
.unit-toggle {
  display: inline-flex;
  background: var(--bg);
  border-radius: 99px;
  padding: 3px;
}
.unit-toggle button {
  border: none;
  background: none;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  color: var(--muted);
}
.unit-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

/* Number inputs */
.input-row { display: flex; gap: 6px; }
.input-wrap { position: relative; flex: 1; min-width: 0; }
.input-wrap input {
  width: 100%;
  padding: 7px 30px 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
}
.input-wrap input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px rgba(226, 86, 61, 0.14); }
.input-wrap input.invalid { border-color: var(--error); }
.input-wrap .suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.78rem;
  pointer-events: none;
}
.hint { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }
.hint:empty { display: none; }
.hint.error { color: var(--error); }

/* Option cards */
.option-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.option-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.option-card svg { width: 40px; height: 56px; fill: none; stroke: var(--plum); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.option-card .option-img {
  width: 100%;
  max-width: 90px;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  mix-blend-mode: multiply; /* blends the white photo background into the selected tint */
}
.option-card small { font-weight: 400; color: var(--muted); font-size: 0.72rem; }
.option-card:hover { border-color: var(--accent); }
.option-card[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.option-card[aria-checked="true"]::after {
  content: "";
  position: absolute;
  top: clamp(4px, 1.2vw, 8px);
  right: clamp(4px, 1.2vw, 8px);
  width: clamp(16px, 4vw, 22px);
  aspect-ratio: 1;
  border-radius: 50%;
  background-color: var(--accent);
  /* SVG tick stays centred and crisp at any size, independent of font metrics or inherited text-align */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FBF5EC' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 62%;
}

/* Chips (band / cup) */
.chip-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-width: 42px;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.85rem;
  transition: border-color 0.2s, background 0.2s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Nav */
.nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font-weight: 700;
  font-size: 0.8rem;
  transition: opacity 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn-primary { background: var(--accent); color: var(--accent-text); box-shadow: 0 10px 24px -10px rgba(226, 86, 61, 0.6); }
.btn-primary:disabled { box-shadow: none; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: none; border-color: var(--border); }
.btn-ghost:hover { border-color: var(--text); }
.btn-block { display: block; width: 100%; margin-top: 10px; }

/* Feedback, a tinted panel under the size cards so it reads as the next step */
.feedback-inline {
  margin-top: 18px;
  padding: 14px;
  background: var(--accent-soft);
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  transition: border-color 0.2s;
}
.feedback-inline .rec-heading { font-family: var(--font-display); font-size: 1rem; font-weight: 600; margin: 0 0 2px; }
.feedback-sub { color: var(--muted); font-size: 0.75rem; margin: 0 0 10px; }
.feedback-inline .btn-block { margin-top: 12px; }
.feedback-inline #fbError { font-size: 0.75rem; margin-top: 10px; }
/* Compact form text inside the panel */
.feedback-inline .field-label { font-size: 0.75rem; margin: 10px 0 4px; }
.feedback-inline .text-input { font-size: 0.8rem; padding: 6px 9px; }
.feedback-inline .text-input::placeholder { color: var(--muted); opacity: 0.8; }
/* Three equal answer buttons */
.verdict-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.verdict {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.78rem;
  transition: border-color 0.2s, background 0.2s;
}
.verdict:hover { border-color: var(--accent); }
.verdict[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
/* Emoji above each label */
.verdict-emoji { font-size: 1.6rem; line-height: 1; }
.feedback-details { margin-top: 4px; animation: reveal 0.25s ease; }
.details-lead { font-weight: 600; font-size: 0.78rem; margin: 12px 0 -4px; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
/* Leaving without feedback: outline the panel once */
.feedback-inline.nudge { border-color: var(--accent); animation: nudge 0.4s ease; }
.feedback-inline.nudge .feedback-sub {
  color: var(--warning);
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.75rem;
  font-weight: 600;
}
.feedback-inline.nudge .feedback-sub::before { content: "\26A0\FE0F  "; }
@keyframes nudge {
  0%, 100% { transform: none; }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.optional { font-weight: 400; color: var(--muted); }
.text-input {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
.text-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px rgba(226, 86, 61, 0.14); }

/* Result */
/* Entered values on one line; scrolls sideways if it doesn't fit */
.summary {
  margin: 6px 0 12px;
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.summary::-webkit-scrollbar { display: none; }
.summary .sep { color: var(--accent); font-weight: 700; margin: 0 6px; }
#screen-result > .screen-title { font-size: 1.15rem; }

.rec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.rec-card {
  background: var(--plum);
  color: var(--accent-text);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.rec-card .label { font-size: 0.78rem; opacity: 0.85; }
.rec-card .size { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; line-height: 1.1; margin: 2px 0 4px; }
.rec-card .note { font-size: 0.75rem; opacity: 0.9; margin: 0; }
.rec-card .alt { font-size: 0.78rem; opacity: 0.85; margin-top: 6px; }
/* Brand letter rides after the number, a step smaller ("40 / L") */
.rec-card .size .letter { font-size: 0.6em; opacity: 0.85; }
/* Measurements: label left, value right, set off from the size by a hairline */
.rec-card .measures { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.2); }
.rec-card .measure { display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem; line-height: 1.5; }
.rec-card .measure dt { opacity: 0.8; }
.rec-card .measure dd { margin: 0; font-weight: 600; }
/* Garment icon (shirt / trousers) at the top-right of the card */
.rec-card.has-icon { display: flex; align-items: flex-start; gap: 10px; }
.rec-card .rec-text { flex: 1; min-width: 0; }
.rec-card .rec-icon { width: 40px; height: 40px; flex-shrink: 0; opacity: 0.9; }
/* Headline size (women's letter size) spans the full row */
.rec-card.primary { grid-column: 1 / -1; }
.rec-card.primary .size { font-size: 2.4rem; }
/* The kurta is tall, so it gets more room on the full-width card */
.rec-card.primary .rec-icon { width: 64px; height: 64px; }

.chart-block { margin-bottom: 14px; }
.chart-block h3 { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; margin: 0 0 6px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; white-space: nowrap; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
tr.highlight td { background: var(--accent-soft); font-weight: 700; }
tr.highlight td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.chart-note { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }

@media (max-width: 420px) {
  /* rem-based text across every section scales down with the root size */
  html { font-size: 14px; }
  body { font-size: 13px; }
  .app { padding: 14px; }
  .screen-title { font-size: 1.35rem; }
  .option-grid { grid-template-columns: 1fr; }
  /* Less vertical padding gives the illustration more room at roughly the same card height */
  .option-card { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 4px 12px; text-align: left; }
  .option-card svg { width: 36px; height: 52px; }
  .option-card .option-img { width: 84px; max-width: none; height: 74px; aspect-ratio: auto; flex-shrink: 0; }
  /* Size cards stay side by side; compact so the result fits with less scrolling */
  .rec-grid { gap: 8px; margin-bottom: 12px; }
  .rec-card { padding: 10px; }
  .rec-card .label { font-size: 0.7rem; }
  .rec-card .size { font-size: 1.5rem; margin: 0 0 2px; }
  .rec-card.primary .size { font-size: 1.8rem; }
  .rec-card .alt,
  .rec-card .measure { font-size: 0.7rem; }
  .rec-card .measures { margin-top: 4px; padding-top: 4px; }
  /* Icon moves to the top-right corner so the text keeps the card's width */
  .rec-card.has-icon { position: relative; display: block; }
  .rec-card.has-icon .label { padding-right: 24px; }
  .rec-card .rec-icon { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; }
  .rec-card.primary .rec-icon { top: 6px; right: 10px; width: 48px; height: 48px; }
  .feedback-inline { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
