:root {
    --ink: #000000;
    --paper: #ffffff;
    --muted: #555555;
    --flat: #5B8DEF;
    --sharp: #F46C3F;
    --intune: #27AE60;
    --wrong: #C0392B;
    --radius: 14px;
    --ans-h: 56px;
    --act-h: 54px;
    --staff-w: 12.5rem;
    --gap: 12px;
}

html {
    height: var(--mc-vvh, 100svh);
    max-height: var(--mc-vvh, 100svh);
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    background-color: var(--paper);
    color: var(--ink);
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--mc-vvh, 100svh);
    max-height: var(--mc-vvh, 100svh);
    overflow: hidden;
}

button,
button * {
    -webkit-user-select: none;
    user-select: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
    outline: 3px solid var(--flat);
    outline-offset: 2px;
}

.acc {
    font-family: "Noto Music", sans-serif;
    font-weight: 400;
    font-size: 1.35em;
    line-height: 0;
    position: relative;
    top: -0.2em;
    margin-left: 0.03em;
}

/* ---------- Layout ---------- */

.app {
    box-sizing: border-box;
    width: min(100%, 27rem);
    max-height: 100%;
    padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas: "head" "levels" "card" "answers" "actions";
    gap: var(--gap);
}

/* ---------- Header ---------- */

.head {
    grid-area: head;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.brand {
    text-align: center;
}

.subtitle {
    margin: 0;
    font-size: 8pt;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.title {
    margin: 0;
    font-family: 'Dancing Script', cursive;
    font-weight: 700;
    font-size: 2.2rem;
    line-height: 1.05;
}

.head {
    position: relative;
}

.head__tools {
    justify-self: start;
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--paper);
    color: var(--ink);
    font-size: 19px;
    font-weight: 700;
}

.score {
    justify-self: end;
    padding: 6px 12px;
    border: 2px solid var(--ink);
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
}

.score__label {
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@media (hover: hover) and (pointer: fine) {
    .icon-btn:hover {
        background: var(--ink);
        color: var(--paper);
    }
}

/* ---------- Levels ---------- */

.levels {
    grid-area: levels;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 2px solid var(--ink);
    border-radius: 999px;
    overflow: hidden;
}

.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 44px;
    padding: 4px 2px;
    border: none;
    border-radius: 0;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.1;
}

.level-btn + .level-btn {
    border-left: 2px solid var(--ink);
}

.level-btn__name {
    font-size: 14px;
    font-weight: 700;
}

.level-btn__kind {
    font-size: 9px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.level-btn[aria-checked="true"] {
    background: var(--ink);
    color: var(--paper);
}

.level-btn:focus-visible {
    outline-offset: -5px;
}

@media (hover: hover) and (pointer: fine) {
    .level-btn[aria-checked="false"]:hover {
        background: #f0f0f0;
    }
}

/* ---------- Card: staff + status ---------- */

.card {
    grid-area: card;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 12px 10px;
    border: 2px solid var(--ink);
    border-radius: 18px;
    background: var(--paper);
    min-height: 0;
}

.staff {
    display: block;
    width: min(100%, var(--staff-w));
    height: auto;
    overflow: visible;
}

.status {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    min-height: 4.4rem;
    text-align: center;
}

.status p {
    margin: 0;
}

.status p:empty {
    display: none;
}

.status__title {
    font-family: 'Dancing Script', cursive;
    font-weight: 700;
    font-size: 1.7rem;
    line-height: 1;
}

.status__line {
    font-size: 1rem;
    line-height: 1.3;
}

.status__detail {
    font-size: 0.85rem;
    line-height: 1.35;
    color: var(--muted);
}

.status.is-wrong .status__detail {
    color: var(--wrong);
    font-weight: 700;
}

.tone-flat { color: var(--flat); }
.tone-sharp { color: var(--sharp); }
.tone-intune { color: var(--intune); }

.status.is-solved .status__title {
    animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Answers ---------- */

.answers {
    grid-area: answers;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.board {
    grid-area: answers;
    display: grid;
    gap: 8px;
}

.answers[hidden],
.board[hidden] {
    display: none;
}

.board__row {
    display: grid;
    grid-template-columns: 1fr 4.6rem 1fr;
    align-items: center;
    gap: 8px;
}

.board__row--intune {
    display: flex;
    justify-content: center;
}

.board__row--intune .ans {
    width: calc(50% + 2.3rem);
}

.board__label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-align: center;
    text-transform: uppercase;
}

.ans {
    height: var(--ans-h);
    padding: 0 8px;
    border: none;
    border-radius: var(--radius);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22);
    transition: transform 0.12s, box-shadow 0.12s, filter 0.25s, opacity 0.25s;
}

.board .ans {
    height: calc(var(--ans-h) - 10px);
}

.ans--flat { background-color: var(--flat); }
.ans--sharp { background-color: var(--sharp); }
.ans--intune { background-color: var(--intune); }

.ans:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
}

@media (hover: hover) and (pointer: fine) {
    .ans:hover { filter: brightness(1.07); }
}

.is-idle .ans,
.ans.is-wrong {
    filter: grayscale(1);
    opacity: 0.35;
    pointer-events: none;
    box-shadow: none;
}

.ans.is-wrong {
    animation: shake 0.35s ease-in-out;
}

.is-idle .ans.is-right {
    filter: none;
    opacity: 1;
    box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink);
}

