/* The quiz engine: hud, lane, cards, answer box, recap content and share.
   Reusable by any page built on the same shell (kn-page / l-intro / the
   kn-setup-kn-quiz-kn-recap panel) - the page's own stylesheet supplies the
   panel and whatever picks the deck; this file supplies what happens once a
   round starts. */

/* A small pill button used by the deck quick-picks, the round-length picker,
   the recap actions and the share row alike - one component, several places
   it shows up. .c-btn in /styles.css is written for an <a>; on a <button>
   the native chrome shows through, so kn-chip and kn-recap__again below
   clear it themselves rather than relying on that reset. */
.kn-chip.is-on {
  border-color: var(--c-pink);
  background: var(--c-pink);
  color: #fff;
  font-weight: 700;
}
.kn-chip.is-on:hover { color: #fff; }

.kn-chip {
  border: 1px solid var(--c-border);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--c-body);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.kn-chip:hover { border-color: var(--c-pink); color: var(--c-pink); }

.kn-recap__again {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* ============================ quiz hud ============================ */

.kn-hud {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--c-muted);
  margin-bottom: 18px;
}
.kn-hud__item b { color: var(--c-pink); font-size: 17px; margin-right: 3px; }
.kn-hud__quit {
  margin-left: auto;
  border: 1px solid var(--c-border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 15px;
  font: inherit;
  font-size: 13px;
  color: var(--c-body);
  cursor: pointer;
}
.kn-hud__quit:hover { border-color: var(--c-pink); color: var(--c-pink); }

/* ============================ the lane ============================ */

.kn-lane {
  position: relative;
  overflow: hidden;
  height: 168px;
  margin: 0 -24px;
}

.kn-lane__track {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
  width: max-content;
  padding-left: 24px;
  will-change: transform;
}

/* The edges dissolve so cards appear to come from and go into nothing
   rather than being clipped by a hard border. */
.kn-lane__fade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 68px;
  pointer-events: none;
}
.kn-lane__fade--left  { left: 0;  background: linear-gradient(to right, #fff 20%, rgba(255,255,255,0)); }
.kn-lane__fade--right { right: 0; background: linear-gradient(to left,  #fff 10%, rgba(255,255,255,0)); }

.kn-card {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 92px;
  padding: 16px 18px;
  border: 2px solid var(--c-border);
  border-radius: 18px;
  background: var(--c-wash);
  color: var(--c-body);
  opacity: .5;
  transform: scale(.82);
  transition: opacity .3s, transform .3s, border-color .2s, background .2s;
}

.kn-card__kana {
  font-family: 'Noto Sans JP', 'Manrope', sans-serif;
  font-weight: 500;
  font-size: 42px;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
}
/* Word cards hold a whole title, so they get room and a smaller face. A
   wrapped title is taller than a single kana, so the lane grows to match
   rather than clipping it. */
.kn-lane--word { height: 200px; }
.kn-card--word { max-width: 460px; }
.kn-card--word .kn-card__kana { font-size: 30px; white-space: normal; }

/* The reading, revealed only after the card is answered or given up on. */
.kn-card__romaji {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--c-muted);
  min-height: 15px;
  opacity: 0;
  transition: opacity .2s;
}
/* The real title is hidden for the same reason the romaji is: on a character
   card it IS the answer written out in latin letters, and on a song card it is
   a strong hint. Kept in the layout at zero opacity so revealing it does not
   change the card's height and shove the lane around. */
.kn-card__title {
  font-size: 11px;
  color: var(--c-muted);
  text-align: center;
  max-width: 100%;
  opacity: 0;
  transition: opacity .2s;
}

/* The card being asked right now. */
.kn-card.is-active {
  opacity: 1;
  transform: scale(1);
  background: #fff;
  border-color: var(--c-pink);
  box-shadow: 0 8px 24px rgba(229, 48, 125, .16);
}

.kn-card.is-right { border-color: #43b581; background: #f2fbf6; }
.kn-card.is-right .kn-card__romaji { opacity: 1; color: #43b581; }
.kn-card.is-wrong { border-color: #e05b5b; background: #fef4f4; }
.kn-card.is-wrong .kn-card__romaji { opacity: 1; color: #e05b5b; }
.kn-card.is-revealed .kn-card__romaji { opacity: 1; }

/* Answered, either way: now the whole card can be read. */
.kn-card.is-right .kn-card__title,
.kn-card.is-wrong .kn-card__title,
.kn-card.is-revealed .kn-card__title { opacity: 1; }

/* Cards already answered keep sliding left and fade out on the way. */
.kn-card.is-done { opacity: .3; transform: scale(.7); }

@keyframes kn-shake {
  0%, 100% { transform: scale(1) translateX(0); }
  20% { transform: scale(1) translateX(-8px); }
  40% { transform: scale(1) translateX(7px); }
  60% { transform: scale(1) translateX(-5px); }
  80% { transform: scale(1) translateX(3px); }
}
.kn-card.is-shaking { animation: kn-shake .4s; }

/* ============================ answer box ============================ */

.kn-answer { display: flex; gap: 10px; margin-top: 22px; }

.kn-answer__input {
  flex: 1;
  min-width: 0;
  padding: 15px 18px;
  border: 2px solid var(--c-border);
  border-radius: 14px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--c-body);
  background: #fff;
  outline: none;
  transition: border-color .15s;
}
.kn-answer__input:focus { border-color: var(--c-pink); }
.kn-answer__input::placeholder { font-weight: 400; letter-spacing: 0; color: #c4c4c4; }

.kn-answer__skip {
  border: 1px solid var(--c-border);
  background: #fff;
  border-radius: 14px;
  padding: 0 18px;
  font: inherit;
  font-size: 14px;
  color: var(--c-muted);
  cursor: pointer;
  white-space: nowrap;
}
.kn-answer__skip:hover { border-color: var(--c-pink); color: var(--c-pink); }

.kn-answer__feedback { min-height: 22px; margin: 12px 0 0; font-size: 14px; font-weight: 700; }
.kn-answer__feedback.is-right { color: #43b581; }
.kn-answer__feedback.is-wrong { color: #e05b5b; }

/* ============================ recap ============================ */

.kn-recap__title { font-family: 'Montserrat Alternates', sans-serif; font-size: 22px; margin: 0 0 16px; color: var(--c-pink); }
.kn-recap__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.kn-stat { background: var(--c-wash); border-radius: 14px; padding: 14px; text-align: center; }
.kn-stat b { display: block; font-size: 26px; color: var(--c-pink); }
.kn-stat span { font-size: 12px; color: var(--c-muted); }

.kn-recap__weak { margin-top: 18px; }
.kn-recap__weak p { font-size: 13px; color: var(--c-muted); margin: 0 0 8px; }
.kn-weak-list { display: flex; flex-wrap: wrap; gap: 8px; }
.kn-weak {
  display: flex;
  align-items: baseline;
  gap: 7px;
  background: #fef4f4;
  border: 1px solid #f3d5d5;
  border-radius: 12px;
  padding: 8px 12px;
}
.kn-weak b { font-family: 'Noto Sans JP', sans-serif; font-size: 20px; color: var(--c-body); font-weight: 500; }
.kn-weak span { font-size: 12px; color: var(--c-muted); }

.kn-recap__actions { display: flex; align-items: center; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* ============================ share ============================ */

.kn-share { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--c-border); }
.kn-share__title {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin: 0 0 10px;
}
.kn-share__preview {
  background: var(--c-wash);
  border: 1px solid var(--c-border);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 0 0 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  color: var(--c-body);
  /* The summary is pre-formatted but must still reflow on a narrow screen. */
  white-space: pre-wrap;
  word-break: break-word;
}
.kn-share__buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.kn-chip--solid { background: var(--c-pink); border-color: var(--c-pink); color: #fff; }
.kn-chip--solid:hover { background: #d02a70; border-color: #d02a70; color: #fff; }
a.kn-chip { text-decoration: none; display: inline-block; }
.kn-share__status { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: #43b581; font-weight: 700; }

/* ============================ mobile ============================ */

@media (max-width: 1024px) and (min-width: 701px) {
  .kn-lane { height: 156px; }
  .kn-lane--word { height: 190px; }
  .kn-card--word { max-width: 60vw; }
}

@media (max-width: 700px) {
  .kn-lane { height: 140px; margin: 0 -16px; }
  .kn-lane--word { height: 176px; }
  .kn-lane__track { padding-left: 16px; gap: 10px; }
  .kn-lane__fade { width: 40px; }
  .kn-card { min-width: 76px; padding: 13px 14px; border-radius: 15px; }
  .kn-card__kana { font-size: 34px; }
  .kn-card--word { max-width: 74vw; }
  .kn-card--word .kn-card__kana { font-size: 22px; }

  /* Kept at 17px deliberately: iOS zooms the whole page in when a focused
     input is under 16px, and the zoom does not come back out. */
  .kn-answer__input { font-size: 17px; padding: 13px 15px; }
  .kn-answer__skip { padding: 0 14px; font-size: 13px; }
  .kn-hud { gap: 12px; margin-bottom: 12px; font-size: 12px; }
  .kn-hud__item b { font-size: 15px; }

  /* Share buttons are the last thing tapped, often one-handed, so they get
     full-width rows rather than a cramped wrap. */
  .kn-share__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .kn-chip { padding: 11px 14px; text-align: center; }
  .kn-share__preview { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .kn-lane__track { transition: none !important; }
  .kn-card.is-shaking { animation: none; }
}
