/* ScaleTrainer - Note Recognition Game */
/* NoteLoop Series by Open Loop Apps */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --error: #ef4444;
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --white-key: #f0f0f0;
    --white-key-active: #4ade80;
    --white-key-error: #ef4444;
    --black-key: #1e293b;
    --black-key-active: #22c55e;
    --black-key-error: #dc2626;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================================
   OVERLAY
   ============================================================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    padding: 20px;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.unlock-card {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 48px 32px;
    text-align: center;
    max-width: 400px;
    border: 2px solid var(--border);
}

.unlock-card h1 {
    font-size: 48px;
    margin-bottom: 16px;
}

.unlock-card p {
    color: var(--text-muted);
    font-size: 18px;
    margin-bottom: 32px;
}

/* ============================================================================
   TUTORIAL SYSTEM
   ============================================================================ */

.tutorial-card {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 40px;
    max-width: 700px;
    width: 100%;
    border: 2px solid var(--border);
    position: relative;
}

.tutorial-dots {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.tutorial-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s ease;
    cursor: pointer;
}

.tutorial-dots .dot.active {
    background: var(--primary);
    transform: scale(1.3);
}

.tutorial-dots .dot.completed {
    background: var(--success);
}

.tutorial-content {
    min-height: 400px;
    position: relative;
}

.tutorial-step {
    display: none;
    animation: fadeIn 0.4s ease;
}

.tutorial-step.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tutorial-step h2 {
    font-size: 32px;
    margin-bottom: 20px;
    color: var(--text);
    text-align: center;
}

.tutorial-step p {
    font-size: 18px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 16px;
    text-align: center;
}

.tutorial-step p strong {
    color: var(--primary);
}

.tutorial-visual {
    margin: 32px 0;
    padding: 24px;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 16px;
    border: 2px solid var(--border);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.music-emoji {
    font-size: 120px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-20px); }
}

.tutorial-svg {
    width: 100%;
    max-width: 400px;
    height: auto;
}

.tutorial-checklist {
    list-style: none;
    text-align: left;
    max-width: 400px;
    margin: 24px auto;
    padding: 0;
}

.tutorial-checklist li {
    font-size: 18px;
    padding: 12px 0;
    color: var(--text);
}

.hint {
    color: var(--text-muted) !important;
    font-style: italic;
    font-size: 16px !important;
    margin-top: 24px !important;
}

/* Quiz Styles */
.quiz-container {
    max-width: 500px;
    margin: 0 auto;
}

.quiz-question {
    margin: 24px 0;
    padding: 20px;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 12px;
    border: 2px solid var(--border);
}

.quiz-question.hidden {
    display: none;
}

