/* Colours and fonts from Tammie's Piano Theory booklet (light) and posters (dark). */

@font-face {
  font-family: 'Fredoka';
  src: local('Fredoka'), url('fonts/Fredoka.ttf') format('truetype');
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: 'Nunito';
  src: local('Nunito'), url('fonts/Nunito.ttf') format('truetype');
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  --bg: #FFFFFF;
  --text: #1F1F1F;
  --ink: #1F1F1F;
  --card: #F3F1EC;
  --muted: #66625B;
  --line: #DAD6CD;
  --tile-text: #1F1F1F;
  --on-accent: #FFFFFF;
  --key-white: #FFFFFF;
  --key-white-down: #EDEBE6;
  --key-black: #1F1F1F;
  --key-black-down: #3A3A3A;
  --note-C: #E63B2E;
  --note-D: #F28C28;
  --note-E: #C99700;
  --note-F: #5A962B;
  --note-G: #258D89;
  --note-A: #8E5BAA;
  --note-B: #E8508A;
  --good: var(--note-F);
  --heading: 'Fredoka', 'Nunito', ui-rounded, system-ui, sans-serif;
  --body: 'Nunito', ui-rounded, system-ui, sans-serif;
  --radius: 20px;
}

/* Dark follows the device, unless a viewer (such as Claude's artifact viewer) sets data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1F1F;
    --text: #F5F3EE;
    --ink: #F5F3EE;
    --card: #2B2B2B;
    --muted: #B8B5AE;
    --line: #3A3A3A;
    --note-E: #F2C230;
    --note-F: #7AB648;
    --note-G: #3FB0AC;
    --note-A: #B48BD1;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1F1F1F;
  --text: #F5F3EE;
  --ink: #F5F3EE;
  --card: #2B2B2B;
  --muted: #B8B5AE;
  --line: #3A3A3A;
  --note-E: #F2C230;
  --note-F: #7AB648;
  --note-G: #3FB0AC;
  --note-A: #B48BD1;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { cursor: default; }

button:focus-visible, input:focus-visible {
  outline: 3px solid var(--note-G);
  outline-offset: 2px;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.screen {
  min-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
}

/* ---- Titles ---- */

.title {
  margin: 24px 0 8px;
  text-align: center;
  font-family: var(--heading);
  line-height: 1.1;
}

