html, body {
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* ── Rule bar ── */
.rule-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto;
  padding: 6px 14px;
}

.rule-btn {
  flex-shrink: 0;
  font-size: 26px;
  padding: 8px 12px;
  background: var(--color-accent);
}

.rule-text {
  flex: 1;
  min-width: 0;
}

.rule-label {
  font-size: 24px;
  font-weight: bold;
  color: var(--color-primary);
}

.rule-sub {
  font-size: 16px;
  font-weight: bold;
  color: #777;
}

.mark-start { color: #e8505b; }
.mark-goal  { color: #f0a500; }

.rule-diagram {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.rule-word {
  display: flex;
  gap: 2px;
}

.rule-box {
  width: 18px;
  height: 18px;
  border: 2px solid #bbb;
  border-radius: 4px;
  background: #fafafa;
}

.rule-box.key {
  border-color: var(--color-primary);
  background: var(--color-primary);
}

.rule-arrow {
  font-weight: bold;
  color: #999;
}

/* ── Board ── */
.board {
  position: relative;
  width: min(calc(100vw - 24px), calc(100vh - 210px), 820px);
  aspect-ratio: 1 / 1;
  margin: 6px auto 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: none;
}

.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.lines line {
  stroke-linecap: round;
}

.lines line.link {
  stroke: #555;
  stroke-width: 5;
}

.lines line.temp {
  stroke: #999;
  stroke-width: 4;
  stroke-dasharray: 8 8;
}

.lines line.bad {
  stroke: var(--color-wrong);
  stroke-width: 7;
  animation: blink 0.35s 3;
}

.lines.answer line.link {
  stroke: #f0a500;
  stroke-width: 7;
  stroke-dasharray: 2 12;
}

.lines.done line.link {
  stroke: var(--color-correct);
  stroke-width: 7;
}

@keyframes blink {
  50% { opacity: 0.2; }
}

.node {
  position: absolute;
  width: 17%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.node img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  -webkit-user-drag: none;
}

.node .fallback {
  font-size: 15px;
  color: #999;
  text-align: center;
}

.node.in-path {
  background: rgba(255, 209, 102, 0.25);
}

.node.head {
  box-shadow: 0 0 0 4px rgba(255, 127, 163, 0.5);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { box-shadow: 0 0 0 9px rgba(255, 127, 163, 0.15); }
}

.node.start {
  border: 4px solid #e8505b;
}

.node.goal {
  border: 4px solid #f0a500;
}

.node .star {
  position: absolute;
  top: -10%;
  right: -10%;
  font-size: clamp(22px, 4vw, 36px);
  color: #f0a500;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  z-index: 3;
}

.node .badge {
  position: absolute;
  top: -22%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  background: #e8505b;
  border-radius: 10px;
  padding: 1px 8px;
  z-index: 3;
}

.node.goal .badge { background: #f0a500; }

.node .name {
  position: absolute;
  bottom: -16%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: clamp(12px, 2vw, 17px);
  font-weight: bold;
  color: var(--color-primary);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 0 4px;
  display: none;
  z-index: 3;
}

.board.show-names .node .name,
.node.reveal .name {
  display: block;
}

.node.reveal .name {
  color: var(--color-correct);
}

/* ── Tools ── */
.tools {
  text-align: center;
  padding: 10px 0 20px;
}

.clear-btn {
  background: #fff;
  color: #888;
  border: 3px solid #eee;
  font-size: 17px;
  font-weight: bold;
  padding: 10px 22px;
}

.next-btn {
  font-size: 24px;
  font-weight: bold;
  padding: 14px 44px;
  animation: pulse-btn 1.4s ease-in-out infinite;
}

@keyframes pulse-btn {
  50% { transform: scale(1.06); }
}

/* ── Feedback ── */
.feedback {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  font-weight: bold;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 200;
}

.feedback.show { opacity: 1; }
.feedback.correct { color: var(--color-correct); }
.feedback.wrong   { color: var(--color-wrong); }

/* ── Result ── */
.result {
  text-align: center;
  padding: 40px 20px;
}

.result h2 {
  font-size: 36px;
  color: var(--color-primary);
}

.result .score {
  font-size: 24px;
  margin: 20px 0;
}

.result .candy-get {
  font-size: 56px;
  margin: 20px 0;
  word-break: break-all;
}

.result button {
  margin: 10px 8px;
  font-size: 18px;
}

@media (max-width: 600px) {
  .rule-label { font-size: 19px; }
  .rule-sub { font-size: 13px; }
  .rule-box { width: 13px; height: 13px; }
}
