/* Kink Jars — app styles. Mobile-first (390px), scales up. */

/* ---------- fonts (self-hosted, OFL) ---------- */
@font-face { font-family: 'Fraunces'; font-weight: 800; font-style: normal; font-display: swap; src: url('../fonts/fraunces-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/nunito-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/nunito-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 800; font-style: normal; font-display: swap; src: url('../fonts/nunito-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Caveat'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/caveat-latin-700-normal.woff2') format('woff2'); }

/* ---------- tokens ---------- */
:root {
  --paper: #fdf8f0;
  --paper-2: #f6eddf;
  --card: #fffdf8;
  --ink: #2b2220;
  --ink-soft: #6b5d55;
  --line: #e7dccb;
  --wood: #e2c290;

  /* the user's colour; app.js overwrites these on <html> */
  --accent: #e0457b;
  --accent-ink: #ffffff;   /* text colour that reads on --accent */
  --accent-soft: #f8d3df;  /* pale tint for backgrounds */
  --accent-dark: #8a2f50;  /* readable on paper */

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-hand: 'Caveat', 'Comic Sans MS', cursive;

  --radius: 18px;
  --radius-lg: 26px;
  --pill: 999px;
  --pop: 3px 3px 0 var(--ink);
  --pop-sm: 2px 2px 0 var(--ink);
  --border: 2.5px solid var(--ink);
  --tap: 48px;
  --gutter: 18px;
  --maxw: 34rem;
  --focus: 0 0 0 3px var(--paper), 0 0 0 6px var(--accent-dark);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 800; line-height: 1.05; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent-dark); text-underline-offset: 3px; text-decoration-thickness: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 12px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 2rem var(--gutter); text-align: center; }

/* ---------- layout ---------- */
.app { min-height: 100dvh; }
.app:focus { box-shadow: none; }
.screen {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: screen-in .35s var(--ease-out) both;
}
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.center { text-align: center; align-items: center; }
.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }
.hand { font-family: var(--font-hand); font-weight: 700; }
.eyebrow {
  font-family: var(--font-body); font-weight: 800; font-size: .78rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent-dark);
}
.card {
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--pop);
  padding: 18px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 10px 20px;
  border: var(--border);
  border-radius: var(--pill);
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--pop);
  transition: transform .12s var(--ease-out), box-shadow .12s var(--ease-out), background-color .15s;
  user-select: none;
  touch-action: manipulation;
  position: relative;
}
/* Hit area that stays put: the button lifts on hover and sinks on press, and this invisible layer
   (covering the border box) moves the opposite way, so the area under the pointer never shifts.
   Without it a pointer resting on an edge flickers in and out of :hover. Every rule that moves
   .btn has a mirror here with the same selector. */
