:root {
  color-scheme: light;
  --bg-top: #e9fbff;
  --bg-bottom: #eefde9;
  --panel: linear-gradient(180deg, #85d9ff 0%, #66c8f3 100%);
  --panel-border: rgba(86, 183, 234, 0.55);
  --text: #29303a;
  --muted: #6e7a88;
  --accent: #ffb611;
  --accent-strong: #ef9b00;
  --cell: #ffe991;
  --cell-border: #ffb72d;
  --cell-active: #90d951;
  --cell-active-2: #d6f784;
  --cell-invalid: #ff8f81;
  --path-glow: rgba(160, 228, 77, 0.52);
  --path-core: rgba(167, 223, 67, 0.98);
  --shadow: 0 24px 50px rgba(83, 166, 198, 0.2);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--text);
  background:url('images/back.svg') no-repeat 50% 50% / cover;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vmin, 18px);
}

.game-shell {
  width: min(96vw, 96vh, 980px);
  min-width: min(96vw, 300px);
  min-height: min(96vh, 300px);
  height: min(96vh, 980px);
  /*background: var(--panel);
  border: 3px solid var(--panel-border);
  box-shadow: var(--shadow);*/
  border-radius: 40px;
  padding: clamp(12px, 2vmin, 20px);
  display: grid;
  grid-template-rows: 1fr;
  gap: clamp(8px, 1.5vmin, 14px);
  position: relative;
  overflow: hidden;
  align-items:center;
}
/*
.game-shell::before,
.game-shell::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.game-shell::before {
  inset: auto 0 0 0;
  height: 18%;
  background:
    radial-gradient(circle at 12% 100%, #9ada4a 0, #9ada4a 22%, transparent 23%),
    radial-gradient(circle at 30% 120%, #b9eb57 0, #b9eb57 23%, transparent 24%),
    radial-gradient(circle at 58% 118%, #a4df4a 0, #a4df4a 22%, transparent 23%),
    radial-gradient(circle at 88% 108%, #bceb5e 0, #bceb5e 20%, transparent 21%),
    linear-gradient(180deg, transparent 0 16%, #b8ec53 16%, #8bd03d 100%);
}

.game-shell::after {
  left: -4%;
  right: -4%;
  bottom: 11%;
  height: 16%;
  background:
    radial-gradient(circle at 10% 70%, rgba(255, 255, 255, 0.95) 0 20%, transparent 21%),
    radial-gradient(circle at 20% 78%, rgba(255, 255, 255, 0.95) 0 18%, transparent 19%),
    radial-gradient(circle at 86% 84%, rgba(255, 255, 255, 0.95) 0 20%, transparent 21%),
    radial-gradient(circle at 96% 74%, rgba(255, 255, 255, 0.95) 0 16%, transparent 17%);
  opacity: 0.82;
}
*/
.topbar {
  position: relative;
  z-index: 2;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position:absolute;
  z-index:3;
}

.level-pill,
.icon-button,
.primary-button {
  border-radius: 24px;
}

.level-pill {
  position:absolute; left:10px; top:10px; z-index:3;
}
#resetButton { width:80px; height:80px; border-radius:60px; box-shadow:0 10px 20px rgba(0,0,0,.2); display:grid; background: linear-gradient(to bottom,  #FCC005 0%,#FEAB06 100%); border:2px solid #FF9100; justify-content: center; align-items: center; cursor:pointer; }
	#resetButton > div { border-top:4px solid #FEDF5E; border-bottom:4px solid #FD9C06; border-radius:50px; position:relative; width: 80px; height: 72px; display: grid; justify-content: center; align-items: center; }
		#resetButton > div > img { width: 70px; height: 67px; max-width: 100%; position: absolute; left: 7px; top: 0px; z-index:2; }

#levelNumber { font-size: 18px; font-weight: bold; color: #fff; font-family: Tahoma, sans-serif; text-shadow:0 4px 4px rgba(0,0,0,.2); }

