:root {
  --bg1: #87cefa;
  --bg2: #d6f0ff;
  --panel-blue: #2563eb;
  --panel-blue-600: #1d4ed8;
  --panel-red: #ef4444;
  --panel-red-600: #dc2626;
  --accent: #10b981;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  --card-bg: #ffffffcc;
  --text: #0f172a;
  --muted: #6b7280;
  --button-blue: #2563eb;
  --button-red: #ef4444;
  --button-blue-600: #1d4ed8;
  --button-red-600: #dc2626;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu,
    Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  color: var(--text);
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  overflow: hidden;
}

.game-wrapper {
  position: relative;
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr minmax(420px, 1.2fr) 1fr;
  gap: 18px;
  padding: clamp(10px, 2vw, 20px);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  padding: clamp(10px, 1.6vw, 16px);
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(6px);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.problem-card {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(20px, 2.6vw, 34px);
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.6);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}
.answer-input {
  width: 100%;
  font-size: clamp(18px, 2.2vw, 28px);
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #e5e7eb;
  outline: none;
  background: #fff;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.answer-input:focus {
  border-color: var(--button-blue);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.08);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .2s ease, background .2s ease;
  box-shadow: 0 6px 16px rgba(0,0,0,.15);
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-blue { background: var(--button-blue); }
.btn-blue:hover { background: var(--button-blue-600); }
.btn-red { background: var(--button-red); }
.btn-red:hover { background: var(--button-red-600); }

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.key {
  background: #ffffff;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 0;
  font-weight: 800;
  font-size: clamp(16px, 2vw, 22px);
  cursor: pointer;
  transition: background .15s ease, transform .06s ease, box-shadow .2s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,.1);
}
.key:active { transform: translateY(1px); }
.key:hover { background: #f8fafc; }

.blue .problem-card { color: var(--panel-blue-600); }
.red .problem-card { color: var(--panel-red-600); }

.stage {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.65), rgba(255,255,255,0.35));
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ground {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 44%;
  background: linear-gradient(180deg, #b0dba9, #7cc576);
}

.center-line {
  position: absolute;
  top: 8%;
  bottom: 36%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 4px dashed #94a3b8;
  opacity: .9;  
}

.rope-area {
  position: relative;
  width: 100%;  
}

.rope-group { transition: transform .5s cubic-bezier(.22,1,.36,1); }

/* Sprite image that contains both kids and the rope. Keep transparency and natural proportions. */
#tugImage {
  width: 550px;
  max-width: 82vw;
  height: auto;
  display: block;
  margin: 0 auto;
  transition: transform .4s ease;
  will-change: transform;
  pointer-events: none;
  z-index: 2;
}

/* Small pull visual feedback applied to the entire sprite */
.pull { transform: translateY(-6px) scale(1.02); transition: transform .16s ease; }

/* Put the dashed center line behind the sprite */
.center-line { z-index: 1; }

.rope {
  position: absolute;
  top: 42%;
  left: 5%;
  right: 5%;
  height: 10px;
  background: repeating-linear-gradient(90deg, #c4a76a 0 16px, #b18d52 16px 32px);
  border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.25);
}
.rope-knot {
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #9b7a3f;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.25);
  border: 3px solid rgba(255,255,255,.6);
}

.kid {
  position: absolute;
  bottom: 28%;
  width: 140px; height: 160px;
  transition: transform .4s ease;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.25));
}
.kid.left { left: 8%; }
.kid.right { right: 8%; }

.kid .body {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 40px; width: 86px; height: 90px; border-radius: 18px;
  background: #60a5fa;
}
.kid.right .body { background: #f87171; }

.kid .head {
  position: absolute; left: 50%; transform: translate(-50%, 0);
  bottom: 116px; width: 70px; height: 70px; border-radius: 50%;
  background: #ffd7b5; box-shadow: inset 0 -4px 0 rgba(0,0,0,.05);
}
.kid .eye {
  position: absolute; top: 22px; width: 10px; height: 10px; border-radius: 50%; background: #111827;
}
.kid.left .eye { left: 22px; }
.kid.right .eye { right: 22px; }
.kid .smile {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  width: 28px; height: 14px; border: 3px solid #111827; border-top: none; border-radius: 0 0 20px 20px;
}
.kid .arm {
  position: absolute; bottom: 84px; width: 64px; height: 14px; border-radius: 8px; background: #ffd7b5;
}
.kid.left .arm { left: 50%; transform-origin: left center; transform: translateX(-2px) rotate(6deg); }
.kid.right .arm { right: 50%; transform-origin: right center; transform: translateX(2px) rotate(-6deg); }
.kid.pull { transform: translateY(-4px) scale(1.02); }

.clouds {
  position: absolute; inset: 0; pointer-events: none; opacity: .7;
  background-image:
    radial-gradient(circle at 10% 18%, #fff 0 22px, transparent 24px),
    radial-gradient(circle at 30% 12%, #fff 0 18px, transparent 20px),
    radial-gradient(circle at 60% 16%, #fff 0 26px, transparent 28px),
    radial-gradient(circle at 80% 10%, #fff 0 18px, transparent 20px),
    radial-gradient(circle at 65% 26%, #fff 0 22px, transparent 24px);
  background-size: 200% 100%;
  animation: clouds 24s linear infinite;
}
@keyframes clouds { to { background-position: -200% 0; } }

.shake { animation: shake .3s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.status-banner {
  position: absolute;
  top: 14px; left: 50%; transform: translateX(-50%);
  background: #ffffffd0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.blue { background: var(--panel-blue); }
.dot.red { background: var(--panel-red); }
.wins { color: #0b1220; opacity: .8; font-weight: 800; }

.overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 6;
}
.overlay.show { display: flex; }
.win-card {
  background: #fff;
  color: var(--text);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px 28px;
  text-align: center;
  min-width: min(90vw, 520px);
}
.win-title { font-size: clamp(24px, 3.2vw, 38px); font-weight: 900; margin: 0 0 8px; }
.win-sub { font-size: clamp(14px, 1.8vw, 18px); color: var(--muted); margin-bottom: 12px; }

.home-btn {
  position: absolute; left: 16px; bottom: 16px;
  background: #ffffffcc; color: var(--text);
  border: 2px solid #e5e7eb; border-radius: 12px;
  padding: 8px 12px; font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow);
}

/* History mini cards */
.mini.history { margin-top: 12px; padding: 10px 12px; }
.mini.history strong { display: block; margin-bottom: 8px; font-size: 14px; color: #0b1220; }
.history-list { display: grid; gap: 6px; max-height: 120px; overflow: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 6px 8px; border-radius: 10px; background: #fff; border: 1px solid #e5e7eb; }
.history-item .bin { font-weight: 800; letter-spacing: .5px; }
.history-item .ans { color: var(--muted); }
.history-item.good { border-color: #86efac; background: #f0fdf4; }
.history-item.bad { border-color: #fecaca; background: #fff1f2; }

@media (max-width: 1100px) {
  .game-wrapper { grid-template-columns: 1fr; grid-template-rows: auto auto auto; overflow: auto; }
  .panel { order: 1; }
  .stage { order: 0; min-height: 340px; }
  .kid { width: 110px; height: 130px; }
}
@media (max-width: 640px) {
  .keypad { grid-template-columns: repeat(5, 1fr); }
  .rope { top: 46%; }
  .kid { width: 96px; height: 114px; }
}
