/* Drills: the library as a deck of cards. The count is the headline, the kit
   and skill chips deal the deck, the top card plays its drill, and the deck can
   spread into a grid and gather back. */

.dk {
  display: grid; grid-template-columns: minmax(330px, 4fr) minmax(0, 7fr); column-gap: var(--s8);
  padding: 100px var(--gut) var(--s8); align-items: start; min-height: 100svh;
}
.dk-side { position: sticky; top: 96px; }
.dk-title {
  font-family: var(--d); font-weight: 820; font-stretch: var(--wide); letter-spacing: -0.04em; line-height: 0.86;
  font-size: clamp(64px, min(8.4vw, 15svh), 136px);
}
.dk-n { display: block; font-variant-numeric: tabular-nums; }
.dk-w { display: block; }

.dk-filters { margin-top: var(--s6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
.dk-group { min-width: 0; }
.dk-group .kit, .dk-group .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 0; }
.dk-group .kit-q { margin-bottom: var(--s2); }
.dk-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }

.dk-search {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: var(--r-ctl);
  border: 1.5px solid color-mix(in oklch, var(--ink) 18%, transparent); background: var(--paper); min-width: 170px; flex: 1; max-width: 240px;
  transition: border-color 0.2s var(--out);
}
.dk-search:focus-within { border-color: var(--ink); }
.dk-search .ic { width: 16px; height: 16px; color: var(--ink-2); }
.dk-search input { border: 0; background: transparent; outline: none; font-size: 15px; font-weight: 520; width: 100%; min-width: 0; }
.dk-search input::placeholder { color: var(--ink-3); }

/* the table the deck sits on */
.dk-table { display: flex; flex-direction: column; min-width: 0; }
.dk-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); height: 48px; }
.dk-pos { font-size: 14px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 90px; }
.dk-views { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-ctl); background: var(--ground-deep); }
.dk-views button { width: 40px; height: 36px; border: 0; border-radius: var(--r-ctl); background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); transition: background-color 0.2s var(--out), color 0.2s var(--out); }
.dk-views button[aria-checked='true'] { background: var(--ink); color: var(--paper); }
.dk-views .ic { width: 18px; height: 18px; }
.dk-saved {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 12px; border-radius: var(--r-ctl);
  border: 1.5px solid color-mix(in oklch, var(--ink) 18%, transparent); background: transparent; cursor: pointer; font-weight: 620; font-size: 14px;
}
.dk-saved .ic { width: 16px; height: 16px; }
.dk-saved b { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--ink); color: var(--paper); font-size: 12px; display: grid; place-items: center; font-variant-numeric: tabular-nums; }

.dk-stage { position: relative; height: clamp(470px, calc(100svh - 250px), 660px); margin-top: var(--s3); }
.dk-stage.is-spread { height: auto; min-height: 400px; }
.dk-deck { position: absolute; inset: 0; }

