/* Hitokuchi 改札 (direction E): components, from docs/design/hitokuchi-e/components.css. Load after app.css.
   Plain CSS for server-rendered HTML + htmx. No build step, no animation library.
   Every component reads tokens only; nothing here defines a colour. */

:where(:root) {
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-pop: cubic-bezier(.2, 1.4, .4, 1);
  --t-press: 110ms;   /* touch feedback */
  --t-enter: 260ms;   /* next pair arrives */
  --t-pass: 440ms;    /* chosen ticket passes the gate; next pair is swapped in at this point */
}

/* ---------- Text helpers ---------- */
.hk-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
/* Restaurant names: never ellipsis on cards. Server splits 店名 / 支店名 and may insert <wbr>. */
.hk-name {
  font-weight: 800; font-feature-settings: "palt";
  word-break: auto-phrase; line-break: strict; overflow-wrap: anywhere; text-wrap: pretty;
}
.hk-meta { font-size: 13px; line-height: 1.5; font-weight: 600; color: var(--ink2); }

/* ---------- The bite (signature) ----------
   Two overlapping circles cut from the top-right edge. Works on any square/round element. */
.hk-bite {
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  mask-composite: intersect;
}
/* Corner bite for large cards (fixed px so it doesn't stretch). Set --bite on the element. */
.hk-bite-corner {
  --bite: 31px;
  --b1: radial-gradient(circle var(--bite) at calc(100% - var(--bite) * .13) calc(var(--bite) * 1.48), #0000 97%, #000);
  --b2: radial-gradient(circle var(--bite) at calc(100% - var(--bite) * 1.55) calc(var(--bite) * .13), #0000 97%, #000);
  -webkit-mask: var(--b1), var(--b2); -webkit-mask-composite: source-in;
  mask: var(--b1), var(--b2); mask-composite: intersect;
}

/* ---------- Score disc ----------
   <span class="hk-score" data-band="great" aria-label="スコア 8.9、優勝">8.9</span>
   Band comes from scoreClass(): great ≥8.5 · good ≥7 · meh ≥4 · bad <4. */
.hk-score {
  --d: 48px;
  inline-size: var(--d); block-size: var(--d); flex: none;
  display: inline-grid; place-items: center; border-radius: 50%;
  background: var(--meh); color: var(--chip-ink);
  font: 800 calc(var(--d) * .32)/1 var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.04em;
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  mask-composite: intersect;
}
.hk-score[data-band="great"], .hk-score.s-great { background: var(--great); }
.hk-score[data-band="good"],  .hk-score.s-good  { background: var(--good); }
.hk-score[data-band="meh"],   .hk-score.s-meh   { background: var(--meh); }
.hk-score[data-band="bad"],   .hk-score.s-bad   { background: var(--bad); }
.hk-score--xs { --d: 24px; font-size: 9px; }
.hk-score--sm { --d: 36px; }
.hk-score--lg { --d: 72px; }
/* 10.0 is a digit wider than the rest, and worth a second, smaller bite on the far side. */
.hk-score--ten {
  font-size: calc(var(--d) * .26);
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000),
    radial-gradient(14% 14% at 9% 79%, #0000 96%, #000), radial-gradient(14% 14% at 21% 91%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000),
    radial-gradient(14% 14% at 9% 79%, #0000 96%, #000), radial-gradient(14% 14% at 21% 91%, #0000 96%, #000);
  mask-composite: intersect;
}
.hk-score--hero { --d: 132px; }
.hk-score--none { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink3); color: var(--ink3); -webkit-mask: none; mask: none; }

/* ---------- Kanji tile ----------
   <span class="hk-tile" lang="ja" aria-hidden="true">麺</span>  (genreKanji) */
.hk-tile {
  --t: 48px;
  inline-size: var(--t); block-size: var(--t); flex: none;
  display: inline-grid; place-items: center; border-radius: 22%;
  background: var(--tile); color: var(--tile-ink);
  font: 900 calc(var(--t) * .56)/1 var(--font-kanji);
  box-shadow: 0 0 0 calc(var(--t) * .04) var(--tile-edge);
}
.hk-tile--sm { --t: 32px; }
.hk-tile--lg { --t: 76px; }
/* Sticker: hero moments only (compare, reveal). Upright in lists. */
.hk-tile--sticker {
  transform: rotate(var(--tilt, -4deg));
  box-shadow: 0 0 0 calc(var(--t) * .045) var(--tile-edge), 0 calc(var(--t) * .07) 0 -1px var(--sticker-drop);
}

/* ---------- Pass: the 乗車券 progress strip ----------
   One hole per comparison. Holes = comparisons done + 「あと約N回」. */
.hk-pass {
  display: flex; align-items: center; gap: 10px; min-block-size: 44px; padding: 0 12px;
  border-radius: 6px; background: var(--ticket); color: var(--ticket-ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ticket-ink) 10%, transparent);
}
.hk-pass__label { font: 900 11px/1.2 var(--font-ja); letter-spacing: .08em; }
.hk-pass__rule { flex: 1; align-self: stretch; margin: 6px 0; border-left: 1.5px dashed color-mix(in srgb, var(--ticket-ink) 35%, transparent); }
.hk-pass__hole { position: relative; inline-size: 22px; block-size: 22px; flex: none; }
.hk-pass__hole::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%;
  border: 1.5px dashed color-mix(in srgb, var(--ticket-ink) 40%, transparent);
}
.hk-pass__hole.is-punched::after {
  inset: 0; border: 0; background: var(--canvas);
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  mask-composite: intersect;
}
/* The hole being punched right now: pops in and drops three paper chads. */
.hk-pass__hole.is-punching::after { animation: hk-pop 240ms var(--ease-pop) both; }
.hk-pass__hole.is-punching::before {
  content: ""; position: absolute; left: 8px; top: 8px; inline-size: 6px; block-size: 5px; border-radius: 2px;
  background: var(--ticket);
  box-shadow: 7px -2px 0 var(--ticket), -6px 3px 0 var(--accent);
  animation: hk-chad 600ms cubic-bezier(.3, 0, .7, 1) both;
}

