:root {
  color-scheme: dark;
  --ink: #111411;
  --panel: rgba(31, 35, 29, 0.9);
  --panel-soft: rgba(255, 243, 214, 0.075);
  --paper: #fff3d6;
  --muted: #d6c79f;
  --line: rgba(255, 243, 214, 0.18);
  --line-strong: rgba(255, 243, 214, 0.34);
  --gold: #f2b33d;
  --teal: #37b7aa;
  --rose: #dc5e74;
  --leaf: #83b95e;
  --clay: #c96f49;
  --focus: #fff1a3;
  --shadow: rgba(0, 0, 0, 0.36);
  --connect-board-size: clamp(320px, 44vw, 480px);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(242, 179, 61, 0.13), transparent 28rem),
    radial-gradient(circle at 86% 18%, rgba(55, 183, 170, 0.12), transparent 26rem),
    linear-gradient(180deg, #111411 0%, #172018 48%, #241a13 100%);
  color: var(--paper);
  font-family: "Avenir Next", "Noto Sans Devanagari", "Mangal", "Kohinoor Devanagari", Verdana, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 243, 214, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 243, 214, 0.03) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent);
}

button {
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(242, 179, 61, 0.52);
  border-radius: 50%;
  background:
    conic-gradient(from 30deg, rgba(242, 179, 61, 0.18), rgba(55, 183, 170, 0.14), rgba(220, 94, 116, 0.12), rgba(242, 179, 61, 0.18)),
    rgba(17, 20, 17, 0.66);
  color: var(--gold);
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: 1.54rem;
  font-weight: 900;
}

h1 {
  margin: 0 0 4px;
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: clamp(2.1rem, 4.2vw, 4.3rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.target-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.target-pill {
  border-radius: 8px;
  padding: 6px 11px;
  background: linear-gradient(135deg, var(--gold), #ffe38a);
  color: #17130a;
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-weight: 900;
}

.top-actions {
  display: flex;
  gap: 9px;
}

.icon-button,
.reset-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.16);
  transition: transform 100ms ease, border-color 100ms ease, background 100ms ease;
}

.icon-button:hover,
.reset-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(255, 243, 214, 0.13);
}

.icon-button:focus-visible,
.reset-button:focus-visible,
.tile:focus-visible,
.river-token:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 258px;
  gap: 18px;
  align-items: stretch;
}

.app[data-game="connect-word"] .layout {
  align-items: start;
}

.stage,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel), rgba(18, 22, 17, 0.84));
  box-shadow: 0 26px 70px var(--shadow);
  backdrop-filter: blur(18px);
}

.stage {
  position: relative;
  min-height: 650px;
  overflow: hidden;
}

.app[data-game="connect-word"] .stage {
  min-height: min(560px, calc(100svh - 150px));
}

.panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
}

.stats {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 850;
}

.stat-row strong {
  color: var(--paper);
  font-size: 1.06rem;
}

.meter {
  height: 9px;
  overflow: hidden;
  border: 1px solid rgba(255, 243, 214, 0.11);
  border-radius: 999px;
  background: rgba(255, 243, 214, 0.08);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--rose));
  transition: width 160ms ease;
}

.mala-orbit {
  position: relative;
  width: min(220px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
}

.mala-orbit::before,
.mala-orbit::after {
  position: absolute;
  inset: 13px;
  border: 1px solid rgba(242, 179, 61, 0.3);
  border-radius: 50%;
  content: "";
}

.mala-orbit::after {
  inset: 44px;
  border-color: rgba(55, 183, 170, 0.28);
}

.mala-beads {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.mala-beads span {
  position: absolute;
  left: calc(50% - 4px);
  top: calc(50% - 4px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 243, 214, 0.2);
  transform: rotate(calc(var(--i) * 10deg)) translateY(-99px);
  transform-origin: 4px 4px;
}

.mala-beads span.active {
  background: var(--gold);
  box-shadow: 0 0 18px rgba(242, 179, 61, 0.55);
}

.mala-center {
  position: absolute;
  inset: 52px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 243, 214, 0.14);
  border-radius: 50%;
  background: rgba(17, 20, 17, 0.84);
  text-align: center;
}

.mala-count {
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.mala-label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.reset-button {
  min-height: 44px;
  width: 100%;
  padding: 8px 12px;
  font-weight: 900;
}

.burst-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(242, 179, 61, 0.7);
  animation: spark 620ms ease-out forwards;
  transform: rotate(var(--a)) translateX(0);
}

.connect-stage {
  display: grid;
  min-height: inherit;
  place-items: center;
  padding: clamp(14px, 2.2vw, 24px);
}

.grid-wrap {
  position: relative;
  width: min(100%, var(--connect-board-size));
  aspect-ratio: 1;
}

.path-svg {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: visible;
  pointer-events: none;
}

.path-glow {
  fill: none;
  stroke: rgba(242, 179, 61, 0.28);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 24;
}

.path-line {
  fill: none;
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 8;
}

.tile-grid {
  position: relative;
  z-index: 3;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.2vw, 12px);
  touch-action: none;
  user-select: none;
}

.tile {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 1px solid rgba(255, 243, 214, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 243, 214, 0.14), rgba(255, 243, 214, 0.035)),
    rgba(20, 25, 19, 0.84);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 28px rgba(0, 0, 0, 0.22);
  color: var(--paper);
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: clamp(1.35rem, 2.8vw, 2.65rem);
  font-weight: 900;
  line-height: 1;
  transition: transform 85ms ease, border-color 85ms ease, background 85ms ease, box-shadow 85ms ease;
}

