:root {
  color-scheme: light;
  --paper: #eee9df;
  --paper-deep: #e3dccf;
  --ink: #313337;
  --muted: #77756f;
  --line: rgba(49, 51, 55, 0.16);
  --circle: #718b98;
  --square: #a87367;
  --triangle: #81947a;
  --diamond: #b29655;
  --star: #927a91;
  --board-size: min(82vw, 72vh, 560px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.88), transparent 35rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(49, 51, 55, 0.6);
  outline-offset: 4px;
}

.game-shell {
  width: min(94vw, 680px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.game-header,
.status-bar,
.game-footer {
  width: var(--board-size);
  margin-inline: auto;
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 0.85;
  letter-spacing: 0.13em;
}

.instructions {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
  text-align: right;
}

.status-bar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 5px 10px;
}

.targets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.target {
  min-width: 68px;
  height: 40px;
  padding: 0 11px 0 7px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.42);
  transition: opacity 180ms ease, transform 180ms ease, background 180ms ease;
}

.target svg {
  width: 27px;
  height: 27px;
}

.target strong {
  min-width: 1.3em;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.target.hit {
  animation: target-hit 280ms ease-out;
}

.target.done {
  opacity: 0.42;
  background: transparent;
}

.target.done strong {
  text-decoration: line-through;
}

.moves {
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.moves span {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.moves strong {
  min-width: 1.3em;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.board-wrap {
  width: var(--board-size);
  aspect-ratio: 1;
  margin-inline: auto;
  filter: drop-shadow(0 22px 34px rgba(74, 67, 56, 0.1));
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(49, 51, 55, 0.15);
  border-radius: clamp(22px, 5vw, 34px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.22)),
    var(--paper-deep);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 4px rgba(63, 58, 48, 0.06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board-grid {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  padding: 3.2%;
  pointer-events: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 21%;
  border: 1px solid rgba(49, 51, 55, 0.035);
}

.blocker {
  position: absolute;
  inset: 17%;
  border: 1px solid rgba(49, 51, 55, 0.14);
  border-radius: 19%;
  background:
    repeating-linear-gradient(135deg, transparent 0 5px, rgba(49, 51, 55, 0.04) 5px 6px),
    rgba(49, 51, 55, 0.065);
  box-shadow: inset 0 2px 5px rgba(49, 51, 55, 0.08);
}

.blocker::after {
  content: "\00d7";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(49, 51, 55, 0.22);
  font-size: clamp(0.9rem, 3vw, 1.4rem);
  font-weight: 300;
}

.node {
  --node-color: var(--circle);
  position: relative;
  z-index: 2;
  width: 72%;
  height: 72%;
  display: grid;
  place-items: center;
  color: var(--node-color);
  transform-origin: center;
  will-change: transform, opacity;
}

.node::before {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  transform: scale(0.72);
  transition: opacity 120ms ease, transform 160ms ease;
  filter: blur(7px);
}

.node svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 3px 2px rgba(49, 51, 55, 0.11));
  transition: filter 120ms ease;
}

.shape-fill {
  fill: currentColor;
  stroke: #3f4143;
  stroke-width: 3.1;
  stroke-linejoin: round;
}

.shape-mark {
  fill: none;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 2;
  stroke-linecap: round;
}

.node.selected {
  z-index: 4;
  animation: select-node 220ms cubic-bezier(0.2, 1.8, 0.4, 1) both;
}

.node.selected::before,
.node.loop-match::before {
  opacity: 0.2;
  transform: scale(1);
}

.node.loop-match svg {
  animation: loop-match 520ms ease-in-out infinite alternate;
  filter: drop-shadow(0 0 7px currentColor);
}

.node.clearing {
  animation: clear-node 220ms cubic-bezier(0.5, -0.25, 0.8, 0.1) both;
  animation-delay: var(--clear-delay, 0ms);
}

.node.loop-clearing {
  animation-name: loop-clear-node;
  animation-duration: 300ms;
}

.node.dropping {
  animation: drop-node var(--drop-duration, 460ms) cubic-bezier(0.2, 0.82, 0.25, 1.12) both;
  animation-delay: var(--drop-delay, 0ms);
}

.node.reshuffling {
  animation: reshuffle-node 420ms ease both;
}

.connections {
  position: absolute;
  inset: 3.2%;
  z-index: 3;
  width: 93.6%;
  height: 93.6%;
  overflow: visible;
  pointer-events: none;
}

.connection-shadow,
.connection-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 80ms ease, stroke-width 150ms ease;
}

.connection-shadow {
  stroke: rgba(49, 51, 55, 0.2);
  stroke-width: 21;
  filter: blur(3px);
}

.connection-line {
  stroke: var(--active-color, var(--circle));
  stroke-width: 14;
}

.connections.active .connection-shadow,
.connections.active .connection-line {
  opacity: 1;
}

.connections.loop .connection-line {
  stroke-width: 18;
  animation: line-lock 430ms ease-in-out infinite alternate;
  filter: drop-shadow(0 0 8px var(--active-color));
}

.board.loop-snap {
  animation: board-snap 260ms ease-out;
}

.board-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0;
  box-shadow: inset 0 0 0 2px var(--active-color, transparent);
}

.board-flash.show {
  animation: board-flash 360ms ease-out;
}

.game-footer {
  min-height: 52px;
  padding: 12px 5px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
}

.seed-button,
.quiet-button {
  width: fit-content;
  padding: 7px 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.seed-button {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.seed-button span,
.quiet-button {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.seed-button strong {
  font-size: 0.73rem;
  letter-spacing: 0.13em;
}

.quiet-button {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.seed-button:hover strong,
.quiet-button:hover {
  color: var(--ink);
}

.shared-score {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.completion {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(49, 51, 55, 0.28);
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 220ms step-end;
  backdrop-filter: blur(7px);
}

.completion.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 220ms ease;
}

.completion-card {
  width: min(100%, 390px);
  padding: 38px;
  border: 1px solid rgba(49, 51, 55, 0.18);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 30px 70px rgba(49, 51, 55, 0.22);
  text-align: center;
  transform: translateY(12px) scale(0.98);
  transition: transform 300ms cubic-bezier(0.2, 0.9, 0.25, 1.1);
}

.completion.open .completion-card {
  transform: none;
}

.completion h2 {
  margin: 4px 0 18px;
  font-size: 2.5rem;
  letter-spacing: 0.12em;
}

.final-score {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.final-score strong {
  color: var(--ink);
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
}

.score-compare {
  min-height: 1.2em;
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.74rem;
}

.completion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.completion-actions button {
  min-height: 46px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.primary-button {
  grid-column: 1 / -1;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.secondary-button {
  border: 1px solid rgba(49, 51, 55, 0.24);
  background: transparent;
}

.completion-actions button:hover {
  transform: translateY(-1px);
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes select-node {
  0% { transform: scale(1); }
  55% { transform: scale(1.13); }
  100% { transform: scale(1.08); }
}

@keyframes loop-match {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}

@keyframes clear-node {
  0% { transform: scale(1.08); opacity: 1; }
  34% { transform: scale(0.88); opacity: 1; }
  100% { transform: scale(1.36); opacity: 0; }
}

@keyframes loop-clear-node {
  0% { transform: scale(1.04); opacity: 1; }
  28% { transform: scale(0.78) rotate(-4deg); opacity: 1; }
  100% { transform: scale(1.55) rotate(8deg); opacity: 0; }
}

@keyframes drop-node {
  0% { transform: translateY(var(--fall-y, -100px)); opacity: 0.15; }
  76% { transform: translateY(4px) scaleY(0.97); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes reshuffle-node {
  0%, 100% { transform: scale(1); opacity: 1; }
  42% { transform: scale(0.55) rotate(8deg); opacity: 0.15; }
}

@keyframes line-lock {
  from { opacity: 0.82; }
  to { opacity: 1; }
}

@keyframes board-snap {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(-2px, 1px); }
  55% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 0); }
}

@keyframes board-flash {
  0% { opacity: 0; box-shadow: inset 0 0 0 2px var(--active-color); }
  30% { opacity: 0.5; }
  100% { opacity: 0; box-shadow: inset 0 0 45px 4px var(--active-color); }
}

@keyframes target-hit {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.09); background: rgba(255, 255, 255, 0.84); }
}

@media (max-width: 600px) {
  :root {
    --board-size: min(94vw, 66vh, 560px);
  }

  .game-shell {
    width: 100%;
    justify-content: flex-start;
    padding-top: max(20px, env(safe-area-inset-top));
  }

  .game-header {
    align-items: center;
    margin-bottom: 14px;
  }

  .instructions {
    font-size: 0.68rem;
  }

  .status-bar {
    min-height: 48px;
    padding-bottom: 7px;
  }

  .target {
    min-width: 59px;
    height: 36px;
    padding: 0 8px 0 5px;
    gap: 5px;
  }

  .target svg {
    width: 24px;
    height: 24px;
  }

  .completion-card {
    padding: 32px 24px;
  }
}

@media (max-width: 380px) {
  .kicker,
  .instructions {
    display: none;
  }

  .game-header {
    margin-bottom: 10px;
  }

  .target {
    min-width: 53px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