/* ---------- Ask sticker 「どっちが好き？」 ---------- */
.hk-ask {
  display: inline-block; margin: 0; padding: 9px 20px 10px; border-radius: 14px;
  background: var(--ask-bg); color: var(--ask-ink);
  font: 900 22px/1.3 var(--font-ja); letter-spacing: .02em;
  transform: rotate(-2deg); box-shadow: 0 5px 0 -1px var(--sticker-drop);
}
.hk-ask__mark { color: var(--ask-mark); }

/* ---------- Compare ticket (the button IS the ticket) ----------
   <button class="hk-ticket" name="answer" value="candidate" data-haptic> … </button> */
.hk-compare { display: flex; flex-direction: column; gap: 14px; flex: 1; min-block-size: 0; }
.hk-ticket {
  appearance: none; border: 0; padding: 0; margin: 0; background: none; font: inherit; color: inherit;
  text-align: left; cursor: pointer; position: relative; display: flex; inline-size: 100%;
  flex: 1 1 0; min-block-size: 200px; -webkit-tap-highlight-color: transparent;
  transition: transform var(--t-press) var(--ease-out);
}
.hk-ticket:active { transform: scale(.975); }
.hk-ticket:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 3px; border-radius: var(--radius-ticket); }
.hk-ticket__paper {
  flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 10px;
  padding: 18px 24px 12px; border-radius: var(--radius-ticket);
  background: var(--ticket); color: var(--ticket-ink);
  /* perforated sides */
  -webkit-mask: radial-gradient(circle 6px at 0 50%, #0000 96%, #000) 0 0/51% 20px repeat-y, radial-gradient(circle 6px at 100% 50%, #0000 96%, #000) 100% 0/51% 20px repeat-y;
  mask: radial-gradient(circle 6px at 0 50%, #0000 96%, #000) 0 0/51% 20px repeat-y, radial-gradient(circle 6px at 100% 50%, #0000 96%, #000) 100% 0/51% 20px repeat-y;
}
.hk-ticket__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; font-weight: 900; letter-spacing: .14em; color: var(--ticket-ink2); }
.hk-ticket__body { display: flex; align-items: center; gap: 14px; flex: 1; }
.hk-ticket__text { display: flex; flex-direction: column; gap: 4px; min-inline-size: 0; }
.hk-ticket__name { font-size: 19px; line-height: 1.4; }
.hk-ticket__meta { font-size: 12px; font-weight: 700; color: var(--ticket-ink2); }
.hk-ticket__foot {
  display: flex; justify-content: space-between; margin: 0 -24px; padding: 8px 24px 0;
  border-top: 1.5px dashed color-mix(in srgb, var(--ticket-ink) 30%, transparent);
  font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--ticket-ink2);
}
.hk-ticket.is-new .hk-ticket__head span:first-child { color: var(--ticket-accent); }
/* Tickets are always light paper, so stickers on them keep an ink edge in both themes. */
.hk-ticket__paper, .hk-issue__paper, .hk-pass { --tile-edge: var(--ticket-ink); --sticker-drop: var(--ticket-ink); }
/* States. Enter plays on fresh DOM (htmx swap); pass/dim are set by JS on tap. */
.hk-ticket { animation: hk-enter var(--t-enter) var(--ease-out) backwards; } /* backwards, so :active still scales after it ends */
.hk-ticket + .hk-ticket:not(.is-passing, .is-dimmed) { animation-delay: 50ms; }
.hk-ticket.is-passing { animation: hk-pass var(--t-pass) cubic-bezier(.5, 0, .6, 1) both; pointer-events: none; }
.hk-ticket.is-dimmed { animation: hk-dim 300ms ease-in both; pointer-events: none; }
.hk-ticket.is-passing::after {
  content: ""; position: absolute; right: -8px; top: -8px; inline-size: 38px; block-size: 38px; border-radius: 50%;
  background: var(--canvas); animation: hk-pop 220ms var(--ease-pop) 60ms both;
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  mask-composite: intersect;
}
/* ほぼ同じ: both tickets squash toward the seam. */
.hk-compare.is-tie .hk-ticket { animation: hk-tie 300ms ease-in-out both; pointer-events: none; }