.sound-button { width:80px; height:80px; border-radius:60px; box-shadow:0 10px 20px rgba(0,0,0,.2); display:grid; background: linear-gradient(to bottom,  #5c92ed 0%,#507ee8 100%); border:2px solid #355FD9; justify-content: center; align-items: center; overflow:hidden; cursor:pointer; position: absolute; top: 10px; right: 10px; z-index: 3; }
	.sound-button > div { border-top:4px solid #9BBEFD; border-bottom:4px solid #4974E4; border-radius:50px; position: relative; width: 80px; height: 76px; top: -1px;}
		.sound-button > div > div { width:60px; height:60px; max-width:100%; position:absolute; left: 10px; top: 4px; z-index:2; background:url('images/sound-on.svg') no-repeat 50% 50% / cover; }
		.sound-button.muted > div > div { background:url('images/sound-off.svg') no-repeat 50% 50% / cover; }


.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.primary-button {
  border: none;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, opacity 140ms ease, box-shadow 160ms ease;
}

.icon-button:hover,
.primary-button:hover
{
  opacity:0.9;
}

.sound-button:hover {
	opacity:0.8;
}

.icon-button {
  width: 68px;
  height: 68px;
  font-size: 2rem;
  color: #fff;
}

.primary-button {
  min-width: 104px;
  padding: 0px 16px;
  color: #fff;
  font-weight: 700;
  
  position: absolute;
  width: 200px;
  height: 50px;
  right: 10px;
  z-index: 999;
  bottom: 20px;
  background: #C5DD64;
  border-top: 2px solid rgba(255,255,255,.5);
  box-shadow: 0 6px 5px rgba(0,0,0,.2);
  font-size: 40px;
  line-height: 22px;
  cursor: pointer;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.hidden {
  display: none;
}

.board-wrap {
  position: relative;
  z-index: 2;
  min-height: 0;
  display: grid;
  place-items: center;
  height: 100%;
}

.board {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  position: relative;
  border-radius: 40px;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 251, 244, 0.95), rgba(255, 255, 255, 0.86) 42%, rgba(248, 245, 240, 0.98) 100%);
  border: 8px solid rgba(255, 245, 236, 0.92);
  box-shadow:
    inset 0 -14px 30px rgba(215, 204, 196, 0.16),
    0 16px 30px rgba(88, 149, 192, 0.12);
  overflow: hidden;
  touch-action: none;
}

.board.transitioning {
  pointer-events: none;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 16%, transparent 82%, rgba(236, 229, 223, 0.2) 100%);
  pointer-events: none;
}

.path-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.path-segment {
  position: absolute;
  transform-origin: left center;
  border-radius: 999px;
  background: #C5DD64;
  opacity: 1;
  border: 2px solid #A5C25F;
  transition: left 80ms linear, top 80ms linear, width 80ms linear, height 80ms linear, transform 80ms linear;
}

.cell {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  border-radius:20%;
  border: 2px solid #CFCDC1;
  background: #F0ECDC;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    transform 120ms ease,
    box-shadow 140ms ease,
    filter 140ms ease;
}

.cell::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: #C5DD64;
  border: 2px solid #A5C25F;
  box-shadow: inset 0 -3px 0 rgba(237, 179, 38, 0.35);
  transition: transform 150ms ease, background-color 150ms ease, opacity 150ms ease;
  display:none;
}

.cell.active {
  border-radius:10px;
  border:2px solid #F6AE38;
  background:#FFF2BD;
}

.cell.active::after {
  display:block;
}

.cell.invalid {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.4), transparent 48%),
    linear-gradient(180deg, #ffd1ca 0%, var(--cell-invalid) 100%);
  border-color: #ff7463;
  transform: scale(0.96);
  box-shadow:
    inset 0 -6px 0 rgba(231, 91, 91, 0.28),
    0 10px 24px rgba(235, 99, 84, 0.24);
  animation: invalidShake 220ms ease;
}

.cell.current {
  animation: currentPulse 1.35s ease-in-out infinite;
  filter: saturate(1.05);
  border: 2px solid #A5C25F;
  background:#D4E9A4;;
}

.cell.current::after {
  opacity: 1;
  background:#fff;
}

