* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: #f2f4f8; }

.cd-outer {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.cd-container {
  width: 100%;
  max-width: 820px;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(0,0,0,0.15);
}

/* ---------- Header ---------- */
.cd-header {
  background: #1c4e9e;
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.cd-instruction { font-size: 13px; font-weight: 600; max-width: 340px; }
.cd-instruction-short { display: none; }
.cd-header-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cd-progress, .cd-score, .cd-life { font-size: 13px; font-weight: 700; }
.cd-home-btn {
  background: #2ecc71; color: #fff; border: none; border-radius: 20px; padding: 6px 16px;
  font-size: 12px; font-weight: 700; cursor: pointer;
}

/* ---------- Scene ---------- */
.cd-scene {
  position: relative;
  min-height: 480px;
  background: linear-gradient(#7fb8e8 0%, #a8d4f0 40%, #dce8ee 40%, #dce8ee 100%);
  padding-bottom: 10px;
}

.cd-loading, .cd-warning {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; gap: 14px; color: #3a3a3a;
}
.cd-spinner {
  width: 36px; height: 36px; border: 4px solid #cfe8ff; border-top-color: #1c4e9e;
  border-radius: 50%; animation: cd-spin 0.8s linear infinite;
}
@keyframes cd-spin { to { transform: rotate(360deg); } }
.cd-warning-icon { font-size: 40px; }

/* ---------- Sky decoration ---------- */
.cd-sky { position: relative; height: 90px; }
.cd-cloud { position: absolute; font-size: 26px; opacity: 0.9; }
.cd-cloud-1 { top: 8px; left: 8%; }
.cd-cloud-2 { top: 20px; right: 12%; }
.cd-tree { position: absolute; bottom: 0; font-size: 34px; }
.cd-tree-1 { left: 4%; }
.cd-tree-2 { right: 6%; }
.cd-station { position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%); font-size: 38px; }

/* ---------- Train ---------- */
.cd-track-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 16px 18px;
  flex-wrap: wrap;
}
.cd-engine { font-size: 46px; position: relative; }
.cd-smoke { position: absolute; top: -14px; left: 6px; font-size: 16px; opacity: 0.8; animation: cd-puff 2s ease-in-out infinite; }
@keyframes cd-puff {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50% { transform: translateY(-6px); opacity: 1; }
}

.cd-wagons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.cd-wagon {
  width: 62px; height: 62px;
  background: #fff;
  border: 3px dashed #4a6fa5;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #1c4e9e;
  cursor: default;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.cd-wagon.filled { border-style: solid; border-color: #2ecc71; background: #f4fff8; cursor: pointer; }
.cd-wagon.drag-over { border-color: #ff9f1c; background: #fff4e0; transform: scale(1.06); }
.cd-wagon.correct-flash { animation: cd-bounce 0.4s; border-color: #2ecc71; background: #d7f9e4; }
.cd-wagon.incorrect-flash { animation: cd-shake 0.4s; border-color: #e74c3c; background: #fdecea; }
@keyframes cd-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes cd-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.cd-feedback {
  text-align: center; font-size: 14px; font-weight: 700; padding: 8px 16px; border-radius: 10px;
  margin: 0 auto 10px; max-width: 400px;
}
.cd-feedback-correct { background: rgba(46,204,113,0.92); color: #fff; }
.cd-feedback-incorrect { background: rgba(231,76,60,0.92); color: #fff; }

/* ---------- Platform ---------- */
.cd-platform-label { text-align: center; font-size: 12px; font-weight: 700; color: #4a3200; margin-bottom: 6px; }
.cd-platform {
  background: #2c3e50;
  border-top: 4px solid #1a252f;
  margin: 0 16px;
  border-radius: 10px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px;
}
.cd-crate {
  width: 58px; height: 58px;
  background: #ecf0f1;
  border: 3px solid #34495e;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; color: #2c3e50;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.cd-crate:hover { transform: translateY(-3px); box-shadow: 0 6px 12px rgba(0,0,0,0.2); }
.cd-crate.dragging { opacity: 0.4; }

.cd-go-wrap { display: flex; justify-content: center; margin-top: 18px; }
.cd-go-btn {
  background: #2ecc71; color: #fff; border: none; border-radius: 16px;
  padding: 14px 50px; font-size: 22px; font-weight: 900; cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,0.2); transition: transform 0.15s, opacity 0.15s;
}
.cd-go-btn:hover:not(:disabled) { transform: translateY(-2px); }
.cd-go-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Result screen ---------- */
.cd-result { text-align: center; padding: 50px 30px; background: #fff; }
.cd-result-icon { font-size: 56px; margin-bottom: 8px; }
.cd-result h2 { margin: 0 0 8px; color: #2f3542; }
.cd-result p { color: #6b6b6b; margin: 0 0 20px; }
.cd-result-stats { display: flex; justify-content: center; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
.cd-result-stats span { display: block; font-size: 24px; font-weight: 800; color: #ff9f1c; }
.cd-result-stats small { color: #999; font-size: 12px; }
.cd-result-answer { font-size: 14px; font-weight: 700; color: #4a3200; margin-bottom: 20px; }
.cd-result-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.cd-btn {
  border: none; border-radius: 12px; padding: 12px 26px; font-size: 14px; font-weight: 700;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.cd-btn-primary { background: #2ecc71; color: #fff; }
.cd-btn-secondary { background: #5b8def; color: #fff; }

/* ---------- Home confirmation modal ---------- */
.cd-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.cd-modal {
  background: #fff; border-radius: 16px; padding: 26px 24px; max-width: 340px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.cd-modal p { font-size: 15px; font-weight: 600; color: #2f3542; margin: 0 0 18px; }
.cd-modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .cd-outer { padding: 10px; }
  .cd-container { border-radius: 12px; }
  .cd-header { padding: 10px 12px; }
  .cd-instruction-long { display: none; }
  .cd-instruction-short { display: inline; }
  .cd-instruction { flex-basis: 100%; text-align: center; order: 1; font-size: 11px; max-width: none; }
  .cd-header-right { order: 2; margin: 0 auto; gap: 10px; }
  .cd-progress, .cd-score, .cd-life { font-size: 11px; }

  .cd-scene { min-height: 420px; }
  .cd-sky { height: 70px; }
  .cd-tree { font-size: 24px; }
  .cd-cloud { font-size: 20px; }
  .cd-station { font-size: 28px; }
  .cd-engine { font-size: 34px; }
  .cd-wagon { width: 48px; height: 48px; font-size: 19px; }
  .cd-crate { width: 48px; height: 48px; font-size: 18px; }
  .cd-platform { margin: 0 10px; padding: 10px; gap: 8px; }
  .cd-go-btn { padding: 12px 40px; font-size: 18px; }
}
