:root {
      --text: #f9fafb;
      --muted: #9ca3af;
      --accent: #38bdf8;
      --ok: #22c55e;
      --danger: #fb7185;
      --warn: #facc15;
      --panel: rgba(31, 41, 55, 0.96);
      --card: #111827;
      --white-count: 8;
    }

    * {
      box-sizing: border-box;
      -webkit-tap-highlight-color: transparent;
      user-select: none;
    }

    html, body {
      margin: 0;
      width: 100%;
      height: 100%;
      min-height: 100dvh;
      overflow: hidden;
      background: radial-gradient(circle at top, #1f2937, #020617);
      color: var(--text);
      font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      overscroll-behavior: none;
    }

    body {
      display: flex;
      flex-direction: column;
      height: 100dvh;
      padding: 8px;
      gap: 8px;
      touch-action: none;
    }

    .topbar {
      position: relative;
      z-index: 5;
      flex: 0 0 auto;
      background: var(--panel);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 18px;
      padding: 9px;
      display: grid;
      gap: 8px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.35);
      max-height: min(58dvh, 455px);
      overflow-y: auto;
      overflow-x: hidden;
      overscroll-behavior: contain;
      -webkit-overflow-scrolling: touch;
      touch-action: pan-y;
    }

    .title {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 10px;
    }

    .title h1 {
      margin: 0;
      font-size: 18px;
      letter-spacing: 0.2px;
      line-height: 1.12;
    }

    .status {
      color: var(--muted);
      font-size: 12px;
      white-space: normal;
      text-align: right;
      line-height: 1.15;
      max-width: 52vw;
    }

    .modeGrid {
      display: grid;
      grid-template-columns: repeat(6, minmax(0, 1fr));
      gap: 7px;
    }

    .modeBtn {
      min-height: 56px;
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 14px;
      background: #0f172a;
      color: var(--text);
      padding: 7px 5px;
      display: grid;
      place-items: center;
      gap: 2px;
      font-weight: 900;
      font-size: 11px;
      line-height: 1.05;
    }

    .modeBtn span {
      display: block;
      font-size: 17px;
      line-height: 1;
    }

    .modeBtn small {
      display: block;
      color: var(--muted);
      font-size: 8px;
      font-weight: 700;
      line-height: 1.05;
    }

    .modeBtn.active {
      background: linear-gradient(180deg, #075985, #0c4a6e);
      border-color: rgba(56, 189, 248, 0.9);
      box-shadow: 0 0 16px rgba(56,189,248,0.32);
    }

    .modePanel {
      position: relative;
      z-index: 1;
      border-radius: 14px;
      background: rgba(15, 23, 42, 0.88);
      border: 1px solid rgba(255,255,255,0.08);
      padding: 8px;
      display: grid;
      gap: 8px;
      overflow: visible;
    }

    .panelTitle {
      color: #dbeafe;
      font-size: 12px;
      line-height: 1.25;
      font-weight: 750;
    }

    .row {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 7px;
    }

    .row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .row.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }

    .controls,
    .metroPanel {
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      gap: 7px;
    }

    button,
    input,
    select {
      touch-action: manipulation;
      font-family: inherit;
    }

    button,
    select,
    input[type="text"] {
      height: 42px;
      border: 0;
      border-radius: 13px;
      background: #374151;
      color: var(--text);
      font-size: 13px;
      font-weight: 800;
      outline: none;
    }

    input[type="text"] {
      background: var(--card);
      border: 1px solid rgba(255,255,255,0.08);
      padding: 0 10px;
      user-select: text;
    }

    select {
      text-align: center;
      text-align-last: center;
    }

    button:active,
    button.active {
      transform: translateY(1px);
    }

    .green { background: #166534; }
    .red { background: #7f1d1d; }
    .yellow { background: #713f12; }
    .blue { background: #075985; }
    .purple { background: #581c87; }
    .disabled { opacity: 0.45; pointer-events: none; }

    #armAudio.active {
      background: var(--ok);
      color: #04130a;
    }

    #metroStart.active,
    #recBtn.active {
      background: var(--danger);
      color: #190208;
    }

    .octaveBox,
    .bpmBox,
    .infoBox {
      height: 42px;
      border-radius: 13px;
      background: var(--card);
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 800;
      border: 1px solid rgba(255,255,255,0.08);
      font-size: 13px;
      text-align: center;
      padding: 0 8px;
      overflow: hidden;
    }

    .infoBox {
      grid-column: span 2;
      color: #dbeafe;
      justify-content: flex-start;
      font-weight: 700;
      font-size: 12px;
      line-height: 1.15;
    }

    .sliderBox {
      grid-column: span 2;
      height: 42px;
      border-radius: 13px;
      background: var(--card);
      border: 1px solid rgba(255,255,255,0.08);
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 0 10px;
      font-size: 12px;
      color: var(--muted);
    }

    .sliderBox input {
      width: 100%;
    }

    .beatDots {
      grid-column: span 2;
      height: 42px;
      border-radius: 13px;
      background: var(--card);
      border: 1px solid rgba(255,255,255,0.08);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      padding: 0 8px;
    }

    .dot {
      width: 13px;
      height: 13px;
      border-radius: 99px;
      background: #374151;
      box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
    }

    .dot.active {
      background: var(--accent);
      box-shadow: 0 0 15px rgba(56,189,248,0.95);
    }

    .dot.first.active {
      background: var(--danger);
      box-shadow: 0 0 16px rgba(251,113,133,0.95);
    }

    .piano {
      position: relative;
      z-index: 1;
      flex: 1 1 auto;
      min-height: 170px;
      border-radius: 20px;
      overflow: hidden;
      background: #000;
      box-shadow: 0 18px 45px rgba(0,0,0,0.55);
      touch-action: none;
    }

    .whiteKeys {
      height: 100%;
      display: grid;
      grid-template-columns: repeat(var(--white-count), 1fr);
      gap: 2px;
      padding: 2px;
    }

    .key {
      position: relative;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      font-weight: 900;
      touch-action: none;
      cursor: pointer;
    }

    .white {
      background: linear-gradient(#ffffff, #dbeafe);
      color: #111827;
      border-radius: 0 0 15px 15px;
      padding-bottom: 15px;
      font-size: 17px;
      box-shadow: inset 0 -8px 14px rgba(0,0,0,0.15);
    }

    .white.active {
      background: linear-gradient(#bae6fd, #38bdf8);
      box-shadow: inset 0 -10px 18px rgba(0,0,0,0.22);
    }

    .white.target {
      outline: 4px solid var(--ok);
      outline-offset: -5px;
    }

    .white.wrong {
      outline: 4px solid var(--danger);
      outline-offset: -5px;
    }

    .white.simon {
      outline: 4px solid var(--warn);
      outline-offset: -5px;
    }

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

    .black {
      pointer-events: auto;
      position: absolute;
      top: 0;
      left: var(--left);
      transform: translateX(-50%);
      width: calc((100% / var(--white-count)) * 0.62);
      height: 61%;
      z-index: 3;
      background: linear-gradient(#111827, #020617);
      color: #e5e7eb;
      border: 2px solid #020617;
      border-radius: 0 0 12px 12px;
      padding-bottom: 10px;
      font-size: 12px;
      box-shadow:
        0 8px 18px rgba(0,0,0,0.55),
        inset 0 -8px 12px rgba(255,255,255,0.05);
    }

    .black.active {
      background: linear-gradient(#075985, #0284c7);
      color: white;
    }

    .black.target {
      outline: 4px solid var(--ok);
      outline-offset: -5px;
    }

    .black.wrong {
      outline: 4px solid var(--danger);
      outline-offset: -5px;
    }

    .black.simon {
      outline: 4px solid var(--warn);
      outline-offset: -5px;
    }

    .soundBtn.active,
    .chordBtn.active {
      background: #0284c7;
      color: #00111a;
    }

    .hint {
      text-align: center;
      color: var(--muted);
      font-size: 11px;
      line-height: 1.2;
      padding-bottom: env(safe-area-inset-bottom);
    }

    @media (max-width: 820px) {
      .modeGrid {
        grid-template-columns: repeat(6, minmax(58px, 1fr));
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
      }

      .modeGrid::-webkit-scrollbar { display: none; }
      .modeBtn { min-width: 62px; }
    }

    @media (max-width: 560px) {
      body {
        padding: 6px;
        gap: 6px;
      }

      .topbar {
        max-height: 52dvh;
        padding: 7px;
        gap: 6px;
        border-radius: 15px;
      }

      .controls,
      .metroPanel,
      .row,
      .row.three,
      .row.five {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
      }

      .sliderBox,
      .beatDots,
      .infoBox {
        grid-column: span 3;
      }

      .title h1 {
        font-size: 15px;
        line-height: 1.1;
      }

      .status {
        font-size: 10px;
        max-width: 45vw;
        line-height: 1.1;
      }

      .modeGrid { gap: 5px; }

      .modeBtn {
        min-width: 60px;
        min-height: 48px;
        font-size: 10px;
        padding: 5px 4px;
      }

      .modeBtn span { font-size: 15px; }
      .modeBtn small { font-size: 8px; }

      .modePanel {
        max-height: 140px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        padding: 6px;
        gap: 6px;
      }

      .panelTitle {
        font-size: 11px;
        line-height: 1.18;
      }

      button,
      select,
      input[type="text"],
      .octaveBox,
      .bpmBox,
      .infoBox,
      .sliderBox,
      .beatDots {
        height: 36px;
        min-height: 36px;
        font-size: 11px;
        border-radius: 11px;
      }

      .infoBox {
        font-size: 10px;
        line-height: 1.15;
      }

      .piano {
        min-height: 165px;
      }

      .white {
        font-size: 14px;
        padding-bottom: 12px;
      }

      .black {
        font-size: 10px;
      }
    }

    @media (max-height: 700px) and (max-width: 560px) {
      .topbar { max-height: 49dvh; }
      .modePanel { max-height: 112px; }

      button,
      select,
      input[type="text"],
      .octaveBox,
      .bpmBox,
      .infoBox,
      .sliderBox,
      .beatDots {
        height: 34px;
        min-height: 34px;
      }

      .piano { min-height: 150px; }
    }


/* Audio activation overlay - browsery blokují zvuk bez uživatelského gesta */
.audioGate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.18), transparent 34%),
    rgba(2, 6, 23, 0.88);
  backdrop-filter: blur(8px);
}

.audioGate.hidden {
  display: none;
}

.audioGate__box {
  width: min(520px, 94vw);
  border-radius: 24px;
  padding: 22px;
  background: rgba(15, 23, 42, 0.96);
  color: #f9fafb;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 22px 70px rgba(0,0,0,0.58);
  text-align: center;
}

.audioGate__icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 10px;
}

.audioGate__title {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.15;
}

.audioGate__text {
  margin: 0 0 16px;
  color: #cbd5e1;
  font-size: 15px;
  line-height: 1.45;
}

.audioGate__btn {
  width: 100%;
  height: 58px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #22c55e, #16a34a);
  color: #04130a;
  font-size: 18px;
  font-weight: 950;
  cursor: pointer;
}

.audioGate__btn:active {
  transform: translateY(1px);
}

.audioGate__note {
  margin-top: 11px;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.35;
}

@media (max-width: 560px) {
  .audioGate {
    padding: 12px;
  }

  .audioGate__box {
    border-radius: 20px;
    padding: 18px;
  }

  .audioGate__icon {
    font-size: 42px;
  }

  .audioGate__title {
    font-size: 20px;
  }

  .audioGate__text {
    font-size: 14px;
  }

  .audioGate__btn {
    height: 54px;
    font-size: 16px;
  }
}

