:root {
  --bg: #f4f1fb;
  --card: #ffffff;
  --line: #e2dcf0;
  --purple: #6b46c1;
  --purple-dark: #553c9a;
  --purple-soft: #ede7fb;
  --gold: #ffd166;
  --gold-dark: #d69e2e;
  --me: #6b46c1;
  --user: #dd6b20;
  --text: #1a202c;
  --muted: #5a6778;
  --good: #2f855a;
  --ebi: #c05621;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; touch-action: manipulation; }
input, textarea { font-size: 17px; } /* 16px+ stops iOS zooming on focus */

/* ---------- top bar ---------- */

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
#brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; white-space: nowrap; }
#steps { flex: 1; display: flex; gap: 6px; justify-content: center; overflow-x: auto; scrollbar-width: none; }
#steps::-webkit-scrollbar { display: none; }
.step-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.step-pill .n {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
}
.step-pill.done .n { background: var(--purple-soft); color: var(--purple); }
.step-pill.active { background: var(--purple-soft); color: var(--purple-dark); }
.step-pill.active .n { background: var(--purple); color: #fff; }
.step-pill:disabled { cursor: default; opacity: .55; }
#top-actions { display: flex; gap: 6px; }

.ghost {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- main ---------- */

#main {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 16px 32px;
  -webkit-overflow-scrolling: touch;
}
.page { max-width: 860px; margin: 0 auto; }
.page h1 { margin: 0 0 4px; font-size: 26px; }
.page .lead { margin: 0 0 18px; color: var(--muted); font-size: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; font-weight: 700; font-size: 15px; }
.field input, .field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 400;
}
.field input:focus, .field textarea:focus, .crit-row input:focus, .why:focus { outline: none; border-color: var(--purple); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.banner {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: #fffbea;
  border: 1px solid #f6e05e;
  font-weight: 600;
}

/* templates */
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tpl {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
}
.tpl .e { font-size: 26px; }
.tpl b { font-size: 15px; }
.tpl small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.tpl.active { border-color: var(--purple); background: var(--purple-soft); }

/* criteria editor */
.crit-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.crit-row .num {
  flex: 0 0 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--purple-soft);
  color: var(--purple);
  font-weight: 800;
  font-size: 14px;
}
.crit-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
}
.icon-del {
  flex: 0 0 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: #fff5f5;
  color: #c53030;
  font-size: 18px;
}
.add-btn {
  margin-top: 4px;
  padding: 10px 14px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: transparent;
  font-weight: 700;
  color: var(--purple);
}

/* rating */
.who-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.who-tab {
  padding: 10px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
}
.who-tab.active.me { border-color: var(--me); background: var(--purple-soft); }
.who-tab.active.user { border-color: var(--user); background: #fff3e6; }
.who-tab .count { font-weight: 600; color: var(--muted); font-size: 13px; margin-left: 4px; }

.rate-card .crit { font-size: 18px; font-weight: 700; margin-bottom: 10px; display: flex; gap: 10px; }
.faces { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.face .e { font-size: 30px; line-height: 1.1; filter: grayscale(.6); opacity: .7; transition: transform .12s; }
.face.on { border-color: var(--purple); background: var(--purple-soft); color: var(--purple-dark); }
.user-mode .face.on { border-color: var(--user); background: #fff3e6; color: #9c4221; }
.face.on .e { filter: none; opacity: 1; transform: scale(1.15); }
.why {
  width: 100%;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
}

.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.switch-row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--purple); }

/* wheel */
.wheel-wrap { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.wheel-card { padding: 8px; }
.wheel-card svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; justify-content: center; margin: 4px 0 6px; font-weight: 700; font-size: 14px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 6px; vertical-align: -2px; }
.www { border-left: 6px solid var(--good); }
.ebi { border-left: 6px solid var(--ebi); }
.diff { border-left: 6px solid var(--user); }
.www h2 { color: var(--good); }
.ebi h2 { color: var(--ebi); }
.diff h2 { color: #9c4221; }
.summary p { margin: 0 0 8px; line-height: 1.45; }
.summary .because { color: var(--muted); font-style: italic; }

/* next time */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}
.chip.idea { border-color: #fbd38d; background: #fffaf0; }
.chip:active { transform: scale(.97); }
.tip-group { margin-bottom: 12px; }
.tip-group .lbl { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
textarea.next { min-height: 120px; resize: vertical; line-height: 1.45; }

.finish { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- footer nav ---------- */

#nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
#nav-hint { flex: 1; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); }
.primary, .secondary {
  height: 52px;
  padding: 0 22px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}
.primary { border: 0; background: var(--purple); color: #fff; box-shadow: 0 3px 0 var(--purple-dark); }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--purple-dark); }
.primary:disabled { background: #b7a6dd; box-shadow: none; cursor: default; }
.secondary { border: 2px solid var(--line); background: #fff; }
.secondary[hidden], .primary[hidden] { display: none; }

/* ---------- modal & toast ---------- */

#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(26, 32, 44, .45);
  z-index: 50;
}
#modal[hidden] { display: none; }
#modal-card {
  width: min(100%, 540px);
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 22px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
#modal-card h2 { margin: 0 0 10px; }
#modal-body { line-height: 1.45; }
#modal-body .link-box {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  word-break: break-all;
  background: #faf9fd;
}
#modal-body ol { padding-left: 20px; }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
#modal-actions button { height: 46px; font-size: 16px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  max-width: min(90%, 480px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(26, 32, 44, .9);
  color: #fff;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 60;
}
#toast.show { opacity: 1; }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  #brand span { display: none; }
  .step-pill .t { display: none; }
  .step-pill { padding: 6px; }
  .step-pill.active .t { display: inline; }
  .step-pill.active { padding-right: 12px; }
}
@media (max-width: 680px) {
  .wheel-wrap { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .ghost .t { display: none; }
  .face .w { display: none; }
  .primary, .secondary { padding: 0 16px; }
}

/* ---------- print: one A4 sheet for the book ---------- */

#print-sheet { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  html, body { height: auto; background: #fff; display: block; }
  #topbar, #main, #nav, #modal, #toast { display: none !important; }
  #print-sheet { display: block; font-size: 11pt; color: #000; }
  .ps-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 8px; }
  .ps-head h1 { margin: 0; font-size: 18pt; }
  .ps-meta { font-size: 10pt; text-align: right; line-height: 1.5; }
  .ps-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
  .ps-grid svg { width: 100%; height: auto; }
  .ps-legend { text-align: center; font-size: 9pt; margin-top: -4px; }
  .ps-legend i { display: inline-block; width: 10px; height: 10px; margin: 0 4px 0 10px; border-radius: 2px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.ps-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .ps-table th, .ps-table td { border: 1px solid #999; padding: 4px 5px; text-align: left; vertical-align: top; }
  .ps-table th { background: #eee; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ps-table td.sc { text-align: center; white-space: nowrap; }
  .ps-box { border: 1.5px solid #000; border-radius: 6px; padding: 6px 9px; margin-top: 8px; break-inside: avoid; }
  .ps-box h3 { margin: 0 0 3px; font-size: 11pt; }
  .ps-box p { margin: 0 0 3px; }
  .ps-box.lines p.blank { border-bottom: 1px solid #999; height: 20px; }
}
