/* Kindred: word-grouping puzzle. Scoped to .kd. */
.kd { --t1: #ffd166; --t2: #2ec27e; --t3: #55d6ff; --t4: #9b8cff; --t1i: #1d1500; --t2i: #02190d; --t3i: #031520; --t4i: #0d0830;
  --m1: #ff6b81; --m2: #ffb347; --m3: #5ee6a8; --m4: #d0b4ff;
  --tile: #18233f; --tile-hi: #1f2c4d; --line: #1c2b4a; --muted: #8aa3c4; --text: #dfe9ff; --tile-h: 66px;
  position: relative; max-width: 600px; margin: 0 auto; padding: 6px 0 14px; color: var(--text);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.kd [hidden] { display: none !important; }
.kd.hc { --t1: #ffe14d; --t2: #00d97e; --t3: #3fb6ff; --t4: #b388ff; --t1i: #000; --t2i: #000; --t3i: #000; --t4i: #000; --tile: #121c34; }
.kd.hc .kd-tile { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.28); }
.kd.hc .kd-bar, .kd.hc .kd-ex { box-shadow: inset 0 0 0 2px rgba(0,0,0,0.55); }
.kd button { font-family: inherit; line-height: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.kd .kd-tile { touch-action: none; }   /* drag to arrange without scrolling the page */
.kd :focus-visible { outline: 2px solid var(--t3); outline-offset: 2px; }
.kd-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */
.kd-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kd-modes { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: #0b1328; border: 1px solid var(--line); }
.kd-mode { border: 0; background: transparent; color: var(--muted); font-weight: 650; font-size: 13.5px; padding: 7px 14px; border-radius: 999px; cursor: pointer; transition: background-color .2s, color .2s; min-height: 34px; }
.kd-mode:hover { color: #fff; }
.kd-mode.is-on { background: #e8edf2; color: #0b1328; }
.kd-tools { display: flex; gap: 4px; }
.kd-ibtn { position: relative; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; color: #c9d7ef; cursor: pointer; transition: background-color .2s, color .2s; }
.kd-ibtn:hover:not(:disabled) { background: rgba(255,255,255,0.07); color: #fff; }
.kd-ibtn:disabled { opacity: 0.35; cursor: default; }
.kd-ibtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kd-hintbtn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px 0 10px; border-radius: 999px; border: 1px solid rgba(255,209,102,0.35); background: rgba(255,209,102,0.07); color: var(--t1); font-size: 13px; font-weight: 700; cursor: pointer; transition: background-color .15s, border-color .15s, opacity .15s; }
@media (hover: hover) { .kd-hintbtn:hover:not(:disabled) { background: rgba(255,209,102,0.14); border-color: rgba(255,209,102,0.6); } }
.kd-hintbtn:disabled { opacity: 0.35; cursor: default; }
.kd-hintbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.kd-hintcount { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--t1); color: #1a1200; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.kd-hintcount:empty { display: none; }
.kd-meta { display: flex; align-items: center; gap: 10px; min-height: 30px; margin: 8px 2px 10px; font-size: 13.5px; color: var(--muted); flex-wrap: wrap; }
.kd-meta-main b { color: #fff; font-weight: 700; }
.kd-level { display: inline-flex; gap: 3px; } .kd-level i { width: 6px; height: 6px; border-radius: 50%; background: #2b3a5c; } .kd-level i.on { background: var(--t1); }
.kd-chip { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--t3); border: 1px solid rgba(85,214,255,0.35); padding: 2px 8px; border-radius: 999px; }
.kd-link { border: 0; background: transparent; color: var(--t3); font-weight: 650; font-size: 13.5px; cursor: pointer; padding: 6px 4px; margin-left: auto; border-radius: 6px; }
.kd-link:hover { text-decoration: underline; }
.kd-back { margin-left: -4px; margin-right: 2px; }

/* ---------- board ---------- */
.kd-play { display: flex; flex-direction: column; }
.kd-boardwrap { position: relative; display: flex; flex-direction: column; }
.kd-hints { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.kd-hintchip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); background: #0b1328; border: 1px solid var(--line); border-left: 4px solid var(--c, var(--t1)); border-radius: 8px; padding: 6px 10px; }
.kd-hintchip.t1 { --c: var(--t1); } .kd-hintchip.t2 { --c: var(--t2); } .kd-hintchip.t3 { --c: var(--t3); } .kd-hintchip.t4 { --c: var(--t4); }
.kd-hintchip i { font-style: normal; }
.kd-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: var(--tile-h); gap: 8px; position: relative; }
.kd-board > * { min-width: 0; }
.kd-tile { position: relative; height: 100%; border: 0; border-radius: 12px; background: var(--tile); color: #fff; cursor: pointer; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; text-align: center; touch-action: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 1px 2px rgba(0,0,0,0.3);
  transition: background-color .16s ease, color .16s ease, transform .16s cubic-bezier(.2,.8,.2,1), box-shadow .16s ease; }
.kd-word { display: block; max-width: 100%; font-weight: 800; font-size: 15px; letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap; line-height: 1.1; pointer-events: none; }
.kd-word.two { white-space: normal; }
@media (hover: hover) { .kd-tile:hover { background: var(--tile-hi); } }
.kd-tile.press { transform: scale(0.96); }
.kd-tile.sel { background: #e8edf2; color: #0b1328; box-shadow: 0 2px 10px rgba(0,0,0,0.35); }
.kd-tile.sel:hover { background: #fff; }
/* markers: coloured ring + symbol, so they read without colour too */
.kd-tile.m1 { box-shadow: inset 0 0 0 2.5px var(--m1); } .kd-tile.m2 { box-shadow: inset 0 0 0 2.5px var(--m2); }
.kd-tile.m3 { box-shadow: inset 0 0 0 2.5px var(--m3); } .kd-tile.m4 { box-shadow: inset 0 0 0 2.5px var(--m4); }
.kd-mark { position: absolute; top: 4px; left: 6px; font-size: 11px; line-height: 1; pointer-events: none; }
.kd-tile.m1 .kd-mark { color: var(--m1); } .kd-tile.m2 .kd-mark { color: var(--m2); } .kd-tile.m3 .kd-mark { color: var(--m3); } .kd-tile.m4 .kd-mark { color: var(--m4); }
.kd-tile.sel.m1 .kd-mark, .kd-tile.sel.m2 .kd-mark, .kd-tile.sel.m3 .kd-mark, .kd-tile.sel.m4 .kd-mark { filter: brightness(0.75) saturate(1.4); }
.kd-pin { position: absolute; top: 3px; right: 6px; font-size: 12px; line-height: 1; color: var(--c); pointer-events: none; }
.kd-tile.pin.t1 { --c: var(--t1); } .kd-tile.pin.t2 { --c: var(--t2); } .kd-tile.pin.t3 { --c: var(--t3); } .kd-tile.pin.t4 { --c: var(--t4); }
.kd-tile.pin::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 5px; height: 3px; border-radius: 2px; background: var(--c); opacity: 0.9; }
.kd-tile.marked { animation: kd-mark .3s ease; }
.kd-tile.lift { z-index: 5; box-shadow: 0 14px 30px rgba(0,0,0,0.55); transition: none; cursor: grabbing; }
.kd-tile.target { background: var(--tile-hi); box-shadow: inset 0 0 0 2px rgba(85,214,255,0.7); }
.kd.dragging, .kd.dragging * { cursor: grabbing; }
.kd-tile.hop { animation: kd-hop .32s ease; }
.kd-tile.shake { animation: kd-shake .42s ease; }
.kd-tile.deal { animation: kd-deal .34s cubic-bezier(.2,.8,.2,1) both; }
.kd.marking .kd-tile { cursor: cell; }

.kd-bar { grid-column: 1 / -1; height: 100%; border: 0; border-radius: 12px; padding: 4px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; text-align: center; overflow: hidden; }
.kd-bar.t1 { background: var(--t1); color: var(--t1i); } .kd-bar.t2 { background: var(--t2); color: var(--t2i); }
.kd-bar.t3 { background: var(--t3); color: var(--t3i); } .kd-bar.t4 { background: var(--t4); color: var(--t4i); }
.kd-bar.is-new { animation: kd-bar .42s cubic-bezier(.2,.9,.3,1.15); }
.kd-bar-tier { font-size: 9.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.6; }
.kd-bar-name { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; line-height: 1.15; }
.kd-bar-words { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.kd-bar:hover { filter: brightness(1.04); }
.kd-bar.rev { opacity: 0.78; }

.kd-toast { position: absolute; left: 50%; top: 10px; transform: translate(-50%, -6px); background: #f4f7fb; color: #0b1328; font-weight: 750; font-size: 14px; padding: 9px 16px; border-radius: 999px; pointer-events: none; opacity: 0; z-index: 6; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.kd-toast.show { animation: kd-toast 1.6s ease forwards; }

/* ---------- controls ---------- */
.kd-controls { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }
.kd-status { min-height: 34px; display: flex; justify-content: center; align-items: center; gap: 18px; flex-wrap: wrap; }
.kd-lives { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.kd-lives-label { margin-right: 4px; }
.kd-lives i { width: 11px; height: 11px; border-radius: 50%; background: #c9d7ef; transition: background-color .3s, transform .3s; }
.kd-lives i.off { background: #253454; transform: scale(0.8); }
.kd-relaxed { color: var(--t3); font-weight: 600; }
.kd-marks { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.kd-marks-label { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700; margin-right: 2px; }
.kd-mk { display: inline-flex; align-items: center; gap: 5px; min-width: 50px; height: 36px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: #0b1328; color: var(--muted); cursor: pointer; transition: background-color .15s, border-color .15s, color .15s; }
.kd-mk i { font-style: normal; font-size: 13px; }
.kd-mk b { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kd-mk[data-m="1"] i { color: var(--m1); } .kd-mk[data-m="2"] i { color: var(--m2); } .kd-mk[data-m="3"] i { color: var(--m3); } .kd-mk[data-m="4"] i { color: var(--m4); }
.kd-mk[data-m="1"] { --c: var(--m1); } .kd-mk[data-m="2"] { --c: var(--m2); } .kd-mk[data-m="3"] { --c: var(--m3); } .kd-mk[data-m="4"] { --c: var(--m4); }
.kd-mk[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, #0b1328); color: #fff; }
.kd-mk.full b { color: #fff; } .kd-mk.over b { color: var(--m1); }
@media (hover: hover) { .kd-mk:hover { border-color: var(--c); } }
.kd-mk-clear { height: 36px; padding: 0 12px; border-radius: 999px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.kd-mk-clear:disabled { opacity: 0.35; cursor: default; }
.kd-actions { display: flex; justify-content: center; gap: 8px; width: 100%; }
.kd-btn { min-height: 46px; min-width: 104px; padding: 0 20px; border-radius: 999px; border: 1px solid #2a3b5f; background: transparent; color: var(--text); font-weight: 700; font-size: 14.5px; cursor: pointer; transition: background-color .15s, border-color .15s, color .15s, transform .12s, opacity .15s; }
@media (hover: hover) { .kd-btn:hover:not(:disabled) { border-color: #5b7099; background: rgba(255,255,255,0.03); } }
.kd-btn:active:not(:disabled) { transform: scale(0.97); }
.kd-btn:disabled { opacity: 0.4; cursor: default; }
.kd-btn-primary { background: #e8edf2; color: #0b1328; border-color: #e8edf2; }
@media (hover: hover) { .kd-btn-primary:hover:not(:disabled) { background: #fff; border-color: #fff; } }
.kd-btn-primary:disabled { background: transparent; color: var(--text); border-color: #2a3b5f; }
.kd-btn.nudge { animation: kd-nudge .35s ease; }

/* ---------- archive ---------- */
.kd-archive { padding: 0 0 6px; }
.kd-archive > .kd-h4:first-child { margin-top: 6px; }
.kd-arch { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.kd-day { text-align: left; display: grid; gap: 3px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #0b1328; color: var(--text); cursor: pointer; transition: border-color .15s, transform .15s; }
@media (hover: hover) { .kd-day:hover { border-color: #3d5a7a; transform: translateY(-1px); } }
.kd-day-n { font-weight: 750; font-size: 14.5px; color: #fff; }
.kd-day-d { font-size: 12.5px; color: var(--muted); }
.kd-day-s { font-size: 12.5px; color: var(--muted); display: flex; gap: 5px; align-items: center; }
.kd-day-s i { font-style: normal; }
.kd-day.perfect .kd-day-s, .kd-day.solved .kd-day-s { color: var(--t2); }
.kd-day.perfect .kd-day-s i { color: var(--t1); }
.kd-day.lost .kd-day-s { color: var(--m1); }
.kd-day.wip .kd-day-s { color: var(--t3); }
.kd-day .kd-level { margin-top: 3px; }

/* ---------- sheets ---------- */
.kd-scrim { position: fixed; inset: 0; z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(2,4,10,0.62); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: kd-fade .2s ease; }
.kd-scrim.out { animation: kd-fade .18s ease reverse forwards; }
.kd-sheet { position: relative; width: 100%; max-width: 460px; max-height: min(86vh, 760px); overflow: auto; overscroll-behavior: contain; background: #0d1630; border: 1px solid #22345a; border-radius: 20px; padding: 22px 22px 20px; box-shadow: 0 30px 80px rgba(0,0,0,0.6); color: var(--text); animation: kd-sheet .28s cubic-bezier(.2,.8,.2,1); user-select: text; -webkit-user-select: text; }
.kd-scrim.out .kd-sheet { animation: kd-sheet .18s ease reverse forwards; }
.kd-sheet:focus { outline: none; }
.kd-x { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.08); color: #c9d7ef; font-size: 20px; line-height: 1; cursor: pointer; }
.kd-x:hover { background: rgba(255,255,255,0.14); color: #fff; }
.kd-sheet-title { margin: 0 40px 4px 0; font-size: 22px; font-weight: 800; color: #fff; letter-spacing: -0.01em; }
.kd-sub { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.kd-h4 { margin: 20px 0 10px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kd-fine { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 14px 0 0; }
.kd-sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.kd-sheet-actions .kd-btn { flex: 1 1 0; min-width: 0; }
.kd-sheet-actions .kd-btn-primary { flex-basis: 100%; }
.kd-res-top { display: flex; gap: 16px; align-items: center; }
.kd-score { position: relative; width: 76px; height: 76px; flex: none; }
.kd-score svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.kd-score circle { fill: none; stroke-width: 4; stroke-linecap: round; }
.kd-score .trk { stroke: #1f2c4d; } .kd-score .val { stroke: var(--t1); animation: kd-ring 1s cubic-bezier(.2,.8,.2,1); }
.kd-score.lost .val { stroke: var(--muted); }
.kd-score b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 24px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.kd-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.kd-badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,0.08); color: #fff; }
.kd-badge.t4 { background: color-mix(in srgb, var(--t4) 25%, transparent); }
.kd-res-grid { display: grid; gap: 4px; justify-content: center; margin: 18px 0 0; }
.kd-res-grid div { display: flex; gap: 4px; }
.kd-res-grid i { width: 22px; height: 22px; border-radius: 5px; }
.kd-res-grid i.t1, .kd-tl.t1 { background: var(--t1); } .kd-res-grid i.t2 { background: var(--t2); } .kd-res-grid i.t3 { background: var(--t3); } .kd-res-grid i.t4, .kd-tl.t4 { background: var(--t4); }
.kd-copy { width: 100%; margin-top: 10px; border-radius: 10px; border: 1px solid var(--line); background: #060b18; color: var(--text); padding: 10px; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; resize: none; }
.kd-next { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.kd-next b { color: #fff; font-variant-numeric: tabular-nums; }
.kd-ex { border-radius: 14px; padding: 12px 14px; margin: 0 0 8px; background: #0a1226; border: 1px solid var(--line); border-left: 5px solid var(--c); }
.kd-ex.t1 { --c: var(--t1); } .kd-ex.t2 { --c: var(--t2); } .kd-ex.t3 { --c: var(--t3); } .kd-ex.t4 { --c: var(--t4); }
.kd-ex.solo { margin-top: 12px; }
.kd-ex-head { display: flex; flex-direction: column; gap: 2px; }
.kd-ex-head b { font-size: 15.5px; color: #fff; }
.kd-ex-tier { font-size: 10.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--c); }
.kd-ex-words { margin: 6px 0 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: #c9d7ef; }
.kd-notes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.kd-notes li { font-size: 13px; color: var(--muted); }
.kd-notes li b { color: #fff; text-transform: uppercase; font-size: 12.5px; letter-spacing: 0.03em; margin-right: 4px; }
.kd-ex-why { margin: 8px 0 0; font-size: 13.5px; color: var(--text); line-height: 1.45; }
.kd-herrings { font-size: 13.5px; color: var(--muted); line-height: 1.5; margin: 10px 0 0; }
.kd-herrings b { color: #fff; }
.kd-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; margin-top: 14px; text-align: center; }
.kd-stats div { display: flex; flex-direction: column; gap: 2px; }
.kd-stats b { font-size: 24px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.kd-stats span { font-size: 11.5px; color: var(--muted); }
.kd-dist { display: grid; gap: 6px; }
.kd-dist-row { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.kd-dist-bar { width: var(--w); min-width: 22px; height: 22px; border-radius: 6px; background: var(--t2); display: flex; justify-content: flex-end; align-items: center; padding: 0 7px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.kd-dist-bar.lost { background: #3a4767; }
.kd-dist-bar.zero { background: #1c2b4a; } .kd-dist-bar.zero b { color: var(--muted); }
.kd-dist-bar b { font-size: 12px; color: #02190d; } .kd-dist-bar.lost b { color: #fff; }
.kd-help { margin: 14px 0 0; padding-left: 18px; display: grid; gap: 9px; }
.kd-help li { font-size: 14px; line-height: 1.5; color: var(--text); }
.kd-tl { display: inline-block; padding: 0 6px; border-radius: 5px; color: #0b1328; font-weight: 700; font-size: 12.5px; }
.kd-demo { margin: 16px 0 4px; display: grid; gap: 6px; }
.kd-demo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kd-demo-row span { background: #e8edf2; color: #0b1328; border-radius: 9px; height: 38px; display: grid; place-items: center; font-size: 12.5px; font-weight: 800; letter-spacing: 0.03em; }
.kd-demo-bar { border-radius: 9px; height: 42px; background: var(--t1); color: var(--t1i); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; font-size: 13.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.kd-demo-bar small { font-size: 9px; letter-spacing: 0.12em; opacity: 0.6; }
.kd-set { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.kd-set span { display: grid; gap: 3px; } .kd-set b { font-size: 15px; color: #fff; } .kd-set small { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.kd-set input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kd-sw { flex: none; width: 46px; height: 28px; border-radius: 14px; background: #2b3448; position: relative; transition: background-color .2s; }
.kd-sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s cubic-bezier(.2,.8,.2,1); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.kd-set input:checked + .kd-sw { background: #2ec27e; } .kd-set input:checked + .kd-sw::after { transform: translateX(18px); }
.kd-set input:focus-visible + .kd-sw { outline: 2px solid var(--t3); outline-offset: 2px; }

/* ---------- animation ---------- */
@keyframes kd-hop { 40% { transform: translateY(-6px); } }
@keyframes kd-shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes kd-deal { from { opacity: 0; transform: scale(0.9) translateY(6px); } }
@keyframes kd-bar { from { transform: scale(0.94); opacity: 0.4; } }
@keyframes kd-mark { 50% { transform: scale(1.06); } }
@keyframes kd-toast { 0% { opacity: 0; transform: translate(-50%, -6px); } 12%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -4px); } }
@keyframes kd-nudge { 30% { transform: scale(1.06); } }
@keyframes kd-fade { from { opacity: 0; } }
@keyframes kd-sheet { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
@keyframes kd-ring { from { stroke-dasharray: 0 200; } }
@media (prefers-reduced-motion: reduce) { .kd *, .kd-scrim, .kd-sheet { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .kd { --tile-h: 60px; padding-top: 2px; }
  .kd-board { gap: 6px; }
  .kd-word { font-size: 13.5px; letter-spacing: 0.01em; }
  .kd-bar-name { font-size: 14px; } .kd-bar-words { font-size: 12px; }
  .kd-mode { padding: 7px 9px; font-size: 13px; }
  .kd-tools { gap: 0; }
  .kd-ibtn { width: 38px; height: 38px; }
  .kd-ibtn svg { width: 20px; height: 20px; }
  .kd-scrim { align-items: flex-end; padding: 0; }
  .kd-sheet { max-width: none; border-radius: 22px 22px 0 0; max-height: 88vh; padding: 20px 18px calc(18px + env(safe-area-inset-bottom, 0px)); animation-name: kd-up; border-bottom: 0; }
  .kd-scrim.out .kd-sheet { animation-name: kd-up; }
  .kd-btn { min-width: 0; flex: 1 1 0; padding: 0 12px; }
  .kd-actions { max-width: 420px; }
  .kd-notes { grid-template-columns: 1fr; }
}
@keyframes kd-up { from { transform: translateY(100%); } }
@media (max-width: 360px) {
  .kd-mode { padding: 7px 7px; font-size: 12px; }
  .kd-modes { gap: 0; }
  .kd-ibtn { width: 32px; height: 38px; }
  .kd-lives-label { display: none; }
  .kd-ibtn svg { width: 19px; height: 19px; }
  .kd-head { gap: 4px; }
  .kd-word { font-size: 12.5px; }
  .kd-mk { min-width: 44px; padding: 0 8px; }
  .kd-marks-label { display: none; }
  .kd-stats { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- full screen: fill the height, controls pinned to the bottom ---------- */
.stage.is-immersive .kd { display: flex; flex-direction: column; width: 100%; max-width: 640px; height: 100%; margin: 0 auto; padding: 10px 4px 10px; }
.stage.is-immersive .kd > * { flex-shrink: 0; }
/* puzzle line + board + status + markers + buttons form one group, centred in the space under the tabs */
.stage.is-immersive .kd-meta { margin-top: auto; }
.stage.is-immersive .kd-play { flex: 0 1 auto; min-height: 0; flex-shrink: 1; justify-content: center; margin-bottom: auto; }
.stage.is-immersive .kd-boardwrap { flex: none; container-type: inline-size; }
/* rows follow the tile width (about 0.62 of it), so tiles and solved bars keep a sensible shape */
.stage.is-immersive .kd-board { grid-auto-rows: clamp(46px, calc((100cqw - 18px) / 4 * 0.62), 92px); }
@media (max-width: 699px) and (orientation: portrait) { .stage.is-immersive .kd-board { grid-auto-rows: clamp(46px, calc((100cqw - 18px) / 4 * 0.82), 92px); } }   /* phones: a touch taller, easier to hit */
@media (min-width: 700px) and (min-height: 760px) { .stage.is-immersive .kd-board { grid-auto-rows: clamp(46px, calc((100cqw - 24px) / 4 * 0.62), 110px); } }
.stage.is-immersive .kd-controls { flex: none; margin-top: 12px; }
.stage.is-immersive .kd-archive { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
@media (orientation: landscape) and (max-height: 540px) {
  .stage.is-immersive .kd { max-width: 980px; padding: 6px 8px; }
  .stage.is-immersive .kd-meta { margin: 4px 2px 6px; min-height: 24px; }
  .stage.is-immersive .kd-play { flex-direction: row; gap: 18px; align-items: stretch; }
  .stage.is-immersive .kd-play { flex: 1 1 auto; justify-content: stretch; margin-bottom: 0; }
  .stage.is-immersive .kd-boardwrap { flex: 1 1 auto; min-height: 0; container-type: normal; justify-content: center; }
  .stage.is-immersive .kd-board { flex: 1 1 auto; max-height: 300px; gap: 6px; grid-auto-rows: auto; grid-template-rows: repeat(4, minmax(0, 1fr)); }
  .stage.is-immersive .kd-hints { margin-bottom: 6px; }
  .stage.is-immersive .kd-hintchip { padding: 4px 10px; }
  .stage.is-immersive .kd-marks-label { display: none; }
  .stage.is-immersive .kd-bar { gap: 0; padding: 2px 10px; }
  .stage.is-immersive .kd-bar-tier { display: none; }
  .stage.is-immersive .kd-controls { width: 270px; margin-top: 0; justify-content: center; gap: 12px; }
  .stage.is-immersive .kd-actions { flex-wrap: wrap; }
  .stage.is-immersive .kd-actions .kd-btn { min-height: 42px; }
  .stage.is-immersive .kd-actions .kd-btn-primary { flex-basis: 100%; }
}