.eyebrow {
  display: block;
  font-family: var(--body);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.rainbow-word {
  display: block;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 700;
  text-transform: uppercase;
}

/* ---- New profile and picker ---- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.label {
  font-family: var(--heading);
  font-size: 1.3rem;
}

#name-input {
  font: inherit;
  font-size: 1.6rem;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

.error {
  margin: 0;
  color: var(--note-C);
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.big-choice {
  border: none;
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 96px;
  padding: 12px;
  font-family: var(--heading);
  font-size: 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: inset 0 0 0 2px var(--line);
}

.big-icon { font-size: 2.2rem; line-height: 1; }

.big-icon.clef-icon svg { height: 2.6rem; width: auto; }

.profile-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.profile-list .big-choice {
  background: var(--card);
  box-shadow: none;
  font-size: 1.4rem;
  overflow-wrap: anywhere;
}

.add {
  align-self: center;
  width: 96px;
  font-size: 2.4rem;
}

.text-button {
  align-self: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 12px;
}

/* ---- Practice ---- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill, .icon-button {
  border: none;
  background: var(--card);
  border-radius: 999px;
  min-height: 48px;
  padding: 0 18px;
  font-family: var(--heading);
  font-size: 1.2rem;
}

.pill {
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button { min-width: 48px; padding: 0; font-size: 1.4rem; }

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

.segmented {
  display: flex;
  background: var(--card);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}

.segmented button {
  border: none;
  background: none;
  border-radius: 999px;
  min-height: 44px;
  min-width: 48px;
  padding: 0 12px;
  font-family: var(--heading);
  font-size: 1.05rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.segmented button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

.segmented [data-level] { color: var(--note-D); }
.segmented [data-level][aria-pressed="true"] { color: var(--note-D); }

.clef-icon svg { height: 30px; width: auto; display: block; }

.stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 0;
  font-family: var(--heading);
  font-size: 1.5rem;
}

.stats div, .summary-stats div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stats dt, .summary-stats dt { margin: 0; }
.stats dd, .summary-stats dd { margin: 0; }
.stats dt[aria-label="Correct out of attempted"] { color: var(--good); }

.staff-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
}

.staff { width: 100%; }

.staff svg {
  display: block;
  width: 100%;
  max-height: 34vh;
}

.note-name {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 30px;
}

.note-wrap.wobble {
  transform-box: fill-box;
  transform-origin: center;
  animation: wobble 0.5s ease-in-out;
}

@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-6deg); }
  40% { transform: translateX(5px) rotate(5deg); }
  60% { transform: translateX(-3px) rotate(-3deg); }
  80% { transform: translateX(2px) rotate(2deg); }
}

.tick {
  position: absolute;
  top: 8px;
  right: 16px;
  font-family: var(--heading);
  font-size: 3rem;
  font-weight: 700;
  color: var(--good);
  pointer-events: none;
}

.tick.fade { animation: tick 0.5s ease-out forwards; }

@keyframes tick {
  from { opacity: 1; transform: scale(1.2); }
  to { opacity: 0; transform: scale(1); }
}

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--heading);
  font-size: 5rem;
  font-weight: 700;
  color: var(--note-C);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  border-radius: var(--radius);
}

.level-up {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  background: var(--note-G);
  color: var(--on-accent);
  font-family: var(--heading);
  font-size: 1.15rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.2);
  animation: pop 0.4s ease-out;
}

@keyframes pop {
  from { transform: translateX(-50%) scale(0.6); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

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

.letters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.letter-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.letter-row .letter { flex: 0 0 calc((100% - (var(--cols) - 1) * 6px) / var(--cols)); }

.letters[data-rows="3"] .letter { min-height: 52px; }
.letters[data-rows="4"] .letter { min-height: 46px; font-size: 1.4rem; }

.letter {
  border: none;
  border-radius: 16px;
  min-height: 64px;
  background: var(--tile);
  color: var(--tile-text);
  font-family: var(--heading);
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  font-weight: 700;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.15);
}

.letter:active { transform: translateY(2px); box-shadow: none; }
.letter:disabled { opacity: 0.45; }
.letter.reveal { opacity: 1; outline: 4px solid var(--ink); outline-offset: 2px; }

.keyboard-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border-radius: 12px;
}

.keyboard {
  --white: calc(100% / var(--n));
  position: relative;
  display: flex;
  min-width: calc(var(--n) * 44px);
  height: 160px;
}

.key { border: none; padding: 0; }

.key.white {
  flex: 1;
  background: var(--key-white);
  border: 2px solid var(--key-black);
  border-left-width: 0;
  border-radius: 0 0 8px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
}

.key.white:first-child { border-left-width: 2px; }

.key.black {
  position: absolute;
  top: 0;
  left: calc((var(--after) + 1) * var(--white) - var(--white) * 0.3);
  width: calc(var(--white) * 0.6);
  height: 60%;
  background: var(--key-black);
  border-radius: 0 0 6px 6px;
  z-index: 1;
}

.key.white:active { background: var(--key-white-down); }
.key.black:active { background: var(--key-black-down); }

.key.reveal { background: var(--reveal); }

.key-name {
  font-family: var(--heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--key-black);
}

/* ---- Footer ---- */

.timer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.go, .finish {
  border: none;
  border-radius: 999px;
  min-height: 52px;
  padding: 0 22px;
  font-family: var(--heading);
  font-size: 1.25rem;
}

.go {
  background: var(--note-C);
  color: var(--on-accent);
}

.finish { background: var(--card); }

.time-left {
  font-family: var(--heading);
  font-size: 2rem;
  font-weight: 700;
  min-width: 2.5ch;
  color: var(--note-C);
}

.best-score {
  font-family: var(--heading);
  font-size: 1.2rem;
  color: var(--muted);
}

/* ---- Summary ---- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.45);
  z-index: 5;
}

.summary-card {
  background: var(--bg);
  padding: 28px 24px;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.summary-stats {
  display: flex;
  gap: 28px;
  margin: 0;
  font-family: var(--heading);
  font-size: 2.4rem;
  font-weight: 700;
}

.summary-stats div:first-child dt { color: var(--good); }

/* ---- Confetti ---- */

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.confetti {
  position: absolute;
  top: -12px;
  left: var(--x);
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: fall 1.4s ease-in var(--delay) forwards;
}

@keyframes fall {
  to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); }
}