/* ---------- Issued ticket (the reveal) ----------
   Prints out of the slot in steps, then gets its bite punched. Background = score band. */
.hk-issue { display: flex; flex-direction: column; align-items: center; }
.hk-issue__slot { position: relative; z-index: 2; inline-size: 100%; block-size: 14px; border-radius: 7px; background: var(--slot); box-shadow: inset 0 3px 4px rgba(0, 0, 0, .7), 0 1px 0 var(--line); }
.hk-issue__window { inline-size: calc(100% - 28px); margin-top: -7px; overflow: hidden; }
.hk-issue__paper {
  position: relative; box-sizing: border-box; min-block-size: 300px; display: flex; flex-direction: column;
  padding: 22px 26px 18px; border-radius: 0 0 14px 14px;
  background: var(--meh); color: var(--chip-ink);
  -webkit-mask: radial-gradient(circle 6px at 0 50%, #0000 96%, #000) 0 0/51% 20px repeat-y, radial-gradient(circle 6px at 100% 50%, #0000 96%, #000) 100% 0/51% 20px repeat-y;
  mask: radial-gradient(circle 6px at 0 50%, #0000 96%, #000) 0 0/51% 20px repeat-y, radial-gradient(circle 6px at 100% 50%, #0000 96%, #000) 100% 0/51% 20px repeat-y;
  animation: hk-print 700ms steps(14) 100ms both;
}
.hk-issue__paper[data-band="great"], .hk-issue__paper.s-great { background: var(--great); }
.hk-issue__paper[data-band="good"], .hk-issue__paper.s-good  { background: var(--good); }
.hk-issue__paper[data-band="meh"], .hk-issue__paper.s-meh   { background: var(--meh); }
.hk-issue__paper[data-band="bad"], .hk-issue__paper.s-bad   { background: var(--bad); }
.hk-issue__head { display: flex; justify-content: space-between; font-size: 11px; font-weight: 900; letter-spacing: .14em; }
.hk-issue__score { font: 800 104px/1 var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.05em; margin: 14px 0 0 -4px; }
.hk-issue__name { font-size: 20px; line-height: 1.35; padding-right: 76px; margin: auto 0 0; }
.hk-issue__meta { font-size: 12px; font-weight: 700; margin-top: 4px; }
.hk-issue__paper > .hk-tile { position: absolute; right: 24px; bottom: 26px; }
.hk-issue__punch {
  position: absolute; right: -14px; top: 36px; inline-size: 46px; block-size: 46px; border-radius: 50%;
  background: var(--canvas); animation: hk-pop 220ms var(--ease-pop) 950ms both;
  -webkit-mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask: radial-gradient(19% 19% at 93% 24%, #0000 96%, #000), radial-gradient(19% 19% at 76% 7%, #0000 96%, #000);
  mask-composite: intersect;
}

/* ---------- Rank rows + reshuffle ----------
   On the reveal: rows above stay, .is-new slides in, rows below step down one place. */
.hk-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.hk-row {
  display: flex; align-items: center; gap: 12px; min-block-size: 52px; padding: 0 12px;
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.hk-row__rank { inline-size: 24px; text-align: center; font: 800 14px/1 var(--font-num); color: var(--ink3); }
.hk-row__rank.is-top { color: var(--accent-text); }
.hk-row__main { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; }
.hk-row__name { font-size: 15px; line-height: 1.4; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hk-row.is-new { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); animation: hk-slidein 420ms cubic-bezier(.2, 1.2, .4, 1) 1350ms both; }
.hk-row.is-shared { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.hk-row.is-shifted { animation: hk-shift 320ms var(--ease-out) 1250ms both; }

/* ---------- Card (feed) ---------- */
.hk-card { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 14px 16px 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.hk-card > .hk-score { position: absolute; top: -12px; right: 14px; transform: rotate(6deg); }
.hk-card__who { display: flex; align-items: center; gap: 8px; padding-right: 64px; font-size: 13px; }
.hk-card__place { display: flex; gap: 12px; align-items: flex-start; }

/* ---------- Chips ---------- */
.hk-chip {
  display: inline-flex; align-items: center; gap: 6px; min-block-size: 36px; padding: 0 14px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font: 800 13px/1 var(--font-ja); white-space: nowrap; cursor: pointer;
}
.hk-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--canvas); }
.hk-chip--tier { min-block-size: 26px; padding: 0 10px; border: 0; background: var(--surface2); color: var(--ink2); font-size: 11px; cursor: default; }
.hk-chip--tier[data-tier="0"] { background: var(--accent-soft); color: var(--accent-ink); }
.hk-chip--match { min-block-size: 26px; padding: 0 10px; border: 0; background: var(--accent-soft); color: var(--accent-ink); font-size: 11px; cursor: default; }

/* ---------- Buttons ---------- */
.hk-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-block-size: 52px; padding: 0 22px; border: 0; border-radius: var(--radius-btn);
  background: var(--accent); color: var(--on-accent);
  font: 900 15px/1 var(--font-ja); font-feature-settings: "palt"; cursor: pointer;
  transition: transform var(--t-press) var(--ease-out); text-decoration: none;
}
.hk-btn:active { transform: scale(.97); }
.hk-btn:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
.hk-btn--share { background: var(--ask-bg); color: var(--ask-ink); }      /* ストーリーズに */
.hk-btn--ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); font-weight: 800; }
.hk-btn--pill { min-block-size: 46px; border-radius: 999px; font-size: 14px; font-weight: 800; }
.hk-btn--block { inline-size: 100%; }
.hk-btn--text { background: none; color: var(--accent-text); min-block-size: 44px; padding: 0 8px; font-weight: 800; }

/* ---------- Tab bar ---------- */
.hk-tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.hk-tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-block-size: 50px; color: var(--ink3); font: 700 11px/1.35 var(--font-ja); text-decoration: none; }
.hk-tabbar a:active { opacity: .6; }
.hk-tabbar a { position: relative; }
.tab-dot { position: absolute; top: -3px; left: calc(50% + 18px); inline-size: 9px; block-size: 9px; border-radius: 50%; background: var(--accent); }
/* content-box: the pill padding goes around the 22px icon, not into it (pages set border-box on everything). */
.hk-tabbar svg { box-sizing: content-box; inline-size: 22px; block-size: 22px; padding: 4px 15px; border-radius: 999px; fill: currentColor; }
.hk-tabbar a[aria-current="page"] { color: var(--ink); font-weight: 800; }
.hk-tabbar a[aria-current="page"] svg {
  background: var(--accent); color: var(--on-accent);
  -webkit-mask: radial-gradient(circle 7px at calc(100% - 4px) 1px, #0000 96%, #000);
  mask: radial-gradient(circle 7px at calc(100% - 4px) 1px, #0000 96%, #000);
}

/* ---------- Motion ---------- */
@keyframes hk-enter   { from { transform: translateY(46px); opacity: 0; } }
@keyframes hk-pass    { 0% { transform: none; } 35% { transform: translateY(-8px) scale(1.03) rotate(-1deg); } 100% { transform: translateY(-150px) scale(.96) rotate(-3deg); opacity: 0; } }
@keyframes hk-dim     { to { transform: translateY(16px) scale(.96); opacity: 0; } }
@keyframes hk-tie     { 50% { transform: scale(.96); } 100% { transform: scale(.96); opacity: 0; } }
@keyframes hk-pop     { from { transform: scale(0); } 70% { transform: scale(1.25); } to { transform: scale(1); } }
@keyframes hk-chad    { from { transform: translate(0, 0) rotate(0); opacity: 1; } to { transform: translate(-4px, 70px) rotate(200deg); opacity: 0; } }
@keyframes hk-print   { from { transform: translateY(-100%); } }
@keyframes hk-slidein { from { transform: translateX(110%); } }
@keyframes hk-shift   { from { transform: translateY(-58px); } }

@media (prefers-reduced-motion: reduce) {
  .hk-ticket, .hk-ticket.is-passing, .hk-ticket.is-dimmed, .hk-compare.is-tie .hk-ticket,
  .hk-pass__hole.is-punching::after, .hk-pass__hole.is-punching::before, .hk-ticket.is-passing::after,
  .hk-issue__paper, .hk-issue__punch, .hk-row.is-new, .hk-row.is-shifted {
    animation-duration: 1ms !important; animation-delay: 0s !important;
  }
  .hk-ticket.is-passing, .hk-ticket.is-dimmed { animation: none !important; opacity: .4; transition: opacity 150ms; }
  .hk-ticket:active, .hk-btn:active { transform: none; }
}
