:root {
  --bg: #06070c;
  --bg-2: #0b0e18;
  --panel: #0c0f19;
  --line: rgba(170, 186, 255, 0.12);
  --line-2: rgba(170, 186, 255, 0.24);
  --text: #e9ecf8;
  --text-2: #aab1c8;
  --text-3: #8890aa;
  --red: #ff4b5c;
  --green: #3dff8a;
  --blue: #4a8dff;
  --display: "Tektur", "Onest", system-ui, sans-serif;
  --ui: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(90% 70% at 35% 45%, rgba(40, 56, 120, 0.22) 0%, rgba(6, 7, 12, 0) 60%),
    radial-gradient(60% 60% at 80% 90%, rgba(120, 30, 90, 0.12) 0%, rgba(6, 7, 12, 0) 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 1fr 372px;
  height: 100vh;
}

.stage { position: relative; min-width: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Панель ---------- */
.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 30px 22px;
  background: linear-gradient(180deg, rgba(14, 18, 30, 0.96), rgba(9, 11, 19, 0.98));
  border-left: 1px solid var(--line);
  overflow-y: auto;
}
.panel > * { flex-shrink: 0; }      /* не сжимать блоки — лучше прокрутка, чем наложение */
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(92deg, #ff6b78 0%, #ffe46b 38%, #53ffa0 62%, #5d9cff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { margin: 6px 0 0; color: var(--text-2); font-size: 15px; }

.level-head { display: flex; align-items: baseline; gap: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.lvnum { font-family: var(--display); font-size: 30px; font-weight: 500; font-variant-numeric: tabular-nums; }
.lvnum .of { font-size: 15px; color: var(--text-3); margin-left: 4px; }
.level-head h2 { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.15; }
.lvtext { margin: -6px 0 0; color: var(--text-2); font-size: 15px; line-height: 1.5; min-height: 1.5em; }

.targets { display: flex; flex-wrap: wrap; gap: 8px; }
.tchip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-2);
  transition: border-color 0.3s ease, color 0.3s ease;
}
.tchip i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; }
.tchip.ok { color: var(--text); border-color: var(--line-2); }

.label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
}
.tray { display: flex; flex-wrap: wrap; gap: 10px; min-height: 76px; }
.piece {
  position: relative;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  cursor: grab;
  touch-action: none;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}
.piece:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.04); }
.piece[aria-pressed="true"] { border-color: rgba(255, 255, 255, 0.55); background: rgba(255, 255, 255, 0.06); }
.piece:active { transform: scale(0.96); }
.piece.empty { opacity: 0.3; cursor: default; }
.piece canvas { width: 56px; height: 56px; pointer-events: none; }
.piece .cnt {
  position: absolute;
  right: 5px;
  bottom: 4px;
  font-family: var(--display);
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.piece .nm {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}
.tray-wrap .tip { margin: 26px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-3); }
.tray-wrap { padding-bottom: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px 0 13px;
  border: 1px solid var(--line-2);
  border-radius: 21px;
  background: transparent;
  color: var(--text);
  font: 500 14px/1 var(--ui);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.35); }
.btn:active { transform: scale(0.97); }
.btn.icon { width: 42px; padding: 0; justify-content: center; }
.btn.primary { background: #f3f5ff; color: #0a0c14; border-color: #f3f5ff; font-weight: 600; padding: 0 22px; }
.btn.primary:hover { background: #ffffff; }
button:focus-visible, summary:focus-visible { outline: 2px solid #9bb8ff; outline-offset: 3px; }

.rules { margin-top: auto; border-top: 1px solid var(--line); padding-top: 14px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.rules summary { cursor: pointer; color: var(--text); font-weight: 500; list-style: none; display: flex; align-items: center; gap: 8px; min-height: 32px; }
.rules summary::-webkit-details-marker { display: none; }
.rules summary::before { content: ""; width: 7px; height: 7px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: rotate(-45deg); transition: transform 0.25s ease; }
.rules[open] summary::before { transform: rotate(45deg); }
.rules ul { margin: 8px 0 0; padding-left: 18px; }
.rules li { margin: 4px 0; }
.rules b { color: var(--text); font-weight: 600; }

/* ---------- Оверлеи ---------- */
.win, .levels {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 10, 0.55);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.win.show, .levels.show { opacity: 1; }
.win[hidden], .levels[hidden] { display: none; }
.win-card, .levels-card {
  background: #0d1120;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.6);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.2, 1);
}
.win.show .win-card, .levels.show .levels-card { transform: none; }
.win-card { padding: 30px 34px 28px; text-align: center; min-width: 320px; }
.win-card .kicker { margin: 0; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-3); font-weight: 600; }
.win-card h2 { margin: 8px 0 6px; font-family: var(--display); font-weight: 500; font-size: 30px; }
.win-card p { margin: 0 0 20px; color: var(--text-2); }

.levels-card { width: min(640px, calc(100vw - 32px)); padding: 24px 26px 22px; }
.levels-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.levels-head h2 { margin: 0; font-family: var(--display); font-weight: 500; font-size: 26px; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.lvbtn {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font: 500 19px/1 var(--display);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.lvbtn:hover { background: rgba(255, 255, 255, 0.07); }
.lvbtn.done { border-color: rgba(83, 255, 160, 0.45); }
.lvbtn.done::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 8px;
  width: 6px;
  height: 10px;
  border-right: 2px solid var(--green);
  border-bottom: 2px solid var(--green);
  transform: rotate(45deg);
}
.lvbtn.cur { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.6); }
.note { margin: 16px 0 0; color: var(--text-3); font-size: 13px; line-height: 1.45; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 30;
  transform: translate(-50%, 8px);
  padding: 10px 18px;
  background: #151a2b;
  border: 1px solid var(--line-2);
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 821px) { .toast { left: calc((100vw - 372px) / 2); } }   /* по центру под полем, а не окна */

/* ---------- Телефон ---------- */
@media (max-width: 820px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; grid-template-rows: 50svh auto; height: auto; min-height: 100svh; }
  /* на телефоне сначала то, чем играют: уровень, лоток, кнопки; объяснения — ниже */
  .panel { border-left: 0; border-top: 1px solid var(--line); padding: 14px 16px 24px; gap: 12px; }
  .brand { order: 0; display: flex; align-items: baseline; gap: 10px; }
  .brand h1 { font-size: 22px; }
  .brand p { margin: 0; font-size: 14px; }
  .level-head { order: 1; padding-top: 10px; }
  .lvnum { font-size: 22px; }
  .level-head h2 { font-size: 18px; }
  .tray-wrap { order: 2; padding-bottom: 18px; }
  .tray-wrap .label { display: none; }
  .tray-wrap .tip { display: none; }
  .actions { order: 3; gap: 6px; }
  .actions .btn { flex: 1 1 auto; justify-content: center; padding: 0 10px; font-size: 13px; }
  #soundBtn { position: absolute; top: 10px; right: 12px; }
  .targets { order: 4; }
  .lvtext { order: 5; margin: 0; }
  .rules { order: 6; margin-top: 6px; }
  .piece { width: 60px; height: 60px; }
  .piece canvas { width: 46px; height: 46px; }
  .grid { grid-template-columns: repeat(4, 1fr); }
}
