/* Pico Sort. Builds on /assets/styles.css tokens. Bins are small wooden
   shelves with one compartment per token; tokens are flat shapes. */
:root {
  --shelf-wood: #b9824f;
  --shelf-wood-dark: #8a5a30;
  --shelf-inside: #fff8ee;
  --shelf-board: #e8d3b8;
  --sort-select: #0a66c2;
  --sort-hint: #b45309;
  --sort-refuse: #b42318;
}

.sort-main { padding-block: .25rem 2.5rem; }
.sort-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; margin: 0 0 .35rem; }
.sort-heading h1 { font-size: clamp(1.45rem, 5vw, 2.1rem); line-height: 1.15; letter-spacing: -.02em; }
.sort-subtitle { margin: 0; color: var(--muted); font-size: .9rem; font-weight: 700; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.sort-card { max-width: 34rem; display: grid; gap: .45rem; padding: .5rem; border: 1px solid var(--line-strong); border-radius: 1.1rem; background: linear-gradient(#fffaf2, #fff 45%); box-shadow: 0 10px 28px rgba(16, 35, 63, .08); }

/* Level switch and stage bar: one row each, nothing larger than the board. */
.sort-levels { display: grid; grid-template-columns: repeat(3, 1fr); padding: 2px; border: 1px solid var(--line-strong); border-radius: 999px; background: #fff; }
.sort-level { min-height: 2.75rem; padding: .25rem .4rem; border: 0; border-radius: 999px; background: transparent; color: var(--accent-dark); font: inherit; font-size: .9rem; font-weight: 780; cursor: pointer; }
.sort-level[aria-pressed="true"] { background: var(--accent); color: #fff; }
.sort-stagebar { display: grid; grid-template-columns: 2.75rem 1fr 2.75rem; align-items: center; gap: .4rem; }
.sort-step { min-width: 2.75rem; min-height: 2.75rem; border: 1px solid var(--line-strong); border-radius: .7rem; background: #fff; color: var(--accent-dark); font: inherit; font-size: 1.3rem; font-weight: 800; cursor: pointer; }
.sort-step:disabled { opacity: .4; cursor: default; }
.sort-stage-title { display: flex; justify-content: center; align-items: center; gap: .35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sort-stage-title [data-stage-mark] { color: var(--sort-hint); }
.sort-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: .3rem; margin: 0; }
.sort-counts div { display: flex; justify-content: center; align-items: baseline; gap: .3rem; padding: .25rem; border-radius: .6rem; background: var(--soft); }
.sort-counts dt { color: var(--muted); font-size: .8rem; font-weight: 700; }
.sort-counts dd { margin: 0; font-size: 1.05rem; font-weight: 820; font-variant-numeric: tabular-nums; }

/* Board: two rows of at most five shelves on phones, one row when there is room. */
.sort-board { --cols: 5; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 4.75rem)); justify-content: center; gap: .55rem .45rem; padding: .6rem .2rem .3rem; user-select: none; -webkit-user-select: none; }
@media (min-width: 40rem) { .sort-board { grid-template-columns: repeat(var(--bins), minmax(0, 4.75rem)); } }
.sort-bin { position: relative; min-width: 2.75rem; display: block; padding: .3rem .3rem .55rem; border: 3px solid var(--shelf-wood); border-radius: .55rem .55rem .7rem .7rem; background: var(--shelf-inside); color: var(--ink); font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: transform .15s ease, box-shadow .15s ease; }
/* The drawer pull at the bottom of each shelf. */
.sort-bin::after { content: ""; position: absolute; left: 50%; bottom: .15rem; width: 34%; height: .22rem; border-radius: 999px; background: var(--shelf-wood-dark); transform: translateX(-50%); }
.sort-slots { display: flex; flex-direction: column-reverse; gap: 0; }
/* Fixed-height compartments keep two rows of shelves within a small phone screen. */
.sort-slot { display: grid; place-items: center; height: 2.4rem; border-top: 2px solid var(--shelf-board); }
.sort-slot:last-child { border-top-color: transparent; }
/* Tokens never take taps: while a moved token slides, it is drawn over another
   shelf, and a quick tap there must still go to the shelf under the finger. */
.sort-token { width: 1.95rem; height: 1.95rem; max-width: 88%; pointer-events: none; transition: transform .15s ease; }
.sort-slot.is-lifted .sort-token { transform: translateY(-.3rem); }
@media (min-width: 40rem) { .sort-slot { height: 3rem; } .sort-token { width: 2.4rem; height: 2.4rem; } }
.sort-bin.is-selected { border-color: var(--sort-select); box-shadow: 0 0 0 3px rgba(10, 102, 194, .28); transform: translateY(-.35rem); }
.sort-bin.is-hint { border-style: dashed; border-color: var(--sort-hint); box-shadow: 0 0 0 3px rgba(180, 83, 9, .25); }
.sort-bin.is-complete { background: #eef8f1; }
.sort-bin.is-complete::before { content: "✓"; position: absolute; top: -.85rem; right: -.4rem; display: grid; place-items: center; width: 1.3rem; height: 1.3rem; border-radius: 999px; background: #1f7a4d; color: #fff; font-size: .75rem; font-weight: 800; }
.sort-bin.is-refused { border-color: var(--sort-refuse); animation: sort-refuse .4s ease; }
.sort-bin[aria-disabled="true"] { cursor: default; }
.sort-bin:focus-visible, .sort-level:focus-visible, .sort-step:focus-visible, .sort-stage:focus-visible, .sort-action:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
@keyframes sort-refuse { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

.sort-status { min-height: 2.6em; margin: 0; padding-inline: .2rem; font-size: .92rem; font-weight: 650; text-align: center; }
.sort-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.sort-action { min-height: 2.9rem; padding: .3rem .4rem; border: 1px solid var(--accent); border-radius: .75rem; background: #fff; color: var(--accent-dark); font: inherit; font-size: .92rem; font-weight: 760; cursor: pointer; }
.sort-action:disabled { opacity: .45; cursor: default; }
.sort-undo-note { margin: 0; color: var(--muted); font-size: .8rem; text-align: center; }

.sort-result { position: relative; overflow: hidden; display: grid; gap: .45rem; padding: .9rem; border: 2px solid #f0c36b; border-radius: .9rem; background: #fff4d6; text-align: center; }
.sort-result:focus { outline: none; }
.sort-result:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sort-result h2 { margin: 0; font-size: 1.35rem; }
.sort-result p { margin: 0; font-weight: 700; }
.sort-perfect { color: #8a3d00; font-size: 1.1rem; letter-spacing: .02em; }
/* Stars: filled ★ and outlined ☆ differ in shape, so the rating never rests on colour. */
.sort-stars { color: #8a3d00; font-size: 2rem; line-height: 1.1; letter-spacing: .12em; }
.sort-stars:not([hidden]) { animation: sort-stars-in .35s ease-out; }
.sort-star-reason { color: var(--ink); font-size: .9rem; }
/* Title row: an optional guide cat (empty until the official asset exists),
   the title, and one short speech line. */
.sort-result-head { display: flex; align-items: center; justify-content: center; gap: .6rem; }
.sort-result-cat { flex: none; width: 3.5rem; height: 3.5rem; }
.sort-result-cat img { display: block; width: 100%; height: 100%; }
.sort-result-cat[hidden] { display: none; }
.sort-result .sort-bubble { display: inline-block; margin: .3rem 0 0; padding: .2rem .75rem; border: 2px solid #f0c36b; border-radius: 1rem; background: #fff; font-size: .92rem; line-height: 1.45; }
.sort-bubble[hidden], .sort-bubble:empty { display: none; }
.sort-result-cat:not([hidden]) + div .sort-bubble { position: relative; }
.sort-result-cat:not([hidden]) + div .sort-bubble::before { content: ""; position: absolute; left: -.55rem; top: 50%; margin-top: -.35rem; border: .35rem solid transparent; border-right: .5rem solid #f0c36b; border-left: 0; }
.sort-totals { color: var(--ink); font-size: .85rem; font-variant-numeric: tabular-nums; }
.sort-totals:empty { display: none; }
/* ★★★ only: one light fall of confetti in the Okabe-Ito token colours. It
   never takes taps and is not drawn at all under reduced motion. */
.sort-result[data-stars="3"]::before, .sort-result[data-stars="3"]::after { content: ""; position: absolute; inset: 0 0 auto; height: 5rem; pointer-events: none; background-image: radial-gradient(circle, #e69f00 0 3px, transparent 3.5px), radial-gradient(circle, #56b4e9 0 3px, transparent 3.5px), radial-gradient(circle, #cc79a7 0 2.5px, transparent 3px); background-size: 97px 71px, 131px 59px, 113px 83px; background-position: 11px 6px, 53px 31px, 87px 17px; animation: sort-confetti 1.3s ease-in 1 both; }
.sort-result[data-stars="3"]::after { background-position: 71px 39px, 19px 9px, 43px 52px; animation-delay: .2s; }
@keyframes sort-confetti { from { transform: translateY(-3rem); opacity: 1; } 75% { opacity: 1; } to { transform: translateY(3.5rem); opacity: 0; } }
.sort-star-reason:empty { display: none; }
@keyframes sort-stars-in { from { transform: scale(.85); opacity: .4; } to { transform: none; opacity: 1; } }
.sort-again { min-height: 2.75rem; border: 1px solid var(--accent); border-radius: .7rem; background: #fff; color: var(--accent-dark); font: inherit; font-weight: 760; cursor: pointer; }

.sort-stages summary { min-height: 2.75rem; display: flex; align-items: center; padding-inline: .3rem; font-weight: 760; cursor: pointer; }
.sort-stage-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .35rem; margin: .2rem 0 .3rem; padding: 0; list-style: none; }
.sort-stage { position: relative; width: 100%; min-height: 2.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: .15rem 0; border: 1px solid var(--line-strong); border-radius: .6rem; background: #fff; color: var(--ink); font: inherit; font-weight: 760; line-height: 1.2; cursor: pointer; }
.sort-stage.is-cleared { background: #eef8f1; border-color: #8cc7a6; }
.sort-stage[aria-current="true"] { border: 2px solid var(--accent); }
.sort-stage-mark { color: #8a3d00; font-size: .72rem; letter-spacing: .04em; }
.sort-stage-mark:empty { display: none; }
.sort-stage-total { margin-left: .35rem; color: #8a3d00; font-size: .85rem; font-variant-numeric: tabular-nums; }
.sort-storage-note { margin: 0; color: var(--muted); font-size: .82rem; }

.sort-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .3rem .8rem; padding: 0; list-style: none; }
.sort-legend li { display: flex; align-items: center; gap: .45rem; }
.sort-legend .sort-token { width: 1.6rem; height: 1.6rem; flex: none; }

@media (prefers-reduced-motion: reduce) {
  .sort-bin, .sort-token { transition: none; }
  .sort-bin.is-selected { transform: none; }
  .sort-slot.is-lifted .sort-token { transform: none; }
  .sort-bin.is-refused { animation: none; outline: 3px solid var(--sort-refuse); outline-offset: 2px; }
  .sort-stars:not([hidden]) { animation: none; }
  .sort-result[data-stars="3"]::before, .sort-result[data-stars="3"]::after { content: none; animation: none; }
}
