/* ============================================================
   깨알도구
   사다리타기

   공통 디자인은 tool-common.css 사용
   사다리 전용 UI만 정의
   ============================================================ */

.ladder-page {
  --tool-page-max-width: 960px;
}

/* ============================================================
   TEXTAREA
   ============================================================ */

.ladder-textarea {
  display: block;

  width: 100%;
  min-height: 138px;

  padding: 12px 13px;

  resize: vertical;

  border: 1px solid var(--line);
  border-radius: var(--tool-input-radius);

  background: #ffffff;

  color: var(--text);

  outline: none;

  font-family: inherit;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.7;

  box-sizing: border-box;

  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.ladder-textarea:focus {
  border-color: var(--accent);

  box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.1);
}

.ladder-textarea:disabled {
  opacity: 0.65;

  background: var(--surface-soft);

  cursor: not-allowed;
}

/* ============================================================
   COUNT SUMMARY
   ============================================================ */

.ladder-count-summary {
  margin-top: 12px;

  padding: 10px 11px;

  border-radius: 9px;

  background: var(--surface-soft);

  color: var(--text-soft);

  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;

  text-align: center;
}

.ladder-count-summary.is-ready {
  background: #eef9f2;

  color: #34714a;
}

.ladder-count-summary.is-error {
  background: #fff1ed;

  color: #a24b3b;
}

/* ============================================================
   RESULT PANEL
   ============================================================ */

.ladder-result-panel {
  min-height: 0;

  justify-content: flex-start;
}

/* ============================================================
   STATUS
   ============================================================ */

.ladder-status {
  width: 100%;

  min-height: 35px;

  display: flex;

  align-items: center;
  justify-content: center;

  margin-bottom: 9px;

  padding: 7px 10px;

  border-radius: 9px;

  background: var(--surface-soft);

  color: var(--text-soft);

  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;

  text-align: center;

  box-sizing: border-box;
}

.ladder-status.is-error {
  background: #fff1ed;

  color: #a24b3b;
}

.ladder-status.is-success {
  background: #eef9f2;

  color: #34714a;
}

/* ============================================================
   LADDER STAGE
   ============================================================ */

.ladder-stage {
  position: relative;

  width: 100%;

  overflow: hidden;

  border: 1px solid var(--line);
  border-radius: 13px;

  background: linear-gradient(180deg, #ffffff 0%, #fbfaf6 100%);
}

/* ============================================================
   CANVAS
   ============================================================ */

#ladderCanvas {
  display: block;

  width: 100%;
  height: auto;

  aspect-ratio: 900 / 620;

  touch-action: none;

  user-select: none;
  -webkit-user-select: none;
}

/* ============================================================
   PARTICIPANT PICK
   ============================================================ */

.ladder-pick-wrap {
  margin-top: 12px;
}

.ladder-pick-wrap[hidden] {
  display: none;
}

.ladder-pick-title {
  margin-bottom: 7px;

  color: var(--text);

  font-size: 12px;
  font-weight: 800;

  text-align: center;
}

.ladder-pick-list {
  display: grid;

  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));

  gap: 6px;
}

.ladder-pick-button {
  min-width: 0;

  min-height: 38px;

  padding: 6px 8px;

  border: 1px solid var(--line);
  border-radius: 9px;

  background: #ffffff;

  color: var(--text);

  font-family: inherit;
  font-size: 12px;
  font-weight: 800;

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  cursor: pointer;

  transition:
    transform 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease;
}

.ladder-pick-button:hover:not(:disabled) {
  transform: translateY(-1px);

  border-color: var(--accent);

  background: #fffaf0;
}

.ladder-pick-button.is-done {
  border-color: #cfe8d7;

  background: #eff9f2;

  color: #34714a;
}

.ladder-pick-button.is-active {
  border-color: var(--brand);

  background: var(--brand);

  color: #ffffff;
}

.ladder-pick-button:disabled {
  cursor: default;
}

/* ============================================================
   CURRENT RESULT
   ============================================================ */

.ladder-current-result {
  margin-top: 12px;

  padding: 12px;

  border-radius: 11px;

  background: #171d2b;

  color: #ffffff;

  text-align: center;

  animation: ladder-result-pop 0.28s ease;
}

.ladder-current-result[hidden] {
  display: none;
}

