/* Word Ladder - the puzzle is drawn as a real ladder: two rails, one rung per word, built downward to the goal. */
.ladder-card [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.ladder-card { --t: min(52px, calc((100vw - 136px) / 5)); --gap: 6px; padding: 14px 12px 18px; }
.ladder-meta { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 12px; font-size: .92rem; }
#par { font-weight: 800; color: var(--accent); letter-spacing: .02em; }
#count { color: var(--muted); font-variant-numeric: tabular-nums; }

.ladder { list-style: none; margin: 0; padding: 0; }
.rung { position: relative; display: flex; justify-content: center; align-items: center; padding: 7px 0; margin: 0 auto;
  width: max-content; min-width: 0; }
/* the rails: left and right borders of every rung line up into two continuous uprights */
.rung { border-left: 4px solid var(--line); border-right: 4px solid var(--line); padding-left: 14px; padding-right: 14px; }
/* the rung itself: a bar running behind the tiles from rail to rail */
.rung::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px;
  background: var(--line); border-radius: 2px; }
.rung-no { position: absolute; right: calc(100% + 10px); font-size: .72rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.word { position: relative; display: flex; gap: var(--gap); }

.tile { position: relative; display: grid; place-items: center; width: var(--t); height: var(--t); border-radius: 10px;
  background: var(--card); border: 2px solid var(--line); font: 800 calc(var(--t) * .5)/1 var(--font); color: var(--ink);
  letter-spacing: 0; }
.tile .mark { position: absolute; bottom: 1px; right: 4px; font-size: .62rem; line-height: 1; }
.tile.changed { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.start .tile { background: var(--tint); border-color: var(--tint); }
.tile.match { border-color: var(--good); color: var(--good); }

/* the input rung: native input laid invisibly over live tiles, so the phone keyboard opens on tap */
.rung-input { cursor: text; }
.rung-input input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0;
  font-size: 16px; /* >=16px stops iOS zooming */ caret-color: transparent; background: transparent; color: transparent; }
.tiles-live { position: relative; display: flex; gap: var(--gap); }
.tile.empty { border-style: dashed; background: transparent; }
.tile.typed { border-color: var(--ink); animation: pop .12s ease-out; }
.tile.diff { border-color: var(--accent); color: var(--accent); }
.rung-input:focus-within .tile.caret { border-color: var(--accent); border-style: solid; animation: blink 1s steps(2) infinite; }
.rung-input:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.target { margin-top: 6px; }
.goal .tile { border-width: 2px; border-style: solid; border-color: var(--ink); }
.goal .tile.match { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--card)); }
.goal.reached .tile { background: var(--good); border-color: var(--good); color: #fff; }
.goal .rung-no { color: var(--ink); font-weight: 700; }

.msg { min-height: 1.5em; text-align: center; margin: 12px 0 6px; font-weight: 600; font-size: .95rem; }
.msg.bad { color: var(--bad); }
.msg.good { color: var(--good); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.controls .btn { flex: 1 1 auto; min-width: 88px; max-width: 200px; }
.controls #add { flex-basis: 100%; max-width: 280px; }

/* rung-by-rung build + feedback */
.rung.new .word { animation: rung-in .32s cubic-bezier(.2, .9, .3, 1.3); }
.rung.new .tile.changed { animation: flip .42s ease-out .08s backwards; }
.shake { animation: shake .32s ease-in-out; }
.ladder-card.solved .goal.reached .tile { animation: climb .5s ease-out backwards; }
.ladder-card.solved .goal.reached .tile:nth-child(2) { animation-delay: .06s; }
.ladder-card.solved .goal.reached .tile:nth-child(3) { animation-delay: .12s; }
.ladder-card.solved .goal.reached .tile:nth-child(4) { animation-delay: .18s; }
.ladder-card.solved .goal.reached .tile:nth-child(5) { animation-delay: .24s; }
@keyframes rung-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes flip { from { transform: rotateX(90deg); } to { transform: none; } }
@keyframes pop { from { transform: scale(.88); } to { transform: none; } }
@keyframes blink { 50% { border-color: var(--line); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes climb { from { transform: translateY(8px); opacity: .3; } to { transform: none; opacity: 1; } }

.reveal { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 4px; }
.reveal h2 { text-align: center; margin: 14px 0 8px; font-size: 1rem; color: var(--muted); }
.ladder.mini { --t: min(36px, calc((100vw - 136px) / 5)); }
.ladder.mini .rung { padding-top: 4px; padding-bottom: 4px; }

.result { margin-top: 16px; }
.result .big { margin: 4px 0 0; }
.result .actions { margin: 6px 0; }
.result .links { font-size: .92rem; margin: 10px 0 0; }

/* archive */
.archive-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.archive-list a { display: flex; justify-content: space-between; align-items: center; min-height: 48px; padding: 10px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.archive-list a:hover { border-color: var(--accent); }
.archive-list .muted { font-size: .88rem; }

@media (min-width: 520px) { .ladder-card { padding: 18px 20px 22px; } }
@media (max-width: 400px) { .rung-no { display: none; } }
