/* Black, white and one red. Square corners, heavy rules. */
:root {
  --bg: #fff;
  --ink: #000;
  --muted: #767676;
  --track: #e8e8e8;
  --accent: #e10600;
  --know: #8c8c8c;
  --border: 2px;
  color-scheme: light;
}

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

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 'Helvetica Neue', Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

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

[hidden] {
  display: none !important;
}

header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 56px;
}

#streak {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
  transition: color 0.3s;
}

#streak span {
  color: var(--ink);
  font-weight: 700;
  font-size: 18px;
  transition: color 0.3s;
}

#streak.hot span {
  color: var(--accent);
}

.icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  justify-self: end;
  border-radius: 50%;
  color: var(--muted);
}

/* ---------- Quiz ---------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#prompt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

#prompt > * {
  animation: rise 0.3s ease-out both;
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

h1 {
  font-size: 44px;
  font-weight: 400;
  line-height: 1.1;
}

b {
  font-weight: 700;
}

.score {
  width: 100%;
  pointer-events: none;
}

#prompt .score {
  max-width: 300px;
}

#options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option {
  position: relative;
  min-height: 72px;
  padding: 10px;
  border: var(--border) solid var(--ink);
  background: var(--bg);
  font-size: 19px;
  animation: rise 0.3s ease-out both;
  animation-delay: calc(var(--i) * 35ms);
  transition: transform 0.12s, border-color 0.2s, background 0.2s, opacity 0.2s;
}

.option:active {
  transform: scale(0.96);
}

.scores .option {
  padding: 14px 10px;
}

.done .option:not(.right, .wrong) {
  opacity: 0.45;
}

.option.right {
  background: var(--ink);
  color: var(--bg);
  animation: pop 0.35s ease-out;
}

.option.wrong {
  border-color: var(--accent);
  color: var(--accent);
  animation: shake 0.35s ease-out;
}

.tag {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  animation: rise 0.25s ease-out both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes pop {
  40% {
    transform: scale(1.06);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

/* ---------- Learn ---------- */

#lesson {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.staves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin: 12px 0;
}

/* Boxed like the quiz's answer tiles. */
.staves > div {
  display: flex;
  align-items: center;
  padding: 14px 10px;
  border: var(--border) solid var(--ink);
}

.twin {
  font-size: 14px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.tip {
  max-width: 40ch;
  min-height: 4.2em; /* three lines, so the circle below doesn't jump between keys */
  font-size: 13px;
  color: var(--muted);
}

.circle .on path {
  fill: var(--ink);
  fill-opacity: 1;
}

.circle .on text {
  fill: var(--bg);
}

#learn-circle g:not(.on) path {
  fill: var(--track);
  transition: fill 0.15s;
}

/* ---------- Sheet ---------- */

dialog {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: contain;
}

dialog[open] {
  animation: sheet 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.4);
  animation: fade 0.3s;
}

@keyframes sheet {
  from {
    transform: translateY(100%);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h2 {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.circle {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
}

.circle path {
  fill: var(--know);
  fill-opacity: var(--m);
  cursor: pointer;
}

.circle .new path {
  fill: var(--track);
  fill-opacity: 0.7;
}

.circle text {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.circle text.small {
  font-size: 10.5px;
}

.circle text.info {
  font-size: 13px;
}

.circle text.info tspan + tspan {
  font-size: 10.5px;
  font-weight: 400;
  fill: var(--muted);
}

#totals {
  margin-top: 8px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.seg {
  display: flex;
  padding: 3px;
  background: var(--track);
}

.seg button {
  min-width: 68px;
  padding: 7px 10px;
  font-size: 14px;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.seg button.on {
  background: var(--bg);
  color: var(--ink);
  font-weight: 600;
}

.link {
  display: block;
  margin: 16px auto 0;
  padding: 8px;
  font-size: 14px;
  color: var(--accent);
}

/* ---------- Desktop ----------
   Group the question and answers in the middle of the window instead of
   pinning the answers to the bottom edge, and show the 1-4 key shortcuts. */

@media (min-width: 700px) and (min-height: 560px) {
  body {
    max-width: 600px;
  }

  main {
    justify-content: center;
    gap: 56px;
    padding-bottom: 56px; /* offsets the header so the group sits at true centre */
  }

  #prompt {
    flex: none;
    gap: 20px;
  }

  #learn {
    gap: 24px;
    padding-bottom: 16px;
  }

  #lesson {
    flex: none;
  }

  #learn-circle {
    max-width: 400px;
  }

  #prompt .score {
    max-width: 440px;
  }

  .hint {
    font-size: 16px;
  }

  h1 {
    font-size: 64px;
  }

  .option {
    min-height: 88px;
    font-size: 22px;
  }

  dialog {
    margin: auto;
  }

  dialog[open] {
    animation-name: fade;
  }
}

@media (hover: hover) and (pointer: fine) {
  #options {
    counter-reset: key;
  }

  .option::before {
    counter-increment: key;
    content: counter(key);
    position: absolute;
    top: 6px;
    left: 9px;
    font-size: 12px;
    color: var(--muted);
  }

  #options:not(.done) .option:hover {
    background: var(--track);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  ::backdrop {
    animation: none !important;
    transition: none !important;
  }
}