.ladder-current-result span {
  display: block;

  color: rgba(255, 255, 255, 0.6);

  font-size: 12px;
  font-weight: 800;
}

.ladder-current-result strong {
  display: block;

  margin-top: 4px;

  font-size: 13px;
  font-weight: 900;
}

.ladder-current-result b {
  display: block;

  margin: 2px 0;

  color: #ffd978;

  font-size: 14px;
}

.ladder-current-result em {
  display: block;

  color: #ffd978;

  font-style: normal;
  font-size: 16px;
  font-weight: 900;

  overflow-wrap: anywhere;
}

@keyframes ladder-result-pop {
  from {
    opacity: 0;

    transform: scale(0.96);
  }

  to {
    opacity: 1;

    transform: scale(1);
  }
}

/* ============================================================
   ACTIONS
   ============================================================ */

.ladder-actions {
  display: grid;

  grid-template-columns: repeat(2, minmax(0, 1fr));

  gap: 7px;

  width: 100%;

  margin-top: 12px;
}

.ladder-actions .tool-result-action {
  width: 100%;
}

/* ============================================================
   HISTORY
   ============================================================ */

.ladder-history {
  width: 100%;

  margin-top: 13px;

  padding-top: 13px;

  border-top: 1px solid var(--line);
}

.ladder-history[hidden] {
  display: none;
}

.ladder-history-head {
  display: flex;

  align-items: center;
  justify-content: space-between;

  gap: 10px;

  margin-bottom: 7px;
}

.ladder-history-head strong {
  color: var(--text);

  font-size: 12px;
  font-weight: 850;
}

.ladder-history-head button {
  padding: 5px 8px;

  border: 1px solid var(--line);
  border-radius: 7px;

  background: #ffffff;

  color: var(--text-soft);

  font-family: inherit;
  font-size: 12px;
  font-weight: 800;

  cursor: pointer;
}

.ladder-history-head button:hover {
  background: var(--surface-soft);
}

.ladder-history-list {
  display: grid;

  gap: 5px;
}

.ladder-history-item {
  display: grid;

  grid-template-columns:
    24px
    minmax(0, 1fr)
    20px
    minmax(0, 1fr);

  align-items: center;

  gap: 6px;

  padding: 8px 9px;

  border-radius: 8px;

  background: var(--surface-soft);

  animation: ladder-row-in 0.25s ease both;
}

.ladder-history-number {
  width: 22px;
  height: 22px;

  display: flex;

  align-items: center;
  justify-content: center;

  border-radius: 50%;

  background: #ffffff;

  color: var(--text-soft);

  font-size: 12px;
  font-weight: 900;
}

.ladder-history-person,
.ladder-history-result {
  min-width: 0;

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

  color: var(--text);

  font-size: 12px;
  font-weight: 800;
}

.ladder-history-result {
  color: var(--brand);
}

.ladder-history-arrow {
  color: var(--text-soft);

  font-size: 12px;

  text-align: center;
}

@keyframes ladder-row-in {
  from {
    opacity: 0;

    transform: translateY(4px);
  }

  to {
    opacity: 1;

    transform: translateY(0);
  }
}

/* ============================================================
   CONFETTI
   ============================================================ */

.ladder-confetti {
  position: absolute;

  inset: 0;

  overflow: hidden;

  pointer-events: none;
}

.ladder-confetti i {
  position: absolute;

  top: -20px;

  border-radius: 2px;

  animation: ladder-confetti-fall 1.3s ease-in forwards;
}

@keyframes ladder-confetti-fall {
  0% {
    opacity: 1;

    transform: translateY(-20px) rotate(0deg);
  }

  100% {
    opacity: 0;

    transform: translateY(600px) rotate(560deg);
  }
}

/* ============================================================
   TABLET
   ============================================================ */

@media (max-width: 760px) {
  .ladder-result-panel {
    order: -1;
  }
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 520px) {
  .ladder-textarea {
    min-height: 115px;

    font-size: 12px;
  }

  .ladder-pick-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ladder-actions {
    grid-template-columns: 1fr;
  }

  .ladder-history-item {
    grid-template-columns:
      21px
      minmax(0, 1fr)
      14px
      minmax(0, 1fr);

    gap: 4px;

    padding: 7px 6px;
  }

  .ladder-history-person,
  .ladder-history-result {
    font-size: 12px;
  }
}
