:root {
  --bg: #fdf2ef;
  --ink: #2b2320;
  --ink-soft: #8a7871;
  --line: #f1ded7;

  --accent: #ef6a55;
  --accent-dark: #d84f3b;

  --font-display: "Nunito", ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", sans-serif;

  --edge: #d9c7c0;
  --node: var(--ink);
  --node-fixed: #4a6fa5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 2.4vh 4vw 3vh;
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0.8vh;
  color: var(--ink-soft);
  font-size: clamp(10px, 1.4vh, 12px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }
.back-link svg { width: 13px; height: 13px; }

.title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(15px, 2.4vh, 20px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.subtitle {
  margin: 0.4em 0 0;
  font-size: clamp(10px, 1.4vh, 12px);
  letter-spacing: 0.3em;
  color: var(--ink-soft);
}

.top-actions {
  display: flex;
  gap: 2vw;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn:active {
  background: rgba(239, 106, 85, 0.12);
  border-color: var(--accent);
  color: var(--accent-dark);
  transform: scale(0.94);
}

.tagline {
  margin: 1.6vh 0 0;
  text-align: center;
  font-size: clamp(12px, 1.7vh, 14px);
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* Show the matching instruction for how this device actually moves a dot —
   touch devices tap, everything else drags. Pure CSS, no device-detection JS. */
.tagline-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .tagline-touch { display: block; }
  .tagline-mouse { display: none; }
}

/* ---- board area ---- */

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2vh;
  min-height: 0;
}

.board-wrap {
  position: relative;
  width: min(90vw, 64vh, 560px);
  aspect-ratio: 1 / 1;
}

.board {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.edge {
  stroke: var(--edge);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke 0.15s ease, stroke-width 0.15s ease;
}

.edge.crossing {
  stroke: var(--accent);
  stroke-width: 3;
  animation: edge-pulse 1.4s ease-in-out infinite;
}

.board.dragging .edge.crossing {
  animation-play-state: paused; /* less concurrent paint work while the player is mid-drag */
}

@keyframes edge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* Invisible, larger circle that owns all pointer/touch interaction — decoupled
   from the visible dot's size so grabbing a node never needs pixel-perfect
   finger placement, even when the dot itself renders small. */
.node-hit {
  fill: transparent;
  cursor: grab;
  touch-action: none; /* the node owns its own drag gesture */
}
.node-hit:active { cursor: grabbing; }

.node {
  fill: var(--node);
  stroke: var(--bg);
  stroke-width: 3;
  pointer-events: none; /* the node-hit circle beneath handles all interaction */
  transition: r 0.15s ease, filter 0.15s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.node.active {
  fill: var(--accent-dark);
  filter: drop-shadow(0 0 6px rgba(239, 106, 85, 0.55));
}

.node.hint {
  animation: node-hint 1.3s ease-in-out infinite;
}

@keyframes node-hint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.node.fixed {
  fill: none;
  stroke: var(--node-fixed);
  stroke-width: 4;
}

.node.shake {
  animation: node-shake 0.26s ease-in-out;
}

@keyframes node-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ---- counter ---- */

.counter-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3vh;
}

.counter-label {
  font-size: clamp(9px, 1.3vh, 11px);
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.counter-value {
  font-size: clamp(16px, 2.4vh, 20px);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.05em;
}

.counter-best {
  font-size: clamp(9px, 1.2vh, 11px);
  color: var(--accent-dark);
  font-weight: 600;
  letter-spacing: 0.06em;
  min-height: 1.4em;
}

.seo-info {
  flex-shrink: 0;
  align-self: center;
  max-width: 90vw;
  margin-top: 0.6vh;
  font-size: 9px;
  color: var(--ink-soft);
  text-align: center;
}
.seo-info summary {
  cursor: pointer;
  letter-spacing: 0.06em;
  font-weight: 600;
  list-style: none;
}
.seo-info summary::-webkit-details-marker { display: none; }
.seo-info summary::after { content: " ▾"; }
.seo-info[open] summary::after { content: " ▴"; }
.seo-info p {
  margin: 4px 0 0;
  line-height: 1.5;
  text-align: left;
}

/* ---- overlay ---- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(253, 242, 239, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.overlay.show {
  opacity: 1;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.2vh;
  pointer-events: none;
}

.overlay.show .overlay-content {
  pointer-events: auto;
}

.overlay-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(18px, 3.4vh, 26px);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.overlay-icon {
  overflow: visible;
}
.overlay-icon line {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.overlay-icon circle {
  fill: var(--accent-dark);
  animation: glow 1.6s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 1.5px rgba(239, 106, 85, 0.5)); }
  50% { filter: drop-shadow(0 0 4px rgba(239, 106, 85, 0.9)); }
}

.overlay-sub {
  margin: 0;
  font-size: clamp(12px, 1.8vh, 14px);
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

.overlay-actions {
  display: flex;
  gap: 3vw;
  margin-top: 1vh;
}

.again-btn,
.share-btn {
  font-family: var(--font-display);
  font-weight: 600;
  padding: 1.2vh 4vw;
  border-radius: 999px;
  font-size: clamp(12px, 1.8vh, 14px);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.again-btn:active,
.share-btn:active { transform: scale(0.96); }

.again-btn {
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 0.8vh 1.8vh rgba(239, 106, 85, 0.35);
}

.share-btn {
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent-dark);
}

.share-note {
  margin: 0;
  font-size: clamp(11px, 1.5vh, 13px);
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.share-note.show {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .node { transition: none; }
  .node.hint { animation: none; }
  .node.shake { animation: none; }
  .edge.crossing { animation: none; }
  .overlay-icon circle { animation: none; }
}

/* ==== Neon Arcade (dark theme) ==== */

:root[data-theme="dark"] {
  --bg: #170f11;
  --ink: #f7ece8;
  --ink-soft: #c9a7a0;
  --line: #3a2420;

  --accent: #ff6b57;
  --accent-dark: #ff3d3d;

  --edge: #4a3430;
  --node: #f7ece8;
  --node-fixed: #4fd3ff;
}

[data-theme="dark"] .icon-btn:active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

[data-theme="dark"] .node.active {
  fill: var(--accent);
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 75%, transparent));
}

[data-theme="dark"] .edge.crossing {
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent) 65%, transparent));
}

[data-theme="dark"] .overlay {
  background: rgba(23, 15, 17, 0.94);
}

[data-theme="dark"] .again-btn {
  box-shadow: 0 0.8vh 1.8vh color-mix(in srgb, var(--accent) 45%, transparent);
}
