/* ── Page shell ── */
.ladder-page { display: grid; gap: var(--space-4); }

.ladder-hero  { padding: var(--space-7) var(--space-8); }
.ladder-stage,
.ladder-control { padding: var(--space-5); }

.ladder-hero .hero-note { margin-bottom: var(--space-4); }

.ladder-hero__title {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.3rem);
  letter-spacing: -0.04em;
  line-height: 1.2;
}
.ladder-hero__body {
  max-width: 600px;
  margin: var(--space-3) 0 0;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.ladder-layout { display: grid; gap: var(--space-5); }

.ladder-main,
.ladder-side { display: grid; gap: var(--space-5); }

/* ── Panel header ── */
.ladder-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.ladder-panel__eyebrow {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #0e8f73;
}
.ladder-panel__title {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

/* ── Board ── */
.ladder-board {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(23, 32, 51, 0.06);
  border-radius: calc(var(--radius-lg) - 4px);
  background:
    linear-gradient(180deg, rgba(223, 251, 244, 0.8), rgba(255, 255, 255, 0.9)),
    linear-gradient(135deg, var(--ladder-start), var(--ladder-end));
  min-height: 252px;
  padding: var(--space-4) var(--space-4) var(--space-4);
}

.ladder-board__overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.45), transparent 45%),
    linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0));
  pointer-events: none;
}

.ladder-board__top,
.ladder-board__bottom {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 10px;
}
.ladder-board__top    { margin-bottom: var(--space-4); }
.ladder-board__bottom { margin-top:    var(--space-4); }

/* ── Nodes ── */
.ladder-node {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid rgba(23, 32, 51, 0.08);
  font-weight: 700;
  line-height: 1.3;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 10px 20px rgba(23,32,51,0.06);
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
.ladder-node--player { color: #0f766e; }
.ladder-node--result { color: var(--text-primary); }

.ladder-node--clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(23,32,51,0.1);
}
.ladder-node--selected {
  border-color: rgba(16, 185, 129, 0.5);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.15), 0 14px 28px rgba(16,185,129,0.18);
}
.ladder-node--matched {
  background: rgba(236,253,245,0.96);
  border-color: rgba(16,185,129,0.3);
  animation: node-match-pop 420ms cubic-bezier(0.22,1,0.36,1) forwards;
}
.ladder-node--done {
  opacity: 0.52;
  background: rgba(255,255,255,0.6);
  cursor: default;
}

@keyframes node-match-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.14); }
  70%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ── SVG wrap ── */
.ladder-board__svg-wrap {
  position: relative;
  z-index: 1;
  min-height: 320px;
  isolation: isolate;
}
.ladder-board__svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Veil: frosted glass — 뒤의 페이크 경로가 흐릿하게 비쳐 보임 ── */
.ladder-board__veil {
  position: absolute;
  inset: 10px 0;
  border-radius: 22px;
  /* 반투명 + 블러로 뒤 SVG가 살짝 비쳐 보임 */
  background: rgba(228, 249, 241, 0.72);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  border: 1px solid rgba(255,255,255,0.62);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 400ms ease, transform 440ms ease, backdrop-filter 400ms ease;
}
.ladder-board__veil.is-open {
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
}