.tile.long {
  font-size: clamp(1rem, 1.9vw, 1.65rem);
  padding-inline: 6px;
}

.tile:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 243, 214, 0.34);
}

.tile.selected {
  color: #19140a;
  border-color: rgba(255, 241, 163, 0.72);
  background: linear-gradient(135deg, var(--gold), #ffe38f);
  box-shadow: 0 0 0 4px rgba(242, 179, 61, 0.16), 0 20px 34px rgba(242, 179, 61, 0.18);
  transform: translateY(-2px) scale(1.025);
}

.tile.right {
  background: linear-gradient(135deg, var(--teal), #b7ead8);
}

.tile.wrong {
  color: #fff8ea;
  background: linear-gradient(135deg, var(--rose), #e77f67);
  animation: nudge 150ms ease both;
}

.bubble-shell {
  display: grid;
  grid-template-columns: minmax(280px, 430px) 258px;
  justify-content: center;
}

.bubble-stage {
  min-height: min(780px, calc(100svh - 126px));
  width: min(430px, 100%);
  justify-self: center;
}

.river-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(55, 183, 170, calc(0.08 + var(--calm, 42) * 0.001)), transparent 52%),
    linear-gradient(90deg, rgba(70, 89, 121, 0.18), rgba(131, 185, 94, 0.12), rgba(242, 179, 61, 0.1));
}

.river-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: rgba(255, 243, 214, 0.2);
  pointer-events: none;
}

.river-art path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.river-token {
  position: absolute;
  z-index: 4;
  left: -52px;
  top: 0;
  min-width: 92px;
  min-height: 92px;
  touch-action: manipulation;
  user-select: none;
  border: 1px solid rgba(255, 243, 214, 0.22);
  border-radius: 999px;
  padding: 12px 16px;
  background:
    radial-gradient(circle at 31% 24%, rgba(255, 255, 255, 0.56), transparent 0.55rem),
    radial-gradient(circle at 68% 74%, rgba(55, 183, 170, 0.22), transparent 2.8rem),
    linear-gradient(145deg, rgba(255, 243, 214, 0.2), rgba(19, 24, 21, 0.72));
  box-shadow:
    inset 0 1px 8px rgba(255, 255, 255, 0.16),
    inset 0 -10px 20px rgba(55, 183, 170, 0.12),
    0 18px 34px rgba(0, 0, 0, 0.24);
  color: var(--paper);
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  will-change: transform, opacity;
}

.river-token::before {
  position: absolute;
  inset: -14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.001);
  content: "";
}

.river-token::after {
  position: absolute;
  inset: 14px auto auto 18px;
  width: 22px;
  height: 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  filter: blur(0.2px);
  pointer-events: none;
  content: "";
  transform: rotate(-24deg);
}

.river-token.long {
  min-width: 116px;
  font-size: 1.1rem;
}

.river-token.target {
  border-color: rgba(242, 179, 61, 0.58);
  background:
    radial-gradient(circle at 31% 24%, rgba(255, 255, 255, 0.62), transparent 0.6rem),
    radial-gradient(circle at 72% 78%, rgba(242, 179, 61, 0.26), transparent 3rem),
    linear-gradient(145deg, rgba(242, 179, 61, 0.34), rgba(19, 24, 21, 0.74));
}

.river-token.caught {
  pointer-events: none;
  background: linear-gradient(135deg, var(--teal), #d3f3e9);
  color: #101411;
  opacity: 0;
  transform: scale(1.3);
  transition: opacity 220ms ease, transform 220ms ease;
}

.river-token.missed {
  pointer-events: none;
  background: linear-gradient(135deg, var(--rose), var(--clay));
  opacity: 0;
  transition: opacity 220ms ease;
}

.unlock {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(17, 20, 17, 0.72);
  backdrop-filter: blur(12px);
}

.unlock.show {
  display: grid;
}

.unlock-panel {
  width: min(360px, 100%);
  border: 1px solid rgba(255, 243, 214, 0.24);
  border-radius: 8px;
  padding: 24px;
  background:
    conic-gradient(from 0deg, rgba(242, 179, 61, 0.2), rgba(55, 183, 170, 0.16), rgba(220, 94, 116, 0.14), rgba(242, 179, 61, 0.2)),
    rgba(20, 23, 18, 0.95);
  text-align: center;
  box-shadow: 0 34px 80px rgba(0, 0, 0, 0.44);
}

.unlock-title {
  margin: 0 0 4px;
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: 3.2rem;
  line-height: 1;
}

.unlock-mantra {
  margin: 0 0 18px;
  color: var(--gold);
  font-family: Georgia, "Noto Serif Devanagari", "Kohinoor Devanagari", serif;
  font-size: 2.1rem;
  font-weight: 900;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-5px);
  }
  70% {
    transform: translateX(5px);
  }
}

@keyframes spark {
  to {
    opacity: 0;
    transform: rotate(var(--a)) translateX(58px) scale(0.2);
  }
}

@media (max-width: 840px) {
  :root {
    --connect-board-size: clamp(304px, 86vw, 430px);
  }

  .topbar,
  .layout,
  .bubble-shell {
    grid-template-columns: 1fr;
  }

  .layout,
  .bubble-shell {
    display: flex;
    flex-direction: column;
  }

  .stage {
    order: -1;
    min-height: 500px;
  }

  .bubble-stage {
    min-height: min(760px, calc(100svh - 112px));
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    flex-direction: column;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
    font-size: 1.34rem;
  }

  .river-token {
    min-width: 84px;
    min-height: 84px;
    padding: 10px 13px;
    font-size: 1.22rem;
  }

  .river-token.long {
    min-width: 104px;
    font-size: 1rem;
  }
}
