:root {
  --bg: #0b1021;
  --surface: #11172c;
  --card: #161d33;
  --primary: #6d9dfc;
  --primary-2: #8f7bff;
  --accent: #3dd6ff;
  --text: #e8ecf5;
  --muted: #9aa6c4;
  --shadow: 0 10px 30px rgba(0,0,0,0.25);
  --success: #4ade80;
  --error: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0; padding: 0;
  font-family: 'Inter', 'Noto Sans KR', Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, #142042 0%, #0b1021 45%, #080a16 100%);
  color: var(--text);
  min-height: 100vh;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 22px 80px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  margin-bottom: 14px;
  background: rgba(12, 17, 36, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.nav-pill:hover,
.nav-pill:focus-visible {
  background: rgba(109,157,252,0.14);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.hero {
  background: linear-gradient(135deg, #6d9dfc, #8f7bff, #3dd6ff);
  color: #0b1021;
  padding: 26px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  text-align: center;
}

.hero h1 { margin: 0 0 10px; font-size: 28px; }
.hero p { margin: 0; font-weight: 600; }

.game-container {
  background: linear-gradient(135deg, rgba(109,157,252,0.08), rgba(143,123,255,0.08));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 24px;
  margin-top: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.input-section {
  margin-bottom: 30px;
}

.input-group {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.input-group label {
  min-width: 100px;
  font-weight: 600;
  color: var(--text);
}

.input-field {
  flex: 1;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(109,157,252,0.2);
}

.button-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--bg);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(109,157,252,0.3);
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:hover {
  background: var(--surface);
}

.ladder-container {
  position: relative;
  margin: 30px 0;
  overflow-x: auto;
}

.ladder {
  display: flex;
  position: relative;
  min-height: 400px;
  padding: 20px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
}

.ladder-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.participant {
  width: 120px;
  padding: 12px;
  background: var(--card);
  border-radius: 8px;
  text-align: center;
  margin-bottom: 20px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
  font-weight: 600;
}

.participant.winner {
  border-color: var(--success);
  background: linear-gradient(135deg, rgba(74,222,128,0.1), rgba(74,222,128,0.05));
}

.ladder-line {
  width: 4px;
  background: var(--muted);
  flex: 1;
  position: relative;
  margin: 8px 0;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(109,157,252,0.3);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.ladder-line.path {
  background: linear-gradient(135deg, var(--accent), var(--primary));
  box-shadow: 0 0 10px rgba(61,214,255,0.35);
}

.connection {
  position: absolute;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(61,214,255,0.6);
  opacity: 0;
  transform: scaleX(0);
  transform-origin: left center;
  transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.connection.active {
  opacity: 1;
  transform: scaleX(1);
}

.connection.path {
  box-shadow: 0 0 18px rgba(61,214,255,0.35);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(61,214,255,0.6); }
  50% { box-shadow: 0 0 16px rgba(61,214,255,1); }
}

.loading-message {
  text-align: center;
  padding: 40px;
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}

.result-flow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.6s ease;
}

.result-flow.visible {
  opacity: 1;
  transform: translateX(0);
}

.result-flow:last-child {
  border-bottom: none;
}

.flow-participant, .flow-result {
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  min-width: 100px;
  text-align: center;
}

.flow-participant {
  background: var(--card);
  color: var(--text);
}

.flow-result {
  background: linear-gradient(135deg, var(--success), var(--accent));
  color: white;
}

.flow-arrow {
  flex: 1;
  text-align: center;
  color: var(--accent);
  font-size: 20px;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.flow-arrow.visible {
  opacity: 1;
}

.results-bar {
  margin-top: 20px;
  padding: 20px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-around;
  gap: 10px;
  flex-wrap: wrap;
}

.result-slot {
  flex: 1;
  min-width: 100px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(109,157,252,0.1), rgba(143,123,255,0.1));
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  color: var(--text);
  transition: all 0.3s ease;
  position: relative;
  opacity: 0;
  transform: translateY(20px);
}

.result-slot.visible {
  opacity: 1;
  transform: translateY(0);
}

.result-slot.highlighted {
  border-color: var(--slot-accent, var(--accent));
  box-shadow: 0 0 15px color-mix(in srgb, var(--slot-accent, var(--accent)) 70%, transparent);
  transform: scale(1.05);
}

.result-slot.emphasis {
  animation: resultPulse 0.9s ease;
}

@keyframes resultPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.participant.clickable {
  cursor: pointer;
  transition: all 0.3s ease;
}

.participant.clickable:hover {
  background: linear-gradient(135deg, rgba(109,157,252,0.2), rgba(143,123,255,0.2));
  transform: translateY(-2px);
}

.participant.selected {
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: var(--bg);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(61,214,255,0.4);
}

.path-highlight {
  position: absolute;
  background: var(--accent);
  opacity: 0.3;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 1;
}

.result-summary {
  margin-top: 30px;
  padding: 20px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  text-align: center;
}

.result-summary h3 {
  margin: 0 0 16px 0;
  color: var(--text);
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.5s ease;
}

.summary-item.visible {
  opacity: 1;
  transform: translateX(0);
}

.summary-item:last-child {
  border-bottom: none;
}

.summary-item.emphasis {
  animation: summaryFlash 0.65s ease;
}

@keyframes summaryFlash {
  0% { background: rgba(61,214,255,0); }
  40% { background: rgba(61,214,255,0.12); }
  100% { background: rgba(61,214,255,0); }
}

.summary-participant, .summary-result {
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
}

.summary-participant {
  background: var(--surface);
  color: var(--text);
}

.summary-result {
  background: linear-gradient(135deg, var(--success), rgba(74,222,128,0.8));
  color: white;
}

.result-section {
  margin-top: 30px;
  padding: 20px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.result-item:last-child {
  border-bottom: none;
}

.result-label {
  font-weight: 600;
  color: var(--text);
}

.result-value {
  color: var(--accent);
  font-weight: 600;
}

.animation-line {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--error);
  border-radius: 50%;
  animation: moveDown 2s ease-in-out;
}

@keyframes moveDown {
  0% { top: 0; }
  100% { top: 100%; }
}

.ladder-tracer {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.hidden { display: none; }

@media (max-width: 768px) {
  .input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .input-group label {
    min-width: auto;
    margin-bottom: 8px;
  }

  .button-group {
    flex-direction: column;
  }

  .participant {
    width: 100px;
    font-size: 14px;
  }
}