.btn::after {
  content: ''; position: absolute; inset: -2.5px; border-radius: inherit;
  transition: transform .12s var(--ease-out);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:hover::after { transform: translate(1px, 1px); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:active::after { transform: translate(-2px, -2px); }
.btn:focus-visible { border-radius: var(--pill); box-shadow: var(--pop), var(--focus); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn[disabled]::after { transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-block { width: 100%; }
.btn-big { min-height: 58px; font-size: 1.12rem; padding: 12px 26px; }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: .9rem; box-shadow: var(--pop-sm); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn-ghost:hover { box-shadow: none; transform: none; background: var(--paper-2); }
.btn-ghost:hover::after { transform: none; }
.btn-icon { width: var(--tap); padding: 0; }
.link-btn {
  background: none; border: 0; padding: 6px 4px; cursor: pointer; font-weight: 800;
  color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px;
  min-height: 40px;
}

/* ---------- gate ---------- */
.gate { min-height: 100dvh; justify-content: center; text-align: center; align-items: center; gap: 18px; }
.gate-jars { display: flex; align-items: flex-end; justify-content: center; gap: 4px; margin-bottom: 4px; }
.gate-jars svg { width: 92px; height: auto; }
.gate-jars svg:nth-child(2) { width: 118px; }
.gate h1 { font-size: clamp(3rem, 15vw, 4.6rem); letter-spacing: -.02em; }
.gate h1 .amp { color: var(--accent); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.gate .pitch { font-size: 1.15rem; max-width: 22rem; }
.gate .fine { font-size: .9rem; color: var(--ink-soft); max-width: 22rem; }
.gate .btn { min-width: 240px; }
.gate-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; width: 100%; }

/* ---------- setup ---------- */
.setup h2 { font-size: 2rem; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > label, .field > .label { font-weight: 800; }
.input {
  min-height: var(--tap);
  border: var(--border);
  border-radius: 14px;
  background: var(--card);
  padding: 10px 14px;
  font-size: 1.05rem;
  width: 100%;
}
.input:focus-visible { box-shadow: var(--focus); border-radius: 14px; }
.input-hand { font-family: var(--font-hand); font-size: 1.7rem; font-weight: 700; padding-block: 4px; color: var(--accent-dark); }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatch {
  aspect-ratio: 1; width: 100%; border-radius: 50%; border: var(--border);
  background: var(--sw); cursor: pointer; padding: 0; position: relative;
  box-shadow: var(--pop-sm); transition: transform .15s var(--ease-out);
}
.swatch[aria-checked="true"] { transform: scale(1.08); box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--ink); }
.swatch[aria-checked="true"]::after {
  content: ''; position: absolute; inset: 30%; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink);
}
.swatch:focus-visible { border-radius: 50%; box-shadow: var(--focus); }
.color-extra { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.color-custom {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 14px 4px 6px;
  border: var(--border); border-radius: var(--pill); background: var(--card); font-weight: 800; font-size: .9rem;
  box-shadow: var(--pop-sm); cursor: pointer;
}
.color-custom input[type="color"] {
  width: 30px; height: 30px; border: 2px solid var(--ink); border-radius: 50%; padding: 0; background: none; cursor: pointer;
}
.color-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-custom input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color-custom input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
.color-custom:focus-within { box-shadow: var(--focus); }
.preview-jars {
  display: flex; justify-content: center; align-items: flex-end; gap: 6px;
  padding: 14px 10px 0; border-radius: var(--radius-lg); background: var(--paper-2);
  position: relative;
}
.preview-jars::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 6px; height: 10px; border: var(--border); border-radius: 6px; background: var(--wood); z-index: 0; }
.preview-jars svg { width: 30%; max-width: 120px; height: auto; position: relative; z-index: 1; margin-bottom: 4px; }
.toggle {
  display: flex; align-items: center; gap: 14px; cursor: pointer; padding: 14px;
  border: var(--border); border-radius: var(--radius); background: var(--card);
}
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .switch {
  flex: none; width: 52px; height: 30px; border-radius: var(--pill); border: var(--border); background: var(--paper-2);
  position: relative; transition: background-color .2s;
}
.toggle .switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--ink); transition: transform .2s var(--ease-out);
}
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(22px); }
.toggle input:focus-visible + .switch { box-shadow: var(--focus); }
.toggle-text { display: flex; flex-direction: column; }
.toggle-text strong { font-weight: 800; }
.toggle-text span { font-size: .88rem; color: var(--ink-soft); }