.quiz-q {
    font-size: 18px !important;
    margin-bottom: 16px !important;
    text-align: left !important;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quiz-option {
    padding: 14px 20px;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.quiz-option:hover:not(:disabled) {
    background: var(--border);
    transform: translateX(4px);
}

.quiz-option:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.quiz-option.correct {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
    color: var(--success);
}

.quiz-option.incorrect {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--error);
    color: var(--error);
}

.quiz-feedback {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    display: none;
}

.quiz-feedback.show {
    display: block;
}

.quiz-feedback.correct {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.quiz-feedback.incorrect {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.quiz-complete {
    text-align: center;
    padding: 32px 20px;
}

.quiz-complete.hidden {
    display: none;
}

.quiz-success h3 {
    font-size: 32px;
    color: var(--success);
    margin-bottom: 16px;
}

.quiz-success p {
    font-size: 18px;
    color: var(--text);
}

/* Tutorial Piano Display */
#tutorial-piano-display {
    position: relative;
    height: 180px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tutorial-piano-key {
    position: relative;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.tutorial-piano-key.white {
    width: 50px;
    height: 160px;
    background: var(--white-key);
    border: 2px solid var(--border);
    border-radius: 0 0 8px 8px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
}

.tutorial-piano-key.black {
    position: absolute;
    width: 35px;
    height: 100px;
    background: var(--black-key);
    border: 2px solid #000;
    border-radius: 0 0 6px 6px;
    z-index: 2;
}

.tutorial-piano-key:hover {
    transform: translateY(-4px);
}

.tutorial-piano-key.white:hover {
    background: #e0e0e0;
}

.tutorial-piano-key.black:hover {
    background: #2d3748;
}

.tutorial-key-label {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    pointer-events: none;
}

.tutorial-piano-key.black .tutorial-key-label {
    color: var(--text);
    font-size: 10px;
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
}

.tutorial-nav {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
    margin-top: 32px;
    flex-wrap: wrap;
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
    transition: color 0.2s ease;
}

.text-btn:hover {
    color: var(--text);
    text-decoration: underline;
}

/* Responsive Tutorial */
@media (max-width: 640px) {
    .tutorial-card {
        padding: 24px;
    }
    
    .tutorial-step h2 {
        font-size: 24px;
    }
    
    .tutorial-step p {
        font-size: 16px;
    }
    
    .music-emoji {
        font-size: 80px;
    }
    
    .tutorial-visual {
        min-height: 150px;
        padding: 16px;
    }
    
    .tutorial-piano-key.white {
        width: 40px;
        height: 130px;
    }
    
    .tutorial-piano-key.black {
        width: 28px;
        height: 80px;
    }
    
    .tutorial-nav {
        justify-content: center;
    }
    
    .text-btn {
        flex-basis: 100%;
        text-align: center;
    }
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.primary-btn,
.secondary-btn {
    font-size: 18px;
    font-weight: 600;
    padding: 16px 32px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    min-width: 140px;
}

.primary-btn {
    background: var(--primary);
    color: white;
}

.primary-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: var(--card-bg);
    color: var(--text);
    border: 2px solid var(--border);
}

.secondary-btn:hover {
    background: var(--border);
}

/* ============================================================================
   GAME CONTAINER
   ============================================================================ */

#game-container {
    width: 100%;
    max-width: 900px;
    transition: opacity 0.3s ease;
}

#game-container.hidden {
    display: none;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.game-header {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 24px;
    background: var(--card-bg);
    padding: 20px;
    border-radius: 16px;
    border: 2px solid var(--border);
    position: relative;
}

.stat {
    text-align: center;
}

.stat .label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat .value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.settings-btn:hover {
    background: var(--border);
    transform: scale(1.1);
}

/* ============================================================================
   SETTINGS PANEL
   ============================================================================ */

.settings-panel {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    transition: all 0.3s ease;
}

.settings-panel.hidden {
    display: none;
}

.settings-panel h3 {
    margin: 0 0 20px 0;
    color: var(--text);
    font-size: 20px;
}

.setting-item {
    margin-bottom: 20px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 28px;
    background: var(--border);
    border-radius: 14px;
    transition: all 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: var(--text);
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: all 0.3s ease;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.toggle-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

/* ============================================================================
   MODE SELECTOR
   ============================================================================ */

.mode-selector {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: 140px;
    padding: 12px 16px;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: var(--border);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ============================================================================
   QUESTION AREA
   ============================================================================ */

.question-area {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Musical Staff */
.staff-svg {
    width: 100%;
    max-width: 400px;
    height: 200px;
}

.staff-line {
    stroke: var(--text-muted);
    stroke-width: 2;
}

.note-head {
    fill: var(--text);
}

.note-stem {
    stroke: var(--text);
    stroke-width: 2;
}

.ledger-line {
    stroke: var(--text-muted);
    stroke-width: 2;
}

/* Note Name Display */
.note-name-display {
    text-align: center;
}

.note-name-display.hidden {
    display: none;
}

#note-name-text {
    font-size: 96px;
    font-weight: 700;
    color: var(--primary);
}

/* Audio Mode Display */
.audio-mode-display {
    text-align: center;
}

.audio-mode-display.hidden {
    display: none;
}

.play-note-btn {
    font-size: 64px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    width: 120px;
    height: 120px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 16px;
}

.play-note-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.play-note-btn:active {
    transform: scale(0.95);
}

.instruction {
    color: var(--text-muted);
    font-size: 16px;
}

/* ============================================================================
   STATUS MESSAGE
   ============================================================================ */

.status-message {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 24px;
    min-height: 28px;
    padding: 12px;
    border-radius: 12px;
    background: var(--card-bg);
    border: 2px solid var(--border);
    transition: all 0.3s ease;
}

.status-message.success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.status-message.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
    color: var(--error);
}

/* ============================================================================
   PIANO KEYBOARD
   ============================================================================ */

.piano-container {
    margin-bottom: 24px;
    overflow-x: auto;
    overflow-y: visible;
    padding: 20px 0;
}

.piano-keyboard {
    position: relative;
    display: inline-flex;
    min-width: 100%;
    justify-content: center;
}

.piano-key {
    position: relative;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    border: 2px solid var(--border);
}

.piano-key.white {
    width: 60px;
    height: 200px;
    background: var(--white-key);
    border-radius: 0 0 8px 8px;
    z-index: 1;
}

.piano-key.black {
    position: absolute;
    width: 40px;
    height: 120px;
    background: var(--black-key);
    border-radius: 0 0 6px 6px;
    z-index: 2;
    border: 2px solid #000;
}

.piano-key.white:hover:not(.disabled) {
    background: #e0e0e0;
    transform: translateY(-4px);
}

.piano-key.black:hover:not(.disabled) {
    background: #2d3748;
    transform: translateY(-4px);
}

.piano-key.white:active:not(.disabled) {
    transform: translateY(-2px);
}

.piano-key.black:active:not(.disabled) {
    transform: translateY(-2px);
}

.piano-key.disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.piano-key.correct {
    animation: correct-flash 0.5s ease;
}

.piano-key.white.correct {
    background: var(--white-key-active);
}

.piano-key.black.correct {
    background: var(--black-key-active);
}

.piano-key.incorrect {
    animation: incorrect-shake 0.5s ease;
}

.piano-key.white.incorrect {
    background: var(--white-key-error);
}

.piano-key.black.incorrect {
    background: var(--black-key-error);
}

.key-label {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    pointer-events: none;
}

.piano-key.black .key-label {
    color: var(--text);
    font-size: 11px;
    bottom: 6px;
}

@keyframes correct-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes incorrect-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* ============================================================================
   ACTION BUTTONS
   ============================================================================ */

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 24px;
}

.action-buttons.hidden {
    display: none;
}

/* ============================================================================
   PROGRESS INDICATOR
   ============================================================================ */

.progress-indicator {
    margin-bottom: 24px;
}

#question-number {
    display: block;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--card-bg);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
    width: 0%;
}

/* ============================================================================
   AD SLOT
   ============================================================================ */

.ad-slot {
    min-height: 50px;
    background: transparent;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 24px;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    
    .unlock-card {
        padding: 32px 24px;
    }
    
    .unlock-card h1 {
        font-size: 36px;
    }
    
    .game-header {
        padding: 16px;
    }
    
    .stat .value {
        font-size: 24px;
    }
    
    .question-area {
        padding: 24px 16px;
        min-height: 180px;
    }
    
    #note-name-text {
        font-size: 72px;
    }
    
    .play-note-btn {
        width: 100px;
        height: 100px;
        font-size: 48px;
    }
    
    .piano-key.white {
        width: 45px;
        height: 160px;
    }
    
    .piano-key.black {
        width: 30px;
        height: 100px;
    }
    
    .key-label {
        font-size: 11px;
    }
    
    .piano-key.black .key-label {
        font-size: 9px;
    }
    
    .mode-btn {
        font-size: 14px;
        padding: 10px 12px;
        min-width: 100px;
    }
}

@media (max-width: 480px) {
    .piano-key.white {
        width: 36px;
        height: 140px;
    }
    
    .piano-key.black {
        width: 26px;
        height: 85px;
    }
    
    .key-label {
        font-size: 10px;
    }
    
    .piano-key.black .key-label {
        font-size: 8px;
    }
}

/* Misc */
.noscript{
  max-width: 720px;
  margin: 24px auto;
  padding: 16px 18px;
  background: rgba(239,68,68,0.15);
  border: 2px solid var(--error);
  border-radius: 12px;
  color: var(--text);
  font-weight: 600;
}

/* Make tutorial dots work as buttons */
.tutorial-dots .dot{
  border: none;
  padding: 0;
}

/* Focus visibility */
button:focus-visible{
  outline: 3px solid rgba(99,102,241,0.8);
  outline-offset: 2px;
}

/* Piano layout fixes */
.piano-keyboard{
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 220px;
  min-width: 100%;
}

.piano-key.white{
  position: relative; /* in normal flow */
}

.piano-key.black{
  top: 0;
}

/* Tutorial piano layout fixes */
#tutorial-piano-display .tutorial-piano-row{
  position: relative;
  display: flex;
}