/* a card: square-cornered paper with the drill drawn on a slab window */
.dk-card {
  position: absolute; inset: 0; margin: auto; width: min(500px, 88%); height: min(590px, 100%);
  margin: 0; display: flex; flex-direction: column; background: var(--paper);
  border: 1px solid color-mix(in oklch, var(--ink) 10%, transparent);
  transform-origin: 50% 85%; touch-action: none; user-select: none; -webkit-user-select: none;
  will-change: transform;
}
.dk-card.is-top { cursor: grab; }
.dk-card.is-top:active { cursor: grabbing; }
.dk-card-head { padding: var(--s4) var(--s5) var(--s3); display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.dk-card-name { font-family: var(--d); font-weight: 760; font-stretch: 106%; letter-spacing: -0.02em; font-size: 26px; line-height: 1.05; }
.dk-card-lv { font-size: 13px; font-weight: 640; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dk-card-win { position: relative; flex: 1; min-height: 0; margin: 0 var(--s3); background: var(--slab); overflow: hidden; }
.dk-card-win .field { width: 100%; height: 100%; aspect-ratio: auto; }
.dk-card-foot { padding: var(--s3) var(--s5) var(--s4); display: grid; gap: 6px; }
.dk-card-cue { font-size: 16px; font-weight: 600; line-height: 1.3; }
.dk-card-meta { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); font-size: 13px; font-weight: 560; color: var(--ink-2); }
.dk-card-gear { display: inline-flex; gap: 2px; }
.dk-card-gear svg { width: 26px; height: 26px; }
.dk-stamp {
  position: absolute; top: 18px; padding: 8px 14px; border: 2px solid var(--ink); font-weight: 760; font-size: 15px; letter-spacing: 0.02em;
  background: var(--paper); opacity: 0; pointer-events: none; text-transform: uppercase;
}
.dk-stamp-save { left: 18px; rotate: -8deg; }
.dk-stamp-skip { right: 18px; rotate: 8deg; }

/* controls under the deck */
.dk-controls { display: flex; justify-content: center; align-items: center; gap: var(--s3); margin-top: var(--s4); }
.is-spread ~ .dk-controls { visibility: hidden; }
.dk-spread .dk-pos { visibility: hidden; }

/* the spread: every card in the deal at once */
.dk-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); }
.dk-grid li { min-width: 0; }
.dk-mini { position: relative; display: flex; flex-direction: column; width: 100%; padding: 0; text-align: left; cursor: pointer; background: var(--paper); border: 1px solid color-mix(in oklch, var(--ink) 10%, transparent); transition: border-color 0.2s var(--out); }
.dk-mini .win { aspect-ratio: 4 / 3; margin: var(--s2) var(--s2) 0; background: var(--slab); overflow: hidden; }
.dk-mini .field { width: 100%; height: 100%; aspect-ratio: auto; }
.dk-mini .t { padding: var(--s2) var(--s3) var(--s3); display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.dk-mini .t b { font-family: var(--d); font-weight: 740; font-stretch: 104%; font-size: 16px; line-height: 1.15; }
.dk-mini .t span { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.dk-mini.is-saved::after { content: ''; position: absolute; right: 12px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); }
@media (hover: hover) { .dk-mini:hover { border-color: var(--ink); } }

.dk-empty, .dk-end { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: var(--s4); text-align: center; }
.dk-empty[hidden], .dk-end[hidden] { display: none; }
.dk-empty-t { font-family: var(--d); font-weight: 760; font-stretch: 106%; font-size: 30px; }

/* ---------- drill detail ---------- */
.dd {
  width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--ground); color: var(--ink); overscroll-behavior: contain;
}
.dd::backdrop { background: color-mix(in oklch, var(--ink) 40%, transparent); }
.dd-in { min-height: 100%; display: flex; flex-direction: column; padding: 0 var(--gut) var(--s6); }
.dd-top { display: flex; align-items: center; justify-content: space-between; height: 72px; flex: none; }
.dd-nav { display: flex; gap: var(--s2); }
.dd-body { flex: 1; display: grid; grid-template-columns: minmax(0, 7fr) minmax(320px, 5fr); gap: var(--s7); align-items: start; }
.dd-window { position: sticky; top: var(--s4); margin: 0; background: var(--slab); height: min(72vh, 680px); }
.dd-window .field { width: 100%; height: 100%; aspect-ratio: auto; }
.dd-play { position: absolute; right: var(--s3); bottom: var(--s3); }
.dd-play .dk-btn { background: var(--paper); border-color: transparent; }
.dd-text { padding-top: var(--s2); max-width: 560px; }
.dd-name { margin-top: var(--s2); font-family: var(--d); font-weight: 790; font-stretch: var(--wide); letter-spacing: -0.03em; font-size: clamp(34px, 3.6vw, 54px); line-height: 0.98; }
.dd-spec { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s4) var(--s4); margin: var(--s5) 0 0; padding: var(--s4) 0; border-top: 1px solid var(--joint); border-bottom: 1px solid var(--joint); }
.dd-spec dt { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.dd-spec dd { margin: 2px 0 0; font-size: 17px; font-weight: 660; line-height: 1.25; }
.dd-setup { margin-top: var(--s5); font-size: 17px; line-height: 1.45; }
.dd-steps { margin: var(--s4) 0 0; padding: 0; list-style: none; counter-reset: st; display: grid; gap: var(--s3); }
.dd-steps li { counter-increment: st; display: grid; grid-template-columns: 28px 1fr; gap: var(--s2); font-size: 17px; line-height: 1.4; }
.dd-steps li::before { content: counter(st); width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 13px; font-weight: 700; display: grid; place-items: center; margin-top: 1px; }
.dd-cue { margin-top: var(--s5); font-family: var(--d); font-weight: 740; font-stretch: 104%; font-size: 26px; line-height: 1.15; letter-spacing: -0.015em; }
.dd-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--joint); }
.dd-pair p { font-size: 15px; line-height: 1.45; }
.dd-k { font-size: 13px !important; font-weight: 640; color: var(--ink-2); margin-bottom: 4px; }
.dd-age { margin-top: var(--s4); font-size: 15px; font-weight: 600; padding: var(--s3) var(--s4); background: var(--paper); }
.dd-actions { display: flex; align-items: center; gap: var(--s4); margin-top: var(--s6); flex-wrap: wrap; }
.dd-actions .btn .ic { width: 16px; height: 16px; }
.dd-actions .btn { border: 1.5px solid var(--ink); }
.dd-actions .btn.is-on { background: var(--paper); color: var(--ink); }

