/* ============================================================
   PERFECT PITCH TRAINER — tool.css
   Piano-key styled answer grid, confusion matrix table,
   accuracy heatmap, speed timer, responsive layout
   ============================================================ */

/* --- Settings Row --- */
.pp-settings {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.pp-settings__group {
  flex: 1 1 180px;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.pp-label {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pp-select {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  transition: border-color 0.2s;
}

.pp-select:hover,
.pp-select:focus {
  border-color: var(--color-primary);
  outline: none;
}

/* --- Speed Mode Toggle --- */
.pp-speed-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.pp-toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  user-select: none;
}

.pp-toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.pp-toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 11px;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.pp-toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--color-text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.pp-toggle-label input:checked + .pp-toggle-slider {
  background: rgba(0, 255, 65, 0.15);
  border-color: #00ff41;
}

.pp-toggle-label input:checked + .pp-toggle-slider::after {
  transform: translateX(18px);
  background: #00ff41;
}

.pp-speed-timer {
  font-family: var(--font-display, var(--font-mono));
  font-size: var(--fs-xl, 1.5rem);
  font-weight: 700;
  color: #ffaa00;
  min-width: 60px;
  text-align: center;
}

.pp-speed-timer--danger {
  color: #ff3c3c;
  animation: pp-timer-pulse 0.5s ease infinite alternate;
}

@keyframes pp-timer-pulse {
  from { opacity: 1; }
  to { opacity: 0.5; }
}

/* --- Status Bar --- */
.pp-status {
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-md);
  padding: var(--space-xs) var(--space-sm);
  background: rgba(0, 255, 65, 0.05);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  min-height: 2.4em;
  display: flex;
  align-items: center;
}

/* --- Control Buttons --- */
.pp-controls {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

/* --- 12-Note Answer Grid (Piano-Key Styled) --- */
.pp-answer-grid {
  display: flex;
  gap: 4px;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
  justify-content: center;
}

.pp-note-btn {
  position: relative;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
  overflow: hidden;
}

/* White keys */
.pp-note-btn--white {
  background: linear-gradient(to bottom, #f5f5f5, #e0e0e0);
  color: #1a1a1a;
  width: 56px;
  height: 100px;
  font-size: var(--fs-base);
  border-color: #999;
}

.pp-note-btn--white:hover:not(:disabled) {
  background: linear-gradient(to bottom, #ffffff, #f0f0f0);
  border-color: #00ff41;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 255, 65, 0.2);
}

/* Black keys */
.pp-note-btn--black {
  background: linear-gradient(to bottom, #3a3a3a, #1a1a1a);
  color: #e0e0e0;
  width: 42px;
  height: 72px;
  font-size: var(--fs-sm);
  border-color: #555;
  z-index: 1;
  margin-left: -10px;
  margin-right: -10px;
}

.pp-note-btn--black:hover:not(:disabled) {
  background: linear-gradient(to bottom, #4a4a4a, #2a2a2a);
  border-color: #00ff41;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 255, 65, 0.3);
}

.pp-note-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.pp-note-btn__label {
  font-size: inherit;
  display: block;
  line-height: 1;
}

.pp-note-btn__shortcut {
  font-size: 9px;
  opacity: 0.5;
  margin-top: 3px;
  display: block;
}

/* Answer result states */
.pp-note-btn--correct {
  border-color: #00ff41 !important;
  background: rgba(0, 255, 65, 0.35) !important;
  color: #fff !important;
  animation: pp-flash-correct 0.6s ease;
}

.pp-note-btn--wrong {
  border-color: #ff3c3c !important;
  background: rgba(255, 60, 60, 0.35) !important;
  color: #fff !important;
  animation: pp-flash-wrong 0.6s ease;
}

.pp-note-btn--reveal {
  border-color: #00ff41 !important;
  background: rgba(0, 255, 65, 0.2) !important;
  color: #fff !important;
}

@keyframes pp-flash-correct {
  0% { background: rgba(0, 255, 65, 0.7); box-shadow: 0 0 30px rgba(0, 255, 65, 0.5); }
  100% { background: rgba(0, 255, 65, 0.35); box-shadow: none; }
}

@keyframes pp-flash-wrong {
  0% { background: rgba(255, 60, 60, 0.7); box-shadow: 0 0 30px rgba(255, 60, 60, 0.5); }
  100% { background: rgba(255, 60, 60, 0.35); box-shadow: none; }
}

/* --- Shortcut Hint --- */
.pp-shortcut-hint {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-md);
  opacity: 0.6;
}

.pp-shortcut-hint kbd {
  display: inline-block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.4;
}

/* --- Round Result --- */
.pp-round-result {
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: 700;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-md);
}

.pp-round-result--correct {
  color: #00ff41;
  background: rgba(0, 255, 65, 0.1);
  border: 1px solid rgba(0, 255, 65, 0.3);
}

.pp-round-result--wrong {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
}

/* --- Stats Row --- */
.pp-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.pp-stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  text-align: center;
}

.pp-stat-box__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xxs, 4px);
}

.pp-stat-box__value {
  font-family: var(--font-display, var(--font-mono));
  font-size: var(--fs-xl, 1.5rem);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
}

.pp-stat-box__sub {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* --- Confusion Alert --- */
.pp-confusion-alert {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: #ffaa00;
  background: rgba(255, 170, 0, 0.08);
  border: 1px solid rgba(255, 170, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-md);
  text-align: center;
}

/* --- Per-Note Accuracy Grid (Heatmap) --- */
.pp-chart-container {
  margin-bottom: var(--space-md);
}

.pp-chart-title {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}

.pp-chart-sub {
  font-size: var(--fs-xs);
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.pp-accuracy-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}

.pp-accuracy-cell {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs);
  text-align: center;
  font-family: var(--font-mono);
  transition: background 0.3s, border-color 0.3s;
}

.pp-accuracy-cell__note {
  font-size: var(--fs-sm);
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.pp-accuracy-cell__pct {
  font-size: 10px;
  color: var(--color-text-muted);
  display: block;
}

.pp-accuracy-cell__count {
  font-size: 9px;
  color: var(--color-text-muted);
  opacity: 0.6;
  display: block;
}

/* Heatmap color levels */
.pp-accuracy-cell--none {
  background: var(--color-surface);
  border-color: var(--color-border);
}

.pp-accuracy-cell--bad {
  background: rgba(255, 60, 60, 0.15);
  border-color: rgba(255, 60, 60, 0.4);
}

.pp-accuracy-cell--mid {
  background: rgba(255, 170, 0, 0.15);
  border-color: rgba(255, 170, 0, 0.4);
}

.pp-accuracy-cell--good {
  background: rgba(0, 255, 65, 0.1);
  border-color: rgba(0, 255, 65, 0.3);
}

.pp-accuracy-cell--great {
  background: rgba(0, 255, 65, 0.2);
  border-color: rgba(0, 255, 65, 0.5);
}

/* --- Confusion Matrix Table --- */
.pp-matrix-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.pp-matrix {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  min-width: 420px;
}

.pp-matrix th,
.pp-matrix td {
  padding: 4px 6px;
  text-align: center;
  border: 1px solid var(--color-border);
  min-width: 32px;
}

.pp-matrix th {
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.pp-matrix th.pp-matrix__corner {
  background: transparent;
  border-color: transparent;
}

.pp-matrix td {
  transition: background 0.3s;
}

.pp-matrix__row-header {
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 600;
}

/* Matrix heatmap cells */
.pp-matrix td.pp-matrix-cell--zero {
  color: var(--color-text-muted);
  opacity: 0.3;
}

.pp-matrix td.pp-matrix-cell--diag {
  background: rgba(0, 255, 65, 0.12);
  color: #00ff41;
  font-weight: 700;
}

.pp-matrix td.pp-matrix-cell--low {
  background: rgba(255, 170, 0, 0.08);
  color: #ffaa00;
}

.pp-matrix td.pp-matrix-cell--mid {
  background: rgba(255, 170, 0, 0.2);
  color: #ffaa00;
  font-weight: 600;
}

.pp-matrix td.pp-matrix-cell--high {
  background: rgba(255, 60, 60, 0.2);
  color: #ff6b6b;
  font-weight: 700;
}

/* --- Session History --- */
.pp-history-container {
  margin-bottom: var(--space-md);
}

.pp-history-count {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-weight: 400;
}

.pp-session-history {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  max-height: 240px;
  overflow-y: auto;
}

.pp-history-empty {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-sm);
}

.pp-history-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xxs, 4px) 0;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.pp-history-item:last-child {
  border-bottom: none;
}

.pp-history-item__icon {
  font-size: var(--fs-base);
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.pp-history-item__icon--correct {
  color: #00ff41;
}

.pp-history-item__icon--wrong {
  color: #ff3c3c;
}

.pp-history-item__icon--timeout {
  color: #ffaa00;
}

.pp-history-item__text {
  flex: 1;
  color: var(--color-text-muted);
}

.pp-history-item__answer {
  color: var(--color-text);
  font-weight: 600;
}

/* --- Reset Row --- */
.pp-reset-row {
  text-align: center;
  padding-top: var(--space-sm);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .pp-settings {
    flex-direction: column;
  }

  .pp-stats-row {
    grid-template-columns: 1fr;
  }

  .pp-accuracy-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .pp-note-btn--white {
    width: 44px;
    height: 80px;
    font-size: var(--fs-sm);
  }

  .pp-note-btn--black {
    width: 34px;
    height: 58px;
    font-size: var(--fs-xs);
    margin-left: -8px;
    margin-right: -8px;
  }

  .pp-answer-grid {
    gap: 3px;
  }
}

@media (max-width: 480px) {
  .pp-accuracy-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .pp-note-btn--white {
    width: 36px;
    height: 68px;
  }

  .pp-note-btn--black {
    width: 28px;
    height: 48px;
    margin-left: -6px;
    margin-right: -6px;
  }

  .pp-controls {
    flex-direction: column;
  }

  .pp-controls .btn {
    width: 100%;
  }

  .pp-shortcut-hint {
    display: none;
  }
}