.ladder-board__veil-copy {
  position: relative;
  z-index: 2;
  padding: 18px 24px;
  border-radius: 20px;
  text-align: center;
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: 0 8px 24px rgba(15,118,110,0.08);
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.ladder-board__veil-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #0e8f73;
}
.ladder-board__veil-body {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── SVG strokes ── */
.ladder-line {
  stroke: rgba(23,32,51,0.2);
  stroke-width: 3.5;
  stroke-linecap: round;
}
.ladder-bridge {
  stroke: rgba(23,32,51,0.38);
  stroke-width: 3.5;
  stroke-linecap: round;
}
.ladder-path {
  fill: none;
  stroke: #10b981;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 6px 14px rgba(16,185,129,0.32));
}

/* ── Tracer ball ── */
.ladder-tracer {
  position: absolute;
  top: 0; left: 0;
  z-index: 4;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #dcfce7 42%, #10b981 72%, #0f766e 100%);
  box-shadow:
    0 0 0 5px rgba(16,185,129,0.18),
    0 0 0 10px rgba(16,185,129,0.07),
    0 10px 20px rgba(16,185,129,0.28);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: tracer-pulse 0.7s ease-in-out infinite alternate;
}
@keyframes tracer-pulse {
  from { box-shadow: 0 0 0 5px rgba(16,185,129,0.18), 0 0 0 10px rgba(16,185,129,0.07), 0 10px 20px rgba(16,185,129,0.28); }
  to   { box-shadow: 0 0 0 8px rgba(16,185,129,0.22), 0 0 0 16px rgba(16,185,129,0.09), 0 12px 28px rgba(16,185,129,0.38); }
}

/* ── Controls ── */
.ladder-inline-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── Horizontal inputs ── */
.ladder-control__group { margin-top: var(--space-4); }

.ladder-horiz-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: var(--space-2);
}
.ladder-horiz-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ladder-horiz-input-index {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #defaf1;
  color: #0f766e;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}
.ladder-horiz-input {
  width: 88px;
  height: 40px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(23,32,51,0.08);
  background: #ffffff;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text-primary);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.ladder-horiz-input:focus {
  outline: none;
  border-color: rgba(16,185,129,0.45);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
}

/* ── Match list ── */
.ladder-reveal-count {
  font-size: 0.8rem;
  font-weight: 800;
  color: #0e8f73;
  background: #defaf1;
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.ladder-match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.ladder-match-list__empty {
  padding: var(--space-4) 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

@keyframes match-slide-in {
  from { opacity: 0; transform: translateX(18px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}

.ladder-match-list__item {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 18px;
  border: 1px solid rgba(23,32,51,0.06);
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: match-slide-in 360ms cubic-bezier(0.22,1,0.36,1) both;
  box-shadow: 0 4px 14px rgba(16,185,129,0.08);
}
.ladder-match-player {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.ladder-match-arrow {
  color: #10b981;
  font-weight: 800;
  flex-shrink: 0;
}
.ladder-match-result {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-left: auto;
}

/* ── Presets ── */
.preset-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--space-4);
}

/* ── 비밀 다리 (반전 이벤트) ── */
@keyframes secret-bridge-appear {
  0%   { opacity: 0; stroke-width: 0;  filter: drop-shadow(0 0 0px rgba(245,158,11,0)); }
  25%  { opacity: 1; stroke-width: 14; filter: drop-shadow(0 0 16px rgba(245,158,11,0.9)); }
  60%  { stroke-width: 7; }
  100% { stroke-width: 7; filter: drop-shadow(0 0 8px rgba(245,158,11,0.55)); }
}

.ladder-secret-bridge {
  stroke: #f59e0b;
  stroke-linecap: round;
  animation: secret-bridge-appear 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* 반전 이후 경로: 주황/금색 */
.ladder-path--surprise {
  stroke: #f59e0b;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 6px 14px rgba(245,158,11,0.38));
}

/* 트레이서 반전 흔들림 */
@keyframes tracer-surprise-shake {
  0%, 100% { transform: translate(-50%, -50%) scale(1)    rotate(0deg); }
  20%       { transform: translate(-50%, -50%) scale(1.45) rotate(-8deg); }
  40%       { transform: translate(-50%, -50%) scale(0.8)  rotate(8deg); }
  60%       { transform: translate(-50%, -50%) scale(1.3)  rotate(-5deg); }
  80%       { transform: translate(-50%, -50%) scale(0.9)  rotate(4deg); }
}

.ladder-tracer.is-surprise {
  animation: tracer-surprise-shake 0.45s ease-in-out infinite;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #fef3c7 42%, #f59e0b 72%, #d97706 100%);
  box-shadow:
    0 0 0 5px  rgba(245,158,11,0.2),
    0 0 0 12px rgba(245,158,11,0.08),
    0 10px 20px rgba(245,158,11,0.35);
}

/* ── Result card: hidden (face-down) ── */
.ladder-node--hidden {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: rgba(255, 255, 255, 0.45);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255,255,255,0.06);
  cursor: default;
}

/* ── Result card: flip-in reveal ── */
@keyframes result-flip-in {
  0%   { transform: rotateY(-90deg) scale(0.78); opacity: 0; }
  55%  { transform: rotateY(14deg)  scale(1.1);  opacity: 1; }
  78%  { transform: rotateY(-5deg)  scale(0.97); }
  100% { transform: rotateY(0deg)   scale(1);    opacity: 1; }
}

.ladder-node--result.is-revealing {
  animation: result-flip-in 500ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  transform-style: preserve-3d;
  background: rgba(236, 253, 245, 0.98);
  border-color: rgba(16, 185, 129, 0.35);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18), 0 14px 32px rgba(16, 185, 129, 0.2);
}

/* ── Result card: swap flash (두 카드가 교환될 때) ── */
@keyframes result-swap-flash {
  0%   { transform: scale(1)    rotate(0deg);   filter: brightness(1); }
  18%  { transform: scale(1.22) rotate(-6deg);  filter: brightness(1.6) saturate(1.8); }
  40%  { transform: scale(0.82) rotate(5deg);   filter: brightness(0.8); }
  62%  { transform: scale(1.15) rotate(-3deg);  filter: brightness(1.4) saturate(1.5); }
  82%  { transform: scale(0.94) rotate(2deg);   filter: brightness(1); }
  100% { transform: scale(1)    rotate(0deg);   filter: brightness(1); }
}

.ladder-node--result.is-swapping {
  animation: result-swap-flash 420ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow:
    0 0 0 3px rgba(245, 158, 11, 0.22),
    0 0 24px rgba(245, 158, 11, 0.35);
  z-index: 10;
  position: relative;
}

/* ── Result card: swapped (교환 완료 — 앰버 하이라이트) ── */
@keyframes result-swapped-land {
  0%   { transform: scale(1.1); }
  55%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

.ladder-node--result.is-swapped {
  animation: result-swapped-land 360ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-color: rgba(245, 158, 11, 0.55);
  color: #92400e;
  box-shadow:
    0 0 0 3px rgba(245, 158, 11, 0.18),
    0 14px 28px rgba(245, 158, 11, 0.22);
}

/* ── Responsive ── */
@media (min-width: 1040px) {
  .ladder-layout {
    grid-template-columns: minmax(0, 1.04fr) minmax(340px, 0.76fr);
    align-items: start;
  }
}

@media (max-width: 560px) {
  .ladder-panel__header { align-items: flex-start; flex-direction: column; }
  .ladder-board { min-height: 420px; padding: var(--space-5) var(--space-3) var(--space-4); }
  .ladder-board__svg-wrap { min-height: 260px; }
  .ladder-node { min-height: 40px; padding-inline: 10px; font-size: 0.84rem; }
  .ladder-board__veil-copy { padding: 14px 18px; }
  .ladder-horiz-input { width: 76px; }
}
