/* Design tokens and page chrome shared by the landing page and every drill.
   Every page links this before its own stylesheet, so a page can override
   anything here — note-reading widens the column by setting --app-width. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b1d21;
  --muted: #6b7280;
  --line: #d9dce1;
  --accent: #2f5fd0;
  --accent-ink: #ffffff;
  /* Red for stopping, a wrong answer, an error; green for an answer
     revealed or right, a note in tune. Each has its ink for on top. */
  --danger: #b3261e;
  --danger-ink: #ffffff;
  --success: #147d4a;
  --success-ink: #ffffff;
  /* The account's red: its messages follow the theme, while a destructive
     button and a confirming remove keep the one red in either. */
  --alert: #c0392b;
  --alert-solid: #c0392b;
  --radius: 12px;
  --app-width: 440px;
  /* Behind the phone's clock and signal in the installed app, which iOS
     sets in white over the page (the black-translucent status bar). */
  --status-bar: #1b1d21;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #333944;
    --accent: #6f9bff;
    --accent-ink: #0f1115;
    --danger: #ff9c92;
    --danger-ink: #0f1115;
    --success: #6ede9f;
    --success-ink: #0f1115;
    --alert: #ff8a7a;
    --status-bar: #14161a;
  }
}

* {
  box-sizing: border-box;
}

/* An author `display` on a flex or grid container beats the browser's own
   rule for [hidden], so hiding one has to be said here or it does nothing. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.45 system-ui,
    -apple-system, "Segoe UI", Roboto,
    "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Every page reaches the screen's edges (viewport-fit=cover), so the clock
   in the installed app is over it, and a notch beside it in landscape; the
   page keeps clear of both, and of the home bar at the foot. In a browser's
   tab there is nothing there, and these come to nothing. */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  height: env(safe-area-inset-top, 0px);
  background: var(--status-bar);
}

.app {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    calc(40px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* One line, always: the title on the left, the language toggle on the right
   border. App-specific controls live in their own row below the header. */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

/* The way back to the landing page, a slim row above each drill's header,
   with the account's button at its end. */
.site-nav {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: -8px;
}

.home-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}

.home-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* The EN / 中文 toggle every page shows; shared/lang.js builds its buttons.
   Two ordinary buttons joined into one: outer corners rounded, one shared
   border between them, so it matches the other buttons rather than a pill. */
.lang-pick {
  display: inline-flex;
}

.lang {
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.lang:first-child {
  border-radius: 10px 0 0 10px;
}

.lang:last-child {
  border-radius: 0 10px 10px 0;
  border-left: 0;
}

.lang.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.levels {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* A row of choices over a thumb that slides under the chosen one: ear
   training's mode and sounds, the metronome's subdivision. The shell
   (shared/segmented.js) sets --switch-count and --switch-index; a page
   can set the inset and its choices' padding. */
.switch {
  --switch-inset: 3px;
  position: relative;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: var(--switch-inset);
}

.switch-thumb {
  position: absolute;
  top: var(--switch-inset);
  bottom: var(--switch-inset);
  left: var(--switch-inset);
  width: calc((100% - 2 * var(--switch-inset)) / var(--switch-count, 1));
  border-radius: 999px;
  background: var(--accent);
  transform: translateX(calc(var(--switch-index, 0) * 100%));
  transition: transform 0.25s ease;
}

.switch-option {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: var(--switch-option-padding, 7px 14px);
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.25s ease;
}

.switch-option.is-active {
  color: var(--accent-ink);
}

/* Drawn choices: colored by the button they sit in, so the thumb can slide
   under them and flip them. */
.switch-option .icon {
  display: block;
  margin: 0 auto;
}

.switch-option .icon-fill {
  fill: currentColor;
}

@media (prefers-reduced-motion: reduce) {
  .switch-thumb,
  .switch-option {
    transition: none;
  }
}

/* A drill's board: its card, and what reads it out, stacked. Each page sets
   its own gap where it wants another. */
.board {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* The card a drill is started and stopped by: ear training's degree, the
   metronome's pulse, the tuner's note. Each page sizes and spaces its own. */
.start-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Only while it is a start button: the tuner's shell grants and revokes the
   role; the others' cards are one for good. */
.start-card[role='button'] {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.start-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The stopped card's invitation, over the blank its reading leaves. */
.card-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.card-play .icon {
  width: 44px;
  height: 44px;
  /* Optically centered: a triangle's weight sits left of its box. */
  margin-left: 6px;
}

.card-play .icon-fill {
  fill: currentColor;
}

/* The account: a quiet button at the end of the site row, and its dialog.
   shared/account-ui.js draws both. */
.account-link {
  margin-left: auto;
  padding: 0;
  background: none;
  border: 0;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* Signed in, the name, with a dot in the accent: someone is here. */
.account-link.is-signed-in::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

.account-dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 15px;
}

.account-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.account-dialog > * + * {
  margin-top: 12px;
}

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

.account-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.account-dialog h3 {
  margin: 18px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.account-close {
  padding: 0 6px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.account-close:hover {
  color: var(--ink);
}

.account-intro,
.account-hint,
.account-message,
.account-expiry {
  margin: 0;
}

.account-hint,
.account-expiry,
.account-dates {
  font-size: 13px;
  color: var(--muted);
}

.account-message.is-error {
  color: var(--alert);
}

.account-input {
  min-width: 0;
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
}

.account-button,
.account-primary {
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.account-primary {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.account-button:hover:enabled {
  border-color: var(--accent);
}

.account-dialog button:disabled {
  opacity: 0.5;
  cursor: default;
}

.account-create,
.account-rename,
.account-row,
.account-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-create {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.account-create h3 {
  flex-basis: 100%;
  margin-top: 0;
}

/* Room for the whole placeholder: the name has a row of its own. */
.account-create .account-input {
  flex-basis: 100%;
}

/* A username and password, one field to a row, for password managers to
   recognize. */
.account-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-form h3 {
  margin-top: 6px;
}

.account-form > .account-button {
  align-self: flex-start;
}

.account-form .account-foot {
  margin-top: 4px;
}

.account-create .account-quiet {
  padding-inline: 0;
  text-align: start;
}

.account-passkeys {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.account-passkey {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.account-passkey + .account-passkey {
  border-top: 1px solid var(--line);
}

.account-passkey-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.account-tag {
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
}

.account-remove,
.account-quiet {
  padding: 6px 8px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.account-remove:hover:enabled,
.account-quiet:hover:enabled {
  color: var(--ink);
  text-decoration: underline;
}

.account-remove.is-confirming,
.account-danger,
.account-danger:hover:enabled {
  color: var(--alert-solid);
}

.account-danger-button {
  background: var(--alert-solid);
  border-color: var(--alert-solid);
  color: #fff;
}

.account-foot {
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* A QR code is read by cameras, not people: black on white in either theme,
   as large as the dialog allows. */
.account-qr {
  width: min(240px, 100%);
  margin-inline: auto;
  border-radius: 8px;
  overflow: hidden;
}

.account-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.account-url {
  font-size: 13px;
}

/* A saved score's title and composer, in the account's dialog look
   (shared/details-dialog.js). */
.details-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.details-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.details-field .account-input {
  font-size: 15px;
  font-weight: normal;
}

.details-buttons {
  justify-content: flex-end;
}

.details-buttons .account-primary {
  width: auto;
}