/* ---------- saved tray ---------- */
.tray {
  margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(440px, 100vw); padding: 0; border: 0;
  background: var(--paper); color: var(--ink);
}
.tray::backdrop { background: color-mix(in oklch, var(--ink) 40%, transparent); }
.tray-in { min-height: 100%; display: flex; flex-direction: column; padding: var(--s3) var(--s5) var(--s5); }
.tray-top { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.tray-top h2 { font-family: var(--d); font-weight: 790; font-stretch: var(--wide); font-size: 30px; letter-spacing: -0.03em; }
.tray-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--joint); }
.tray-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 60px; border-bottom: 1px solid var(--joint); }
.tray-list button.name { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; font-weight: 650; font-size: 16px; }
.tray-list span { font-size: 13px; color: var(--ink-2); font-weight: 540; display: block; margin-top: 2px; }
.tray-empty { color: var(--ink-2); margin-top: var(--s5); }
.tray-actions { margin-top: auto; padding-top: var(--s5); }
.tray-actions .btn { width: 100%; }
.tray-note { margin-top: var(--s3); font-size: 13px; color: var(--ink-2); text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .dk { grid-template-columns: minmax(0, 1fr); padding-top: 88px; }
  .dk-side { position: static; }
  .dk-title { font-size: clamp(56px, 13vw, 96px); display: flex; gap: 0.25em; flex-wrap: wrap; }
  .dk-n, .dk-w { display: inline; }
  .dk-filters { margin-top: var(--s4); gap: var(--s4); }
  .dk-table { margin-top: var(--s5); }
  .dk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dd-body { grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
  .dd-window { position: relative; top: 0; height: min(66vw, 460px); margin: 0 calc(var(--gut) * -1); }
}
@media (max-width: 560px) {
  .dk-stage { height: min(132vw, 560px); }
  .dk-card { width: 100%; }
  .dk-controls { margin-top: calc(var(--s4) + 30px); } /* clear the fanned cards under the top one */
  .dk-card-name { font-size: 22px; }
  .dk-group .kit, .dk-group .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(var(--gut) * -1); padding: 0 var(--gut); scrollbar-width: none; }
  .dk-group .kit::-webkit-scrollbar, .dk-group .chips::-webkit-scrollbar { display: none; }
  .dk-group .kit > *, .dk-group .chips > * { flex: none; }
  .dk-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s2); }
  .dk-mini .t b { font-size: 14px; }
  .dd-spec { grid-template-columns: 1fr 1fr; }
  .dd-pair { grid-template-columns: 1fr; gap: var(--s4); }
}
