:root {
  --ink: #101b34;
  --ink-soft: #31415f;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --glass: rgba(255, 255, 255, 0.24);
  --line: rgba(255, 255, 255, 0.56);
  --primary: #3d7cff;
  --primary-dark: #1742b6;
  --accent: #ffd34d;
  --success: #27d17f;
  --warning: #ff9f43;
  --danger: #ff4d6d;
  --pipe: #23d18b;
  --boss: #d948ff;
  --shadow: rgba(13, 24, 48, 0.28);
  --radius: 22px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(117, 245, 255, 0.42), transparent 24%),
    radial-gradient(circle at 86% 82%, rgba(255, 211, 77, 0.32), transparent 22%),
    linear-gradient(135deg, #081a3a 0%, #114d8f 42%, #25b6c9 100%);
  color: var(--ink);
  font-family: "Arial", "Noto Sans Hebrew", "Segoe UI", sans-serif;
}

body {
  display: grid;
  place-items: center;
}

.shell {
  position: relative;
  width: min(100vw, 1120px);
  aspect-ratio: 16 / 9;
  max-height: 100vh;
  background: #78d9ff;
  border: 1px solid rgba(255,255,255,0.62);
  border-radius: 26px;
  box-shadow:
    0 24px 70px rgba(2, 9, 28, 0.42),
    0 0 0 8px rgba(255,255,255,0.08),
    inset 0 0 0 2px rgba(255,255,255,0.28);
  overflow: hidden;
}

.shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255,255,255,0.18), transparent 28%, transparent 72%, rgba(255,255,255,0.10)),
    radial-gradient(circle at 50% 0, rgba(255,255,255,0.18), transparent 42%);
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #8bdcff;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 16% 18%, rgba(255, 211, 77, 0.35), transparent 20%),
    radial-gradient(circle at 78% 20%, rgba(35, 209, 139, 0.32), transparent 18%),
    radial-gradient(circle at 82% 82%, rgba(217, 72, 255, 0.28), transparent 20%),
    linear-gradient(145deg, rgba(8, 24, 60, 0.88), rgba(19, 94, 160, 0.84));
  text-align: center;
  z-index: 2;
  animation: overlayIn 220ms ease-out;
}

.overlay::before,
.overlay::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 34px;
  border: 22px solid rgba(255,255,255,0.08);
  transform: rotate(18deg);
  pointer-events: none;
}

.overlay::before {
  right: -70px;
  top: 38px;
}

.overlay::after {
  left: -58px;
  bottom: 26px;
  border-color: rgba(255, 211, 77, 0.14);
  transform: rotate(-22deg);
}

@keyframes overlayIn {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: scale(1); }
}

.overlay.hidden,
.scoreBoard,
.howToBox,
.nameEntry {
  display: none;
}

.scoreBoard.open,
.howToBox.open,
.nameEntry.open {
  display: grid;
}

.panel {
  width: min(92%, 580px);
  max-height: 94vh;
  overflow: auto;
  position: relative;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.97), rgba(230, 247, 255, 0.9)),
    var(--panel-strong);
  box-shadow:
    0 22px 55px rgba(2, 9, 28, 0.32),
    inset 0 1px 0 rgba(255,255,255,0.95);
  backdrop-filter: blur(14px);
  z-index: 1;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: calc(var(--radius) - 8px);
  border: 1px solid rgba(61,124,255,0.12);
  pointer-events: none;
}

.panel.wide,
.levelPanel {
  width: min(94%, 910px);
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(38px, 6vw, 72px);
  line-height: 1.02;
  color: #102650;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(255,255,255,0.8), 0 14px 30px rgba(61,124,255,0.24);
}

h2 {
  margin: 0 0 8px;
  color: #102650;
}

.titleRow {
  display: grid;
  gap: 12px;
  justify-items: center;
  margin-bottom: 10px;
}

.titleMark {
  width: 88px;
  height: 68px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.7);
  background:
    linear-gradient(145deg, rgba(255,255,255,0.55), transparent 28%),
    linear-gradient(#61e887 0 30%, #b77236 30% 100%);
  box-shadow: 0 14px 28px rgba(23,43,77,0.24), inset -10px -10px 0 rgba(13,24,48,0.10);
  position: relative;
  transform: rotate(-4deg);
}

.titleMark::before,
.titleMark::after {
  content: "";
  position: absolute;
  background: #102650;
  border-radius: 999px;
}

.titleMark::before {
  width: 10px;
  height: 10px;
  right: 25px;
  top: 31px;
  box-shadow: -24px 0 0 #102650;
}

.titleMark::after {
  width: 30px;
  height: 6px;
  right: 28px;
  top: 48px;
  background: #704016;
}

.metaRow {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 13px;
  border: 1px solid rgba(61,124,255,0.22);
  border-radius: 999px;
  background: rgba(255,255,255,0.74);
  color: #17345f;
  font-weight: 900;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
}

