:root {
  --surface-color: #f8d761;
  --help-surface-color: #fff5d8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  color: #1c1b17;
  background: var(--surface-color);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { overflow: hidden; overscroll-behavior: none; }
body { margin: 0; background: var(--surface-color); }
button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.app {
  height: 100dvh;
}

.app-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 3;
  height: calc(64px + var(--safe-top));
  background: var(--surface-color);
  pointer-events: none;
}

.brand-mark {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 50%;
  z-index: 1;
  width: 80px;
  height: 60px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding-top: 8px;
  transform: translateX(-50%);
  color: #1c1b17;
  font-synthesis: weight;
  line-height: 1;
  white-space: nowrap;
}
.brand-mark span { font-size: 40px; font-weight: 800; }

.stage {
  --stage-top: 52px;
  --stage-right: 20px;
  --stage-bottom: 36px;
  --stage-left: 20px;
  position: relative;
  isolation: isolate;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  touch-action: pinch-zoom;
  -webkit-user-select: none;
  user-select: none;
  padding: calc(var(--stage-top) + var(--safe-top))
    max(var(--stage-right), var(--safe-right))
    max(var(--stage-bottom), var(--safe-bottom))
    max(var(--stage-left), var(--safe-left));
}

.stage::before {
  content: "";
  position: absolute;
  inset: var(--cue-top, 72%) 0 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, #e5b048 82%);
  opacity: 0;
  transition: opacity .42s ease-out;
}
.stage.is-singing::before { opacity: 1; transition-duration: .12s; }

.feedback-visual {
  --reference-stroke: 8;
  --live-stroke: 6px;
  display: block;
  width: min(64dvh, 500px, calc(100vw - 40px));
  height: auto;
  min-width: 0;
  min-height: 0;
  overflow: visible;
  pointer-events: none;
}

.vowel-shape {
  --input-level: 0;
  fill: none;
  stroke: var(--vowel-stroke, var(--help-surface-color));
  stroke-width: calc(var(--live-stroke) + 2px * var(--input-level) + var(--outline-width, 0px));
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-width .09s ease-out;
}
.vowel-shape-outline {
  --vowel-stroke: #5d4d2e;
  --outline-width: 3px;
}

.reference-shape { fill: none; stroke: #1c1b17; stroke-width: var(--reference-stroke); }
@media (prefers-reduced-motion: reduce) {
  .vowel-shape { stroke-width: calc(var(--live-stroke) + var(--outline-width, 0px)); transition: none; }
  .stage::before, .stage.is-singing::before { transition: none; }
}
.actual-pitch-dot { fill: var(--help-surface-color); transition: cy .12s; }
.pitch-dot { fill: #1c1b17; }

.practice-area { position: relative; min-height: 121px; display: flex; flex-direction: column; align-items: center; }
.practice-button {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #1c1b17;
  padding: 0;
  transition: transform .15s;
}
.practice-button:active:not(:disabled) { transform: scale(.96); }
.practice-button:focus-visible, .help-button:focus-visible { outline: 3px solid #1c1b17; outline-offset: 3px; }
.practice-button:disabled { cursor: wait; opacity: .6; }
.practice-button svg { width: 64px; height: 64px; }
.practice-error {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: min(230px, calc(100vw - 32px));
  margin: 0;
  font-size: 13px;
  text-align: center;
}

.help-button {
  --help-border: #a18d5a;
  position: fixed;
  bottom: calc(6px + var(--safe-bottom));
  left: calc(6px + var(--safe-left));
  z-index: 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #4c442d;
}
.help-button span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--help-border);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}
.help-button:active:not(:disabled), .help-button[aria-expanded="true"] { --help-border: #4c442d; color: #1c1b17; }
.help-button:disabled { cursor: wait; opacity: .45; }
.signature {
  position: fixed;
  right: calc(17px + var(--safe-right));
  bottom: calc(17px + var(--safe-bottom));
  z-index: 1;
  font-size: 13px;
  font-weight: 800;
  line-height: 22px;
}
.help-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: min(320px, calc(100vw - 2 * max(20px, var(--safe-left), var(--safe-right))));
  max-height: calc(100dvh - 140px - 2 * var(--safe-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translate(-50%, -50%);
  padding: 19px 20px;
  border: 1px solid #c6ac4d;
  border-radius: 12px;
  background: var(--help-surface-color);
  box-shadow: 0 12px 35px rgb(74 55 13 / 18%);
  font-size: 12px;
  line-height: 1.55;
  color: #4e482e;
}
.help-panel[hidden] { display: none; }
.help-panel h1 { margin: 0 0 10px; color: #1c1b17; font-size: 16px; font-weight: 650; }
.help-panel p { margin: 0; }
.help-panel dl { margin: 14px 0; }
.help-panel dt { margin-top: 10px; color: #1c1b17; font-weight: 650; }
.help-panel dd { margin: 2px 0 0; }

@media (hover: hover) and (pointer: fine) {
  .practice-button:hover:not(:active):not(:disabled) { transform: scale(1.04); }
  .help-button:hover:not(:disabled) { --help-border: #4c442d; color: #1c1b17; }
}

@media (max-width: 700px), (max-height: 500px) and (orientation: landscape) and (any-pointer: coarse) {
  .feedback-visual { --reference-stroke: 12; --live-stroke: 9px; }
}

@media (max-height: 600px) {
  .feedback-visual { width: min(62dvh, 420px, calc(100vw - 40px)); }
  .stage { --stage-top: 40px; --stage-right: 16px; --stage-bottom: 20px; --stage-left: 16px; }
}

@media (max-width: 700px) {
  .stage { gap: 24px; --stage-top: 60px; --stage-right: 20px; --stage-bottom: 28px; --stage-left: 20px; }
  .brand-mark { top: calc(8px + var(--safe-top)); }
}

@media (max-height: 500px) and (orientation: landscape) {
  .app-header { height: calc(16px + var(--safe-top)); }
  .stage { flex-direction: row; gap: 24px; --stage-top: 16px; --stage-right: 72px; --stage-bottom: 16px; --stage-left: 20px; }
  .feedback-visual { width: min(78dvh, calc(100vw - 230px)); }
  .practice-area { min-width: 150px; }
}