.board.success .cell {
  animation: pulseWin 3000ms linear infinite;
}

.board.success .path-segment {
  animation: victoryTrail 720ms ease;
}

.sound-button.muted {
  opacity: 0.62;
}

.transition-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(255, 250, 236, 0.18), rgba(255, 250, 236, 0.82)),
    linear-gradient(180deg, rgba(160, 223, 255, 0.2), rgba(244, 252, 239, 0.88));
  opacity: 0;
  transition: opacity 280ms ease;
  z-index: 2;
}

.transition-overlay.visible {
  opacity: 1;
}

.transition-card {
  min-width: min(70vw, 260px);
  padding: 22px 28px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 246, 228, 0.96));
  border: 3px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 18px 36px rgba(58, 67, 48, 0.12);
  transform: translateY(16px) scale(0.96);
  transition: transform 320ms ease;
}

.transition-overlay.visible .transition-card {
  transform: translateY(0) scale(1);
}

.transition-kicker {
  margin: 0 0 8px;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7f8a96;
}

#transitionLevel {
  font-size: clamp(2rem, 8vmin, 4rem);
  line-height: 1;
  color: #ff9c00;
}

.confetti-piece {
  position: absolute;
  z-index: 3;
  width: 10px;
  height: 16px;
  border-radius: 999px;
  top: 8%;
  opacity: 0.92;
  animation: confettiFall 3000ms ease-out forwards;
  pointer-events: none;
}

@keyframes pulseWin {
  0%,
  100% {
	transform: scale(1);
	transform: rotate(0);
  }
  25% {
	transform: scale(1.1);
	transform: rotate(10deg);
  }
  50% {
	transform: scale(1);
	transform: rotate(0deg);
  }
  75% {
	transform: scale(0.9);
	transform: rotate(-10deg);
  }
}

@keyframes currentPulse {
  0%,
  45%,
  55%,
  100% {
    transform: rotate(0);
  }
  47% {
	  transform: rotate(5deg);
  }
  53% {
    transform: rotate(-5deg);
  }
}

@keyframes trailFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.95;
  }
}

@keyframes victoryTrail {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.25);
  }
}

@keyframes invalidShake {
  0%,
  100% {
    transform: scale(0.96) translateX(0);
  }
  25% {
    transform: scale(0.96) translateX(-2px);
  }
  75% {
    transform: scale(0.96) translateX(2px);
  }
}

@keyframes confettiFall {
  from {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  to {
    transform: translate3d(var(--drift), calc(100% + 120px), 0) rotate(var(--spin));
    opacity: 0.1;
  }
}
/*
@media (orientation: portrait) {
  .game-shell {
    width: min(98vw, 760px);
    height: min(98vh, 1100px);
  }
}*/

@media (max-width: 480px), (max-height: 480px) {
	.app { padding:4px; }
  .game-shell {
    border-radius: 28px;
    gap: 6px;
	padding:4px;
  }
  .primary-button {
    padding: 10px 14px;
    min-width: 88px;
  }

  .cell {
    border-width: 1px;
  }

  .transition-card {
    min-width: 0;
    width: calc(100% - 28px);
    padding: 18px 20px;
  }
}

@media (max-width: 960px) {
	.level-pill { position: absolute; left: 0; top: 0; }
	#resetButton { width: 50px; height: 50px; border-radius: 0 0 20px 0; }
	#resetButton > div { border: 0; border-radius: 0; width: 40px; height: 40px; }
	#resetButton > div > img { width: 40px; height: 40px; left: 0px; }
	#levelNumber { font-size: 18px; color: #fff; position: relative; left: -2px; top: 34px; z-index: 4; }
	
	.sound-button { top: 0; right: 0; border-radius: 0 0 0 20px; width: 50px; height: 50px; }
	.sound-button > div { border: 0;width: 40px;height: 40px;border-radius: 0; }
	.sound-button > div > div { width: 40px; height: 40px; left: 1px; top: 1px; }
}

@media (max-width: 360px) {
	.game-shell { min-width: min(96vw, 200px); min-height: min(96vh, 200px); }
}
