:root {
  --bg: #f6f1e7;
  --ink: #2a2a33;
  --muted: rgba(42, 42, 51, .6);
  --green: #5fb85a;
  --blue: #3c8fd6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #e9e2d4;
  color: var(--ink);
  font-family: Rubik, system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

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

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  border-radius: 12px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(246, 241, 231, .78);
  backdrop-filter: blur(3px);
  border-radius: 12px;
}

[hidden] { display: none !important; }

h1 {
  margin: 0;
  font-weight: 800;
  font-size: clamp(36px, 8vw, 84px);
  letter-spacing: -.02em;
}

.sub { margin: 0; max-width: 520px; color: var(--muted); font-size: clamp(13px, 2vw, 17px); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 8px; }
.note { margin: 0; min-height: 1em; font-size: 13px; color: #b5473f; }
.keys { margin: 0; font-size: 13px; color: var(--muted); }
h2 { margin: 0; font-weight: 800; font-size: 32px; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  max-width: 460px;
  width: 100%;
}
.level-grid button {
  padding: 0;
  aspect-ratio: 1;
  font-size: 14px;
  background: rgba(42, 42, 51, .1);
  color: var(--ink);
  box-shadow: none;
  border-radius: 8px;
}
.level-grid button.done { background: var(--green); color: #fff; }
.level-grid button.current { outline: 3px solid var(--ink); outline-offset: -3px; }
#levels { z-index: 2; }

button {
  font: inherit;
  font-weight: 500;
  border: 0;
  border-radius: 12px;
  padding: 12px 22px;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
button:disabled { opacity: .45; cursor: default; }
button.alt { background: var(--blue); }
button.ghost { background: rgba(42, 42, 51, .08); color: var(--ink); box-shadow: none; }

#hud {
  position: absolute;
  z-index: 1;
  top: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
#hud button { padding: 6px 12px; font-size: 14px; }

#status, #toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  max-width: calc(100% - 32px);
  text-align: center;
}
#status { top: 45%; }
#toast { bottom: 16px; }

#touch { display: none; }
@media (pointer: coarse) {
  #touch {
    position: fixed;
    inset: auto 16px 16px 16px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
  }
  #touch div { display: flex; gap: 12px; }
  #touch button {
    pointer-events: auto;
    width: 64px; height: 64px;
    padding: 0;
    font-size: 24px;
    background: rgba(42, 42, 51, .25);
    box-shadow: none;
  }
  #hud { font-size: 12px; }
}

/* В редакторе канвас сжимается, панель стоит под ним. */
body.editing { place-items: start center; }
body.editing #stage { width: min(100vw, calc((100vh - var(--edh)) * 16 / 9)); }
body { --edh: 230px; }
#editor {
  position: fixed;
  z-index: 2;
  left: 0; right: 0; bottom: 0;
  height: var(--edh);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(246, 241, 231, .94);
  border-top: 2px solid rgba(42, 42, 51, .12);
  font-size: 14px;
}
.ed-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#editor button { padding: 6px 12px; font-size: 14px; }
#editor input, #editor select {
  font: inherit;
  font-size: 14px;
  padding: 5px 8px;
  border: 2px solid rgba(42, 42, 51, .15);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
#ed-name { width: 180px; font-weight: 500; }
#ed-saved { max-width: 220px; }
#ed-items { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border-radius: 10px;
  background: #fff;
  border-left: 5px solid var(--c);
}
.chip select { padding: 2px 4px !important; }
.chip-T, .add-T { --c: #545873; }
.chip-G, .add-G { --c: #e0574f; }
.chip-P, .add-P { --c: #8a7fd6; }
.chip-R, .add-R { --c: #f2b84b; }
#ed-add button { border-left: 5px solid var(--c); }
.chip-tools { display: flex; gap: 2px; }
#editor .chip-tools button { padding: 2px 7px; background: rgba(42, 42, 51, .08); color: var(--ink); box-shadow: none; }
.ed-foot { justify-content: space-between; }
#ed-code { font-size: 12px; color: var(--muted); }
.ed-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
#editor select { max-width: 100%; }
.ed-key { display: flex; align-items: center; gap: 6px; min-width: 0; }