/* ---------- quiz ---------- */
.quiz {
  min-height: 100dvh;
  gap: 10px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  animation: none;
}
.quiz-top { display: flex; align-items: center; gap: 10px; }
.quiz-top .count { font-weight: 800; font-variant-numeric: tabular-nums; margin-left: auto; font-size: .95rem; }
.progress { height: 8px; border-radius: var(--pill); background: var(--paper-2); border: 2px solid var(--ink); overflow: hidden; }
.progress > span { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); transition: width .4s var(--ease-out); }
.quiz-card { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 0; text-align: center; }
.quiz-card .shelf-chip {
  display: inline-block; padding: 3px 12px; border: 2px solid var(--ink); border-radius: var(--pill);
  background: var(--accent-soft); font-weight: 800; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase;
}
.jar-stage { width: min(58vw, 30vh, 250px); position: relative; margin: 4px auto 0; }
.jar-stage svg { width: 100%; height: auto; }
.jar-stage::before {
  content: ''; position: absolute; left: -14%; right: -14%; bottom: 1.6%; height: 5.5%;
  background: var(--wood); border: var(--border); border-radius: 8px;
}
.jar-stage svg { position: relative; }
.quiz-label { font-size: clamp(1.7rem, 8vw, 2.4rem); max-width: 20ch; min-height: 2.1em; display: flex; align-items: center; justify-content: center; }
.answer-word { font-family: var(--font-hand); font-size: 1.6rem; line-height: 1; color: var(--accent-dark); min-height: 1em; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.fills { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.fill-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px;
  padding: 6px 2px 6px; min-height: 76px;
  border: var(--border); border-radius: 16px; background: var(--card);
  box-shadow: var(--pop-sm); cursor: pointer; font-weight: 800; font-size: 1rem;
  transition: transform .12s var(--ease-out), background-color .15s, box-shadow .12s;
  touch-action: manipulation;
}
.fill-btn svg { width: 34px; height: auto; }
.fill-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.fill-btn[aria-pressed="true"] { background: var(--accent-soft); transform: translateY(-3px); box-shadow: 2px 5px 0 var(--ink); }
.fill-btn:focus-visible { border-radius: 16px; box-shadow: var(--pop-sm), var(--focus); }
.fill-captions { display: flex; justify-content: space-between; font-size: .82rem; font-weight: 800; color: var(--ink-soft); margin-top: -4px; padding: 0 4px; }
.alt-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.alt-btn { min-height: 52px; border-radius: 16px; }
.alt-btn[aria-pressed="true"] { background: var(--accent-soft); }
.alt-btn .q-tag {
  display: inline-grid; place-items: center; width: 22px; height: 26px; border: 2px solid var(--ink); border-radius: 4px 4px 6px 6px;
  font-family: var(--font-display); font-size: .9rem; background: #fffaf0; transform: rotate(8deg);
}
.alt-btn .no-mark { display: inline-block; width: 18px; height: 22px; border: 2px solid var(--ink); border-radius: 3px 3px 6px 6px; background: var(--card); }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.kbd-hint { font-size: .78rem; color: var(--ink-soft); display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; } }

/* ---------- jar animations (jar.js adds .kj-anim on the quiz jar only) ---------- */
.kj-anim .kj-liquid { animation: kj-rise .7s var(--ease-out) both; }
.kj-anim .kj-wave { animation: kj-sway 3.2s linear infinite; }
.kj-anim .kj-pop { animation: kj-pop .45s .5s var(--ease-out) both; transform-origin: 60px 30px; transform-box: view-box; }
.kj-anim .kj-spill { animation: kj-fade .4s .55s both; }
.kj-anim.kj-l5 .kj-body { animation: kj-wobble .7s .45s ease-in-out both; transform-origin: 60px 140px; transform-box: view-box; }
@keyframes kj-rise { from { transform: translateY(var(--kj-rise, 0px)); } to { transform: translateY(0); } }
@keyframes kj-sway { from { transform: translateX(0); } to { transform: translateX(-20px); } }
@keyframes kj-pop { from { opacity: 0; transform: scale(.4) translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes kj-fade { from { opacity: 0; } }
@keyframes kj-wobble {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-3.5deg); }
  45% { transform: rotate(3deg); }
  70% { transform: rotate(-1.5deg); }
  85% { transform: rotate(.8deg); }
}