@media (prefers-reduced-motion: reduce) {
  .confetti { animation-duration: 0.01s; }
  .note-wrap.wobble, .tick.fade, .level-up { animation: none; }
}

/* ---- Larger screens ---- */

@media (min-width: 700px) {
  .letter { min-height: 84px; }
  .keyboard { height: 200px; }
}

/* ---- Captions and summary buttons ---- */

.stats div.with-caption, .summary-stats div.with-caption {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  column-gap: 6px;
  row-gap: 2px;
}

.stat-caption {
  grid-column: 1 / -1;
  line-height: 1.25;
  align-self: start;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.summary-stats .stat-caption { font-size: 0.85rem; }

.summary-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ---- Grand staff and Both clefs ---- */

.staff svg[aria-label="grand staff"] { max-height: 34vh; }

.both-clefs { display: flex; align-items: center; gap: 1px; }
.both-clefs svg { height: 26px; width: auto; display: block; }

/* ---- Locked to 60-second rounds ---- */

.start-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--heading);
  font-size: 1.05rem;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

.start-hint[hidden] { display: none; }
.staff-card:has(.level-up:not([hidden])) .start-hint { display: none; }

.level-up-inline { background: var(--note-G); white-space: nowrap; }
.summary-buttons { flex-wrap: wrap; }
.summary-buttons button { padding: 0 18px; white-space: nowrap; }

/* ---- Level names under the stars ---- */

.segmented button[data-level] { flex-direction: column; gap: 0; padding: 4px 12px; line-height: 1.1; }
.level-name { font-family: var(--body); font-size: 0.7rem; font-weight: 600; color: var(--muted); }

/* ---- Go above the staff, medal with the other scores ---- */

.go-row { justify-content: center; min-height: 52px; }
.stats { gap: 14px; }
.stats .stat-caption { font-size: 0.7rem; }

/* ---- Reset all progress ---- */

.reset-row { display: flex; justify-content: center; margin-top: auto; padding-top: 8px; }
.reset-row .text-button { font-size: 0.9rem; text-decoration: underline; }
.reset-row .text-button:disabled { opacity: 0.4; }
.reset-confirm { text-align: center; }
.reset-confirm p { margin: 0 0 10px; }
.reset-buttons { display: flex; gap: 10px; justify-content: center; }
.reset-yes { background: var(--note-C); color: var(--on-accent); }

/* ---- Go sits in the score row ---- */

.stats-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.stats-row .stats { gap: 10px; font-size: 1.35rem; }
.stats-row .stat-caption { font-size: 0.65rem; }
.go-slot { min-width: 64px; justify-content: center; }
.go.go-green { background: var(--good); padding: 0 16px; min-height: 48px; }
.go-slot .time-left { color: var(--good); }
@media (max-width: 370px) {
  .stats-row, .stats-row .stats { gap: 6px; }
  .stats-row .stats { font-size: 1.2rem; }
}
