:root {
  --bg: #f8f5f0;
  --surface: #ffffff;
  --primary: #2c3e50;
  --accent: #d35400;
  --success: #27ae60;
  --error: #c0392b;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #e0d6c8;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 16px;
  min-height: 100vh;
  touch-action: manipulation;
}

.container { max-width: 900px; margin: 0 auto; }

header { text-align: center; margin-bottom: 20px; }
h1 { font-size: 1.6rem; margin-bottom: 4px; color: var(--primary); }
.subtitle { color: var(--text-muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

select, button {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.2s;
  min-height: 44px; /* iOS touch target */
}

button:hover { background: #f0ebe4; }
button:active { transform: translateY(1px); }

button.primary { background: var(--primary); color: white; border: none; }
button.primary:hover { background: #1a252f; }
button.success { background: var(--success); color: white; border: none; }
button.success:hover { background: #219150; }

.piano-wrapper { overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.piano { display: flex; position: relative; height: 160px; margin: 0 auto; width: max-content; }

.key { position: relative; cursor: pointer; transition: 0.1s; user-select: none; }
.key.white {
  width: 48px; height: 100%;
  background: linear-gradient(to bottom, #fff 0%, #f2f2f2 100%);
  border: 1px solid #ccc;
  border-radius: 0 0 6px 6px;
  margin: 0 2px; z-index: 1;
}
.key.black {
  width: 32px; height: 65%;
  background: linear-gradient(to bottom, #333 0%, #111 100%);
  border-radius: 0 0 4px 4px;
  position: absolute; z-index: 2; margin-left: -16px;
}
.key.active { transform: translateY(2px); filter: brightness(0.9); }

.key-label {
  position: absolute; bottom: 6px; left: 0; right: 0;
  text-align: center; font-size: 10px; font-weight: 600; pointer-events: none;
}
.white .key-label { color: #888; }
.black .key-label { color: #ddd; bottom: 4px; font-size: 9px; }

.mode-toggle { display: flex; gap: 6px; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.mode-btn {
  padding: 6px 12px; border-radius: 20px;
  background: #f0ebe4; border: 1px solid var(--border);
  font-size: 0.8rem; min-height: 36px;
}
.mode-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.pedal { text-align: center; margin: 10px 0; }
.pedal-btn {
  width: 110px; height: 34px; border-radius: 17px;
  background: #d4c5b2; border: none; font-weight: 600; font-size: 0.85rem;
}
.pedal-btn.active { background: var(--accent); color: white; box-shadow: 0 0 10px rgba(211,84,0,0.4); }

.quiz-list {
  display: grid; gap: 6px; max-height: 280px; overflow-y: auto;
  padding-right: 4px; -webkit-overflow-scrolling: touch;
}
.quiz-empty { text-align: center; padding: 16px; color: var(--text-muted); }

.quiz-item {
  display: flex; align-items: center; gap: 6px;
  background: #faf7f3; padding: 8px 10px; border-radius: 8px; flex-wrap: wrap;
}
.q-num { font-weight: bold; min-width: 22px; color: var(--text-muted); font-size: 0.9rem; }
.q-type { font-size: 0.8rem; color: var(--text-muted); min-width: 56px; }
.q-input {
  flex: 1; min-width: 90px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); font-size: 0.9rem; min-height: 36px;
}
.q-status { font-size: 1.1rem; width: 22px; text-align: center; }
.q-play {
  padding: 5px 9px; font-size: 0.8rem; background: #e8e0d5; border: none; min-height: 32px;
}

.stats {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 0.9rem;
}
.hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px); padding: 20px;
}
.overlay-box {
  background: white; padding: 20px; border-radius: 16px;
  text-align: center; max-width: 300px; width: 100%;
}
.overlay-text { margin: 10px 0; color: #666; font-size: 0.95rem; }
.hidden { display: none !important; }

/* Mobile */
@media (max-width: 500px) {
  body { padding: 12px; }
  h1 { font-size: 1.4rem; }
  .controls { flex-direction: column; }
  select, button { width: 100%; }
  .key.white { width: 40px; }
  .key.black { width: 26px; margin-left: -13px; }
  .piano { height: 140px; }
}

/* === Стили для справки внизу === */
.help-section {
    background: #fdfbf7; /* Чуть теплее, чем основной фон */
    border: 1px dashed var(--border);
}
.help-section h3 {
    text-align: center;
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 10px;
}
.help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.help-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
}
.help-col li {
    margin-bottom: 6px;
    border-bottom: 1px solid #eee;
    padding-bottom: 2px;
}
.help-col b {
    color: var(--accent);
    min-width: 40px;
    display: inline-block;
}

/* Адаптивность для мобильных */
@media (max-width: 500px) {
    .help-grid {
        grid-template-columns: 1fr; /* Одна колонка на телефоне */
    }
}