/* ---------- results ---------- */
.results { gap: 22px; }
.result-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 6px; }
.result-name { font-family: var(--font-hand); font-weight: 700; font-size: 2.6rem; line-height: 1; color: var(--accent-dark); border-bottom: 3px solid var(--ink); padding: 0 18px 2px; }
.result-type { font-size: clamp(2rem, 9.5vw, 3rem); max-width: 14ch; }
.result-desc { max-width: 28rem; color: var(--ink-soft); font-size: 1.02rem; }
.pct-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.pct-row .jar-mini svg { width: 64px; height: auto; }
.pct { font-family: var(--font-display); font-weight: 800; font-size: 4.6rem; line-height: .9; color: var(--accent); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; letter-spacing: -.03em; }
.pct-label { font-weight: 800; text-align: left; line-height: 1.2; }
.pct-label small { display: block; font-weight: 700; color: var(--ink-soft); }
.top-jars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.top-jar { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 12px 6px 10px; }
.top-jar svg { width: 64px; height: auto; }
.top-jar .rank { font-family: var(--font-display); font-weight: 800; font-size: .9rem; color: var(--accent-dark); }
.top-jar .lbl { font-weight: 800; font-size: .9rem; line-height: 1.15; }
.section-title { font-size: 1.4rem; display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.section-title small { font-family: var(--font-body); font-size: .85rem; font-weight: 800; color: var(--ink-soft); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn-block { grid-column: 1 / -1; }

.shelf { display: flex; flex-direction: column; gap: 4px; }
.shelf-head { display: flex; align-items: baseline; gap: 10px; }
.shelf-head h3 { font-size: 1.25rem; color: var(--accent-dark); }
.shelf-head p { font-size: .82rem; color: var(--ink-soft); }
.shelf-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 4px 6px;
  position: relative;
}
.jar-tile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 0 0 10px; position: relative; }
.jar-tile svg { width: 56px; height: auto; position: relative; z-index: 1; }
.jar-tile::before {
  content: ''; position: absolute; left: -3px; right: -3px; top: calc(56px * 1.25 - 8px); height: 8px;
  background: var(--wood); border-top: 2.5px solid var(--ink); border-bottom: 2.5px solid var(--ink);
}
.jar-tile .lbl { font-size: .74rem; font-weight: 700; line-height: 1.15; margin-top: 4px; }
.jar-tile .lvl { font-size: .72rem; color: var(--ink-soft); font-weight: 800; }
a.jar-tile { color: inherit; text-decoration: none; border-radius: 10px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--ink-soft); font-weight: 700; justify-content: center; }

/* ---------- sheet (dialog) ---------- */
.sheet {
  border: var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 0; margin: auto auto 0;
  width: 100%; max-width: 34rem; max-height: 94dvh; background: var(--paper); color: var(--ink);
  box-shadow: 0 -4px 0 var(--ink);
}
.sheet::backdrop { background: rgba(43, 34, 32, .45); }
.sheet[open] { animation: sheet-up .3s var(--ease-out); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-inner { padding: 18px var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 18px); display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 1.5rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: var(--border); border-radius: var(--pill); overflow: hidden; background: var(--card); }
.seg label { position: relative; text-align: center; padding: 10px 6px; font-weight: 800; cursor: pointer; min-height: 44px; }
.seg label small { display: block; font-weight: 700; font-size: .75rem; color: var(--ink-soft); }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg label:has(input:checked) small { color: inherit; opacity: .85; }
.seg label:has(input:focus-visible) { box-shadow: inset 0 0 0 3px var(--ink); }
.seg label + label { border-left: var(--border); }
.preview-img {
  display: grid; place-items: center; min-height: 200px; background: var(--paper-2); border-radius: var(--radius);
  border: 2px dashed var(--line); padding: 10px;
}
.preview-img img { max-height: 46dvh; width: auto; border-radius: 10px; box-shadow: var(--pop-sm); border: 2px solid var(--ink); }
.preview-img .spinner { font-weight: 800; color: var(--ink-soft); }

@media (min-width: 640px) {
  :root { --gutter: 28px; }
  body { font-size: 18px; }
  .screen { max-width: 40rem; }
  .sheet { border-radius: var(--radius-lg); margin: auto; box-shadow: var(--pop); }
  .jar-stage { width: min(34vh, 280px); }
  .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
  .jar-tile svg { width: 70px; }
  .jar-tile::before { top: calc(70px * 1.25 - 9px); }
}
@media (min-width: 1000px) {
  .screen.results { max-width: 64rem; display: grid; grid-template-columns: 22rem 1fr; align-items: start; column-gap: 40px; }
  .results > .results-side { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 20px; }
  .results > .results-main { display: flex; flex-direction: column; gap: 22px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .kj-anim .kj-wave { animation: none !important; }
}

/* programmatic focus targets (headings) don't need a ring */
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { box-shadow: none; outline: none; }
.results-side, .results-main { display: flex; flex-direction: column; gap: 22px; }
