:root{
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #15171a;
  --muted: #6b7280;
  --border: #d6d9df;
  --shadow: 0 10px 30px rgba(0,0,0,.08);

  --good: #16a34a;
  --bad: #dc2626;

  --boxW: 140px;
  --boxH: 82px;
}

*{ box-sizing: border-box; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app{
  min-height: 100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
}

.card{
  width: min(720px, 96vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.hidden{ display:none !important; }

h1{
  margin: 6px 0 16px;
  font-size: 28px;
  letter-spacing: .2px;
}

.field{
  display:flex;
  flex-direction:column;
  gap: 8px;
  margin: 12px 0;
}
.field span{ color: var(--muted); font-size: 14px; }

input[type="number"]{
  width: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 18px;
}

.checkbox{
  display:flex;
  align-items:center;
  gap: 10px;
  margin: 12px 0 4px;
  color: var(--ink);
}
.checkbox input{ transform: scale(1.1); }

.error{
  min-height: 22px;
  color: var(--bad);
  margin: 6px 0 10px;
}

.btn{
  border: 1px solid var(--border);
  background: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
}
.btn:hover{ filter: brightness(0.98); }
.btn:active{ transform: translateY(1px); }
.btn.primary{
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.hint{
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

/* game topbar */
.topbar{
  display:grid;
  grid-template-columns: 1fr auto 1fr;
  align-items:center;
  gap: 10px;
  padding: 6px 2px 14px;
  border-bottom: 1px solid var(--border);
}

.score{
  font-size: 20px;
  font-weight: 700;
}

.progressWrap{
  justify-self:center;
  text-align:center;
}
.dots{
  display:flex;
  justify-content:center;
  gap: 10px;
  margin-bottom: 6px;
}
.dot{
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #111;
  background: transparent;
}
.dot.filled{
  background: var(--good);
  border-color: var(--good);
}
.maxText{
  font-size: 14px;
  color: var(--muted);
}

#stopBtn{
  justify-self:end;
}

/* board */
.board{
  padding: 18px 6px 8px;
  position: relative;
  min-height: 360px;
}

.instruction{
  margin-top: 14px;
  text-align:center;
  color: var(--muted);
}

/* reward overlay */
.reward{
  position:absolute;
  inset: 0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 44px;
  font-weight: 800;
  color: var(--good);
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(2px);
  border-radius: 16px;
  z-index: 5;
}

/* diagram: fixed positioning so it never collapses */
.diagram{
  position: relative;
  width: 520px;
  height: 320px;
  margin: 10px auto 0;
}

/* the connecting lines */
.wires{
  position:absolute;
  inset: 0;
  z-index: 0;
}
.wires line{
  stroke: #111;
  stroke-width: 5;
  stroke-linecap: round;
}

/* wires toggling */
.wires3{ display:none; }
.diagram.three .wires2{ display:none; }
.diagram.three .wires3{ display:block; }

/* boxes */
.box{
  width: var(--boxW);
  height: var(--boxH);
  border: 3px solid #111;
  border-radius: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  position:absolute;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  z-index: 1;
}

/* positions (2-split default) */
.box.top   { top: 40px; }
.box.left  { top: 190px; transform: translateX(calc(-50% - 130px)); }
.box.right { top: 190px; transform: translateX(calc(-50% + 130px)); }

/* middle box: hidden unless 3-split */
.box.mid{ display:none; }
.diagram.three .box.mid{
  display:flex;
  top: 190px;
  transform: translateX(-50%);
}
.diagram.three .box.left{
  transform: translateX(calc(-50% - 165px));
}
.diagram.three .box.right{
  transform: translateX(calc(-50% + 165px));
}

/* number text */
.num{
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
}

/* answer input */
.ans{
  width: 96px;
  height: 62px;
  border: none;
  outline: none;
  border-radius: 12px;
  text-align:center;
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  background: transparent;
  color: var(--ink);
  padding: 0;
}

/* feedback colors */
.good{ color: var(--good) !important; }
.bad{ color: var(--bad) !important; }

/* mobile scaling */
@media (max-width: 560px){
  .diagram{ width: 360px; height: 300px; }
  .wires{ width: 360px; height: 300px; }
  .wires line{ stroke-width: 4; }

  .box.top{ top: 36px; }
  .box.left{ top: 186px; transform: translateX(calc(-50% - 90px)); }
  .box.right{ top: 186px; transform: translateX(calc(-50% + 90px)); }

  .diagram.three .box.left{ transform: translateX(calc(-50% - 115px)); }
  .diagram.three .box.right{ transform: translateX(calc(-50% + 115px)); }

  .num{ font-size: 40px; }
  .ans{ font-size: 40px; width: 84px; height: 56px; }
}