/* ---------- Actions ---------- */

.actions {
    grid-area: actions;
    display: flex;
    gap: 10px;
}

.act {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--act-h);
    padding: 0 12px;
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
}

@media (max-width: 360px) {
    .act { font-size: 15px; gap: 6px; }
}

.act[hidden] {
    display: none;
}

.act--primary {
    background: var(--ink);
    color: var(--paper);
}

.act--ghost {
    background: var(--paper);
    color: var(--ink);
}

.act:active {
    transform: translateY(2px);
}

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

.act__icon {
    display: inline-flex;
    width: 1.15em;
    height: 1.15em;
}

.act__icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.act[data-mode="next"] .act__icon {
    order: 2;
}

.is-playing .act__icon {
    animation: play-pulse 0.8s infinite ease-in-out;
}

@keyframes play-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.75); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}

@keyframes pop-in {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

/* ---------- Staff ---------- */

.staff__line,
.staff__ledger {
    stroke: var(--ink);
    stroke-width: 1;
}

.staff__clef,
.staff__acc,
.staff__arrow {
    font-family: "Noto Music", sans-serif;
    dominant-baseline: middle;
    text-anchor: middle;
    user-select: none;
}

.staff__clef {
    font-size: 40px;
    fill: var(--ink);
}

.staff__acc {
    font-size: 25px;
    fill: var(--note-color, var(--ink));
}

.staff__arrow {
    font-family: Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    fill: var(--note-color, var(--ink));
}

.staff__head {
    fill: var(--note-color, var(--ink));
}

.staff__ledger {
    stroke: var(--note-color, var(--ink));
    stroke-width: 1.3;
}

.staff__note {
    opacity: 0;
    transform-box: view-box;
    animation: note-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.staff__note.is-shown {
    opacity: 1;
    animation: none;
}

.staff__note.is-shown.is-hit {
    animation: note-pulse 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

@keyframes note-pop {
    0% { opacity: 0; transform: scale(0.2); }
    55% { opacity: 1; transform: scale(1.22); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes note-pulse {
    0% { transform: scale(1); }
    45% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .staff__note { animation-duration: 0.01s; }
    .staff__note.is-shown.is-hit,
    .status.is-solved .status__title,
    .ans.is-wrong { animation: none; }
}

/* ---------- How to Play ---------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.45);
}

.overlay.hidden {
    display: none;
}

.ed-modal {
    box-sizing: border-box;
    width: min(100%, 21rem);
    max-height: 100%;
    overflow: auto;
    padding: 1.5rem 1.35rem 1.25rem;
    border: 2px solid var(--ink);
    border-radius: 18px;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.ed-modal__title {
    margin: 0;
    text-align: center;
    font-family: 'Dancing Script', cursive;
    font-size: 2rem;
    font-weight: 700;
}

.ed-modal__prompt {
    margin: 0.85rem 0 0;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.4;
}

.ed-modal__note {
    font-size: 0.85rem;
    color: #444444;
}

.ed-modal__btn {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 1.1rem;
    padding: 0.65rem 0.75rem;
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--paper);
    font-size: 0.95rem;
    font-weight: 700;
}

/* ---------- Sizes ---------- */

@media (min-width: 768px) and (min-height: 820px) {
    :root {
        --staff-w: 15rem;
        --ans-h: 60px;
        --gap: 14px;
    }
    .app { width: min(100%, 30rem); }
    .title { font-size: 2.6rem; }
    .subtitle { font-size: 9pt; }
}

/* Shorter phones */
@media (max-height: 740px) {
    :root {
        --staff-w: 10.5rem;
        --ans-h: 52px;
        --act-h: 50px;
        --gap: 10px;
    }
    .title { font-size: 1.9rem; }
    .status { min-height: 4rem; }
}

@media (max-height: 640px) {
    :root {
        --staff-w: 9rem;
        --ans-h: 48px;
        --act-h: 46px;
        --gap: 8px;
    }
    .subtitle { font-size: 7pt; }
    .title { font-size: 1.6rem; }
    .icon-btn { width: 36px; height: 36px; }
    .card { padding: 8px 10px 6px; }
    .status { min-height: 3.6rem; }
    .status__title { font-size: 1.45rem; }
    .status__line { font-size: 0.92rem; }
    .status__detail { font-size: 0.8rem; }
}

/* Hard has three answer rows: give it room on short screens. */
@media (max-height: 740px) {
    .app[data-level="hard"] { --staff-w: 10rem; }
    .app[data-level="hard"] .board .ans { height: 46px; }
}

@media (max-height: 640px) {
    .app[data-level="hard"] { --staff-w: 8.5rem; }
    .app[data-level="hard"] .board { gap: 6px; }
    .app[data-level="hard"] .board .ans { height: 40px; font-size: 15px; }
    .app[data-level="hard"] .status { min-height: 3.4rem; }
}

/* Phones in landscape: staff card on the left, controls on the right. */
@media (orientation: landscape) and (max-height: 520px) {
    :root,
    .app[data-level] {
        --staff-w: 12rem;
        --ans-h: 44px;
        --act-h: 44px;
        --gap: 8px;
    }
    .app[data-level="hard"] .status { min-height: 3.6rem; }
    .app {
        width: min(100%, 48rem);
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "head head"
            "card levels"
            "card answers"
            "card actions";
        align-content: center;
        column-gap: 16px;
    }
    .subtitle { display: none; }
    .title { font-size: 1.6rem; }
    .icon-btn { width: 34px; height: 34px; font-size: 16px; }
    .score { padding: 4px 10px; }
    .card { justify-content: center; }
    .board { gap: 6px; }
    .board .ans { height: 36px; font-size: 14px; }
    .status { min-height: 3.6rem; }
}

@media (orientation: landscape) and (max-height: 380px) {
    :root,
    .app[data-level] { --staff-w: 10rem; }
}

/* Easy has no staff: the card is just the prompt and the result. */
.app[data-level="easy"] .staff {
    display: none;
}

.app[data-level="easy"] .card {
    justify-content: center;
    padding: 18px 14px;
}

.app[data-level="easy"] .status {
    min-height: 6rem;
}

.app[data-level="easy"] .status__title {
    font-size: 2.1rem;
}

.app[data-level="easy"] .status__line {
    font-size: 1.1rem;
}

/* ---------- Easy: the floating orbs ---------- */

.app[data-level="easy"] .answers {
    position: relative;
    grid-template-columns: 1fr 1.15fr 1fr;
    align-items: center;
    gap: 0;
    height: 15rem;
}

.app[data-level="easy"] .answers::before {
    content: "";
    position: absolute;
    left: 6%;
    right: 6%;
    top: 50%;
    border-top: 2px dashed var(--ink);
    opacity: 0.12;
    pointer-events: none;
}

.app[data-level="easy"] .ans {
    --orb: 100px;
    position: relative;
    z-index: 1;
    justify-self: center;
    width: var(--orb);
    height: var(--orb);
    padding: 8px;
    border-radius: 50%;
    font-size: 15px;
    white-space: normal;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
    transition: scale 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s, opacity 0.25s, box-shadow 0.25s;
}

.app[data-level="easy"] .ans .acc {
    display: none;
}

.app[data-level="easy"] .ans--flat {
    margin-top: 2.6rem;
    animation: dip 2.8s ease-in-out infinite;
}

.app[data-level="easy"] .ans--intune {
    --orb: 118px;
    z-index: 2;
    font-size: 16px;
    animation: heartbeat 1.6s ease-in-out infinite;
}

.app[data-level="easy"] .ans--sharp {
    margin-bottom: 2.6rem;
    animation: lift 2.8s ease-in-out infinite;
}

.app[data-level="easy"] .ans:active {
    transform: none;
    scale: 0.94;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.35);
}

@media (hover: hover) and (pointer: fine) {
    .app[data-level="easy"] .ans:hover {
        scale: 1.1;
        z-index: 3;
        filter: none;
    }
}

.app[data-level="easy"] .is-idle .ans,
.app[data-level="easy"] .ans.is-wrong {
    box-shadow: none;
}

.app[data-level="easy"] .is-idle .ans.is-right {
    box-shadow: 0 0 0 4px var(--paper), 0 0 0 6px var(--ink);
}

@keyframes dip {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(12px); }
}

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

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    16% { transform: scale(1.07); }
    28% { transform: scale(1); }
    42% { transform: scale(1.05); }
    58% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .app[data-level="easy"] .ans { animation: none; }
}

@media (min-width: 768px) and (min-height: 820px) {
    .app[data-level="easy"] .answers { height: 17.5rem; }
    .app[data-level="easy"] .ans { --orb: 130px; font-size: 17px; }
    .app[data-level="easy"] .ans--intune { --orb: 150px; font-size: 19px; }
    .app[data-level="easy"] .ans--flat { margin-top: 3.4rem; }
    .app[data-level="easy"] .ans--sharp { margin-bottom: 3.4rem; }
}

@media (max-height: 740px) {
    .app[data-level="easy"] .answers { height: 13rem; }
    .app[data-level="easy"] .ans { --orb: 92px; }
    .app[data-level="easy"] .ans--intune { --orb: 108px; }
    .app[data-level="easy"] .status { min-height: 5rem; }
}

@media (max-height: 640px) {
    .app[data-level="easy"] .answers { height: 11rem; }
    .app[data-level="easy"] .ans { --orb: 80px; font-size: 14px; }
    .app[data-level="easy"] .ans--intune { --orb: 92px; font-size: 15px; }
    .app[data-level="easy"] .ans--flat { margin-top: 2rem; }
    .app[data-level="easy"] .ans--sharp { margin-bottom: 2rem; }
    .app[data-level="easy"] .status { min-height: 4.2rem; }
}

@media (orientation: landscape) and (max-height: 520px) {
    .app[data-level="easy"] .answers { height: 9.5rem; }
    .app[data-level="easy"] .ans { --orb: 70px; font-size: 13px; }
    .app[data-level="easy"] .ans--intune { --orb: 82px; font-size: 14px; }
    .app[data-level="easy"] .ans--flat { margin-top: 1.6rem; }
    .app[data-level="easy"] .ans--sharp { margin-bottom: 1.6rem; }
}


/* "As played" / "In tune" label during the comparison */
.card {
    position: relative;
}

.now {
    position: absolute;
    top: 10px;
    left: 12px;
    margin: 0;
    padding: 3px 9px;
    border: 2px solid currentColor;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.now.is-shown {
    opacity: 1;
    transform: scale(1);
}


/* ---------- Volume ---------- */

.icon-btn--vol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn--vol svg {
    width: 20px;
    height: 20px;
}

.icon-btn[aria-expanded="true"] {
    background: var(--ink);
    color: var(--paper);
}

.vol-pop {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    width: min(100%, 19rem);
    box-sizing: border-box;
    padding: 10px 14px;
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.vol-pop[hidden] {
    display: none;
}

.vol-pop__label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.vol-pop__val {
    min-width: 2.6em;
    font-size: 14px;
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.vol-pop input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 32px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}

.vol-pop input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--ink) var(--fill, 75%), #d6d6d6 var(--fill, 75%));
}

.vol-pop input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 999px;
    background: #d6d6d6;
}

.vol-pop input[type="range"]::-moz-range-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--ink);
}

.vol-pop input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    margin-top: -9px;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--paper);
}

.vol-pop input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--paper);
}

@media (max-width: 380px) {
    .score__label { display: none; }
    .subtitle { letter-spacing: 1px; font-size: 7pt; }
    .head__tools { gap: 4px; }
    .icon-btn { width: 36px; height: 36px; font-size: 17px; }
}

.vol-pop input[type="range"]:focus {
    outline: none;
}

.vol-pop input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--flat);
}
