:root {
  --ink: #17353d;
  --panel-soft: rgba(255, 255, 255, 0.6);
  --panel-softer: rgba(255, 255, 255, 0.38);
  --line-soft: rgba(255, 255, 255, 0.5);
  --shadow: 0 12px 28px rgba(10, 46, 52, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100dvh;
}

body {
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 232, 172, 0.7), transparent 22%),
    radial-gradient(circle at 88% 82%, rgba(192, 244, 226, 0.65), transparent 23%),
    linear-gradient(180deg, #b9e5ec 0%, #e6f2ce 56%, #d4f0e4 100%);
}

.app-shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.top-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
  backdrop-filter: blur(2px);
  box-shadow: var(--shadow);
}

.top-menu h1 {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1;
}

.logo-trigger {
  border: 0;
  background: transparent;
  font-size: 1.3em;
  cursor: pointer;
  padding: 0 6px 0 0;
}

.menu-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 9px 14px;
  font-family: "Baloo 2", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #24474f;
  background: #f2f9fb;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.btn:hover {
  filter: brightness(0.97);
}

.btn.warm {
  background: #ffe3b6;
}

.btn.mint {
  background: #cef4e9;
}

.status-overlay {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.19);
  border: 1px solid rgba(255, 255, 255, 0.32);
  backdrop-filter: blur(1px);
}

.status-item {
  border-radius: 10px;
  padding: 8px 9px;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
}

.game-wrap {
  position: relative;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
  background: rgba(255, 255, 255, 0.2);
}

.zen-panel {
  position: absolute;
  top: 72px;
  right: 14px;
  width: min(460px, 94vw);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  z-index: 20;
  backdrop-filter: blur(2px);
}

.zen-panel h3 {
  margin: 0 0 8px;
  font-family: "Baloo 2", sans-serif;
}

.zen-option {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-family: "Baloo 2", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1f4d56;
  cursor: pointer;
}

.zen-drag-handle {
  cursor: move;
  user-select: none;
}

#zenOutput {
  width: 100%;
  border: 1px solid #c6dce3;
  border-radius: 10px;
  padding: 8px;
  font: inherit;
  margin-top: 8px;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#gameCanvas:active {
  cursor: grabbing;
}

.hint-dialog {
  border: 0;
  border-radius: 16px;
  width: min(700px, 94vw);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.hint-dialog::backdrop {
  background: rgba(13, 56, 63, 0.32);
}

.hint-dialog h2 {
  margin: 8px 0;
  font-family: "Baloo 2", sans-serif;
}

.hint-dialog p {
  margin: 8px 0;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.welcome-dialog {
  border: 0;
  border-radius: 16px;
  width: min(760px, 94vw);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
}

.welcome-dialog::backdrop {
  background: rgba(15, 68, 74, 0.45);
}

.welcome-dialog h2 {
  margin: 8px 0 6px;
  font-family: "Baloo 2", sans-serif;
}

.welcome-cta {
  font-weight: 800;
  color: #1f4d56;
}

.score-name {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  font-weight: 700;
}

.score-name input {
  border: 1px solid #c6dce3;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}

.high-score-list {
  margin: 8px 0 0;
  padding-left: 22px;
  max-height: 180px;
  overflow: auto;
  background: #f2fbf8;
  border-radius: 10px;
}

.high-score-list li {
  margin: 4px 0;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-right: 8px;
}

.seed-btn {
  border: 0;
  border-radius: 8px;
  padding: 3px 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: #1f4f58;
  background: #d9f2ea;
  cursor: pointer;
}

.hint-list {
  max-height: 44vh;
  overflow: auto;
  border-radius: 10px;
  padding: 10px;
  background: #edf9f4;
  white-space: pre-wrap;
}

#zenLog {
  max-height: 7.5em;
  overflow-y: auto;
}

.levels-dialog {
  width: min(760px, 94vw);
}

.levels-tabs {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.levels-tab {
  border: 1px solid rgba(69, 119, 108, 0.25);
  background: #edf9f4;
}

.levels-tab.active {
  background: linear-gradient(180deg, #b4e8d8 0%, #d4f6eb 100%);
  border-color: rgba(36, 100, 88, 0.35);
}

.levels-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
  max-height: 50vh;
  overflow: auto;
}

.level-tile {
  display: grid;
  place-items: center;
  gap: 8px;
  aspect-ratio: 1 / 1;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: #edf9f4;
  border: 1px solid rgba(69, 119, 108, 0.12);
  color: #1f4d56;
  cursor: pointer;
  text-align: center;
  font: inherit;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
}

.level-tile:hover {
  filter: brightness(0.98);
}

.level-number {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(1.9rem, 4vw, 2.7rem);
  font-weight: 800;
  line-height: 1;
}

.level-time {
  font-size: 0.92rem;
  font-weight: 700;
  color: #3d6971;
}

.level-empty {
  margin: 0;
  grid-column: 1 / -1;
  padding: 14px;
  border-radius: 12px;
  background: #edf9f4;
}

.level-tile.infinity {
  background: linear-gradient(180deg, #ffe8bc 0%, #fff4d9 100%);
}

.level-tile.impossible {
  background: linear-gradient(180deg, #ffd7ce 0%, #ffe8e2 100%);
  border-color: rgba(139, 63, 45, 0.2);
}

.level-tile.played {
  background: linear-gradient(180deg, #d9e9ff 0%, #edf4ff 100%);
  border-color: rgba(49, 91, 155, 0.24);
}

@media (max-width: 680px) {
  .levels-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .app-shell {
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .top-menu {
    border-radius: 14px;
  }

  .status-item {
    font-size: 0.93rem;
  }

  .top-menu {
    gap: 8px;
    padding: 8px 10px;
  }

  .menu-buttons {
    gap: 6px;
  }

  .btn {
    padding: 8px 10px;
    font-size: 0.93rem;
  }

  .status-overlay {
    left: 6px;
    right: 6px;
    bottom: 6px;
    gap: 6px;
    padding: 6px;
  }
}

@media (orientation: portrait) and (max-width: 680px) {
  .top-menu h1 {
    width: 100%;
    text-align: center;
    font-size: 1.25rem;
  }

  .menu-buttons {
    width: 100%;
    justify-content: center;
  }
}