.panel p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: clamp(16px, 2.2vw, 21px);
  line-height: 1.55;
}

button,
.menuLink {
  min-width: 188px;
  min-height: 50px;
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.68);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.34), transparent 46%),
    linear-gradient(135deg, #ffd34d, #ff9f43);
  color: #102650;
  font: 900 18px/1 Arial, "Noto Sans Hebrew", sans-serif;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 12px 26px rgba(255,159,67,0.34), 0 4px 0 rgba(133,79,0,0.45);
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
}

button::after,
.menuLink::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.38), transparent);
  transform: translateX(110%);
  transition: transform 420ms ease;
}

button:hover,
.menuLink:hover {
  filter: brightness(1.06);
  transform: translateY(-2px);
  box-shadow: 0 16px 30px rgba(255,159,67,0.42), 0 6px 0 rgba(133,79,0,0.45);
}

button:hover::after,
.menuLink:hover::after {
  transform: translateX(-110%);
}

button:focus-visible,
.menuLink:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(35,209,139,0.8);
  outline-offset: 3px;
}

button:active,
.menuLink:active {
  transform: translateY(3px);
  box-shadow: 0 8px 20px rgba(255,159,67,0.32), 0 2px 0 rgba(133,79,0,0.45);
}

button[disabled] {
  opacity: 0.55;
  filter: grayscale(0.75);
  cursor: not-allowed;
  box-shadow: none;
}

.buttonStack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(188px, 1fr));
  gap: 12px;
  justify-items: center;
  align-items: center;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  text-align: right;
}

.controlItem,
.levelCard {
  border: 1px solid rgba(61,124,255,0.16);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: rgba(232, 247, 255, 0.82);
  color: #24334f;
  font-size: 14px;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 20px 0;
  text-align: right;
}

.levelCard {
  min-height: 168px;
  display: grid;
  gap: 8px;
  align-content: start;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(255,255,255,0.82), transparent 26%),
    linear-gradient(145deg, rgba(255,255,255,0.92), rgba(226,240,255,0.82));
  box-shadow: 0 12px 24px rgba(13,24,48,0.12);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.levelCard::before {
  content: "";
  position: absolute;
  inset-inline-start: -34px;
  bottom: -44px;
  width: 120px;
  height: 120px;
  border: 18px solid rgba(61,124,255,0.10);
  border-radius: 24px;
  transform: rotate(18deg);
}

.levelCard:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 32px rgba(13,24,48,0.18);
}

.levelCard h2 {
  position: relative;
  margin: 0;
  font-size: 18px;
}

.levelCard p {
  position: relative;
  margin: 0;
  font-size: 13px;
}

.levelCard button {
  position: relative;
  min-width: 132px;
  min-height: 40px;
  font-size: 15px;
  justify-self: start;
}

.levelCard.completed {
  background: linear-gradient(145deg, rgba(224,255,236,0.96), rgba(190,245,220,0.88));
}

.levelCard.completed::after {
  content: "✓";
  position: absolute;
  left: 16px;
  top: 12px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--success);
  color: white;
  font-weight: 900;
}

.levelCard.progressCard {
  grid-column: span 2;
  min-height: 132px;
  background:
    radial-gradient(circle at 82% 16%, rgba(255,255,255,0.9), transparent 24%),
    linear-gradient(135deg, rgba(38,247,177,0.2), rgba(255,215,82,0.16)),
    linear-gradient(145deg, rgba(255,255,255,0.94), rgba(226,240,255,0.84));
}

.levelNumber {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-left: 8px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: 0 10px 24px rgba(61, 124, 255, 0.24);
}

.themeIcon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-left: 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.levelCard.locked {
  background: linear-gradient(145deg, rgba(237,241,248,0.92), rgba(207,216,229,0.82));
  color: #647085;
}

.scoreBoard,
.howToBox {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid rgba(61,124,255,0.16);
  border-radius: var(--radius-sm);
  background: rgba(255, 247, 215, 0.78);
  text-align: right;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.scoreBoard ol {
  margin: 0;
  padding: 0 24px 0 0;
  line-height: 1.8;
  font-weight: 900;
}

.nameEntry {
  gap: 10px;
  justify-items: center;
  margin: 16px 0;
}

input {
  width: min(100%, 280px);
  min-height: 44px;
  border: 1px solid rgba(61,124,255,0.24);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255,255,255,0.88);
  color: var(--ink);
  font: 800 18px Arial, "Noto Sans Hebrew", sans-serif;
  text-align: center;
  box-shadow: inset 0 2px 8px rgba(13,24,48,0.08);
}

.miniText,
.credit,
.saveMessage {
  color: #31455f;
  font-size: 14px;
  font-weight: 900;
}

@media (max-width: 700px) {
  .controls,
  .levelGrid,
  .buttonStack {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 22px;
  }

  .levelCard.progressCard {
    grid-column: auto;
  }
}
