/* Black, white and one red. Square corners, heavy rules. */
:root {
  --bg: #fff;
  --ink: #000;
  --muted: #767676;
  --track: #e8e8e8;
  --soft: #f2f2f2; /* highlighted table rows and columns */
  --ghost: #b5b5b5; /* scale notes not yet compared */
  --accent: #e10600;
  --know: #8c8c8c; /* fully known, in progress charts */
  --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;
}

header .left {
  display: flex;
  align-items: center;
  gap: 4px;
}

#home-btn {
  margin: 0 0 0 -12px;
  color: var(--ink);
}

/* On the home screen there is no topic to go back from, no streak and no Quiz | Learn. */
[data-screen='home'] :is(header .left, #view, #open-menu) {
  visibility: hidden;
}

#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;
}

.why {
  max-width: 34ch;
  font-size: 15px;
  animation: rise 0.25s ease-out both;
}

#after {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 10px;
  animation: rise 0.25s ease-out both;
}

#after button {
  height: 56px;
  border: var(--border) solid var(--ink);
  font-weight: 600;
}

#next {
  background: var(--ink);
  color: var(--bg);
}

#show-me[hidden] + #next {
  grid-column: 1 / -1;
}

.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);
  }
}

/* ---------- Home ---------- */

#home {
  justify-content: center;
  gap: 8px;
  padding-bottom: 56px;
}

.home-title {
  font-size: 34px;
  font-weight: 700;
}

#topics {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border: var(--border) solid var(--ink);
  text-align: left;
  animation: rise 0.3s ease-out both;
  animation-delay: calc(var(--i) * 60ms);
  transition: transform 0.12s;
}

.tile:active {
  transform: scale(0.98);
}

.tile .score {
  max-width: 120px;
  margin-bottom: 4px;
}

.tile b {
  font-size: 21px;
}

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

.bar {
  height: 4px;
  margin-top: 4px;
  background: var(--track);
}

.bar i {
  display: block;
  height: 100%;
  background: var(--ink);
}

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

#learn-keys,
#learn-intervals {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Intervals: the method, step by step */

#learn-intervals {
  gap: 10px;
  padding-bottom: 12px;
}

.walk-title {
  margin: 20px 0 6px;
  font-size: 34px;
  text-align: center;
}

.another {
  align-self: center;
  margin-top: -6px;
  padding: 4px 8px;
  font-size: 15px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.walk-title span {
  font-size: 18px;
  color: var(--muted);
}

.score.walk {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.walk .unseen {
  opacity: 0;
}

.walk .ghost {
  color: var(--ghost);
  animation: fade 0.35s ease-out both;
}

.walk .changed {
  color: var(--accent);
  animation: fade 0.35s ease-out both;
}

.walk text.degree,
.walk text.diff {
  stroke: none;
}

.walk text.degree {
  font:
    600 11px 'Helvetica Neue',
    Helvetica,
    Arial,
    sans-serif;
  fill: var(--muted);
  text-anchor: middle;
}

.walk text.fresh {
  animation: fade 0.3s ease-out both;
}

.walk .link {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.walk text.diff {
  font:
    600 11px 'Helvetica Neue',
    Helvetica,
    Arial,
    sans-serif;
  fill: var(--accent);
  text-anchor: middle;
}

.caption {
  min-height: 4.4em;
  font-size: 15px;
  text-align: center;
}

.dots {
  margin-top: auto;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.dots i {
  width: 6px;
  height: 6px;
  background: var(--track);
}

.dots i.on {
  background: var(--ink);
}

.walk-controls {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}

.walk-controls button {
  height: 48px;
  border: var(--border) solid var(--ink);
  font-weight: 600;
}

.walk-controls .fwd {
  background: var(--ink);
  color: var(--bg);
}

.walk-controls button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* The quality table, filled in as the steps reach it. */
table.qualities {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: center;
}

.qualities th,
.qualities td {
  padding: 6px 4px;
  border: 1px solid var(--track);
  transition:
    background 0.3s,
    color 0.3s;
}

.qualities th {
  font-weight: 400;
  color: var(--muted);
}

.qualities th:first-child {
  text-align: left;
}

.qualities small {
  color: var(--muted);
}

.qualities .in-col,
.qualities .in-row {
  background: var(--soft);
  color: var(--ink);
}

.qualities th.in-col,
.qualities th.in-row {
  font-weight: 700;
}

.qualities td.hit {
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
}

/* Interval progress: the quality table as a grid of squares. */
.grid-wrap {
  overflow-x: auto;
}

table.known {
  margin: 0 auto;
  border-collapse: separate;
  border-spacing: 4px;
  font-size: 12px;
}

.known th {
  font-weight: 400;
  color: var(--muted);
}

.known tr th:first-child {
  padding-right: 6px;
  text-align: right;
  white-space: nowrap;
}

.known td {
  width: 28px;
  height: 28px;
  background: color-mix(in srgb, var(--know) calc(var(--m) * 100%), transparent);
  cursor: pointer;
}

.known td.new {
  background: var(--track);
}

.known td.none {
  background: none;
  cursor: default;
}

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

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

.staves {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 12px 0;
}

/* Boxed like the quiz's answer tiles. */
.staves > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: calc(50% - 5px);
  padding: 12px 10px 8px;
  border: var(--border) solid var(--ink);
}

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

.staves span {
  font-size: 12px;
  color: var(--muted);
}

.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);
  outline: none;
}

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

.sheet-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

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

.welcome {
  margin-top: 4px;
  font-size: 15px;
}

#start {
  width: 100%;
  height: 52px;
  margin-top: 20px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

/* Welcome and Start only on the first visit; progress only after it. */
#menu:not(.first) :is(.welcome, #start),
#menu.first #progress {
  display: none;
}

.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);
}

/* The Quiz | Learn switch: one choice at a time. */
.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;
}

.note {
  margin: -4px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.row > span {
  font-size: 14px;
}

.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Each option is its own on/off toggle with a checkbox, so several can be on. */
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 10px;
  border: 1px solid var(--track);
  font-size: 14px;
  color: var(--muted);
  transition:
    border-color 0.2s,
    color 0.2s;
}

.check::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  transition: background 0.2s;
}

.check.on {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 600;
}

.check.on::before {
  border-color: var(--ink);
  /* a white tick on a black square */
  background: var(--ink)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7.5l2.5 2.5L11 4.5' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E")
    center / 100% no-repeat;
}

.check.last {
  cursor: not-allowed;
}

.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;
  }

  #after {
    margin-top: -46px; /* sit 10px under the options, not a full section gap */
  }

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

  #learn-intervals {
    justify-content: center;
    gap: 20px;
    padding-bottom: 56px;
  }

  #learn-intervals .dots {
    margin-top: 12px;
  }

  .score.walk {
    max-width: 480px;
  }

  #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;
  }
}
