:root {
  --cream: #fff6e4;
  --ink: #2a1a10;
  --red: #d7263d;
  --gold: #ffcf3f;
  --teal: #1f4a46;
  --panel: rgba(32, 20, 12, 0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a120d;
  color: var(--cream);
  font-family: 'Fredoka', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  touch-action: none;
}

.hidden { display: none !important; }

/* crosshair */
#crosshair {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 5;
  transform: translate(50vw, 50vh);
}
#crosshair i {
  position: absolute;
  width: 34px;
  height: 34px;
  left: -17px;
  top: -17px;
  border-radius: 50%;
  border: 3px solid var(--cream);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}
#crosshair i::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  left: 11px;
  top: 11px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px var(--cream);
}
body:has(#overlay:not(.hidden)) #crosshair { display: none; }
body:has(#overlay:not(.hidden)) #c { cursor: default; }

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  align-content: start;
  gap: 12px;
  z-index: 4;
}
.panel {
  background: var(--panel);
  border: 2px solid rgba(255, 207, 63, 0.35);
  border-radius: 18px;
  padding: 8px 16px 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
}
.label {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.75;
}
.score { justify-self: start; display: flex; flex-direction: column; }
#score { font-size: 34px; font-weight: 700; line-height: 1.05; color: var(--gold); font-variant-numeric: tabular-nums; }
@keyframes throb { to { transform: scale(1.12); } }

.symphony { justify-self: end; width: 230px; }
.symphony .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#mult { font-size: 22px; color: var(--gold); }
#meter { display: flex; gap: 4px; margin: 6px 0 4px; }
#meter i {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  position: relative;
  overflow: hidden;
}
#meter i::after {
  content: '';
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(var(--fill, 0));
  background: linear-gradient(90deg, #ff8a3d, var(--gold));
  transition: transform 0.15s linear;
}
#meter i:nth-child(4)::after { background: linear-gradient(90deg, #ff5d8f, #ffb3c7); }
#meter i:nth-child(5)::after { background: linear-gradient(90deg, #b46bff, #7fdcff); }
#level { font-weight: 600; font-size: 15px; }
#chord { font-size: 13px; opacity: 0.7; }
#hud[data-level="5"] #level { color: #b9f3ff; text-shadow: 0 0 10px #7fdcff; animation: throb 0.9s ease-in-out infinite alternate; }

#mute {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 207, 63, 0.35);
  background: var(--panel);
  font-size: 20px;
  cursor: pointer;
}

#repo {
  position: fixed;
  right: 16px;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 54px);
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 207, 63, 0.2);
  background: var(--panel);
  color: var(--cream);
  display: grid;
  place-items: center;
  opacity: 0.55;
  transition: opacity 0.2s;
}
#repo:hover, #repo:focus-visible { opacity: 1; }

#hint {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: opacity 0.5s, transform 0.5s;
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 15px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }

/* score popups */
#popups { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  animation: pop 1.4s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 12px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.popup b { display: block; font-size: 30px; color: var(--gold); -webkit-text-stroke: 1px #6b3a00; }
.popup span { display: block; font-size: 15px; font-weight: 600; color: var(--cream); }
.popup.big b { font-size: 42px; color: #fff; -webkit-text-stroke: 1.5px var(--red); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  30% { transform: translate(-50%, -70%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(0.95); }
}

/* overlay */
#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(26, 18, 13, 0.25), rgba(26, 18, 13, 0.75));
  z-index: 10;
}
.card {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border-radius: 28px;
  padding: 28px 30px 22px;
  box-shadow: 0 0 0 6px var(--teal), 0 0 0 10px var(--gold), 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}
h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 50px);
  line-height: 1;
  color: var(--red);
  text-shadow: 0 3px 0 #7a1020;
  transform: rotate(-2deg);
}
h1 span { display: block; color: var(--teal); text-shadow: 0 3px 0 #0e2826; transform: rotate(3deg); }
.tag { margin: 16px 0 12px; font-size: 16px; line-height: 1.4; }
.buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
button#play {
  font: inherit;
  font-weight: 700;
  font-size: 20px;
  padding: 12px 26px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  color: #fff;
  background: var(--red);
  box-shadow: 0 5px 0 #7a1020;
  transition: transform 0.1s, box-shadow 0.1s;
}
button#play:hover { transform: translateY(-2px); }
button#play:active { transform: translateY(3px); box-shadow: 0 2px 0 #7a1020; }


/* Quiet nudges on the title card, one per line: turning a portrait screen sideways,
   and headphones. */
.nudge { margin: 14px 0 0; font-size: 13px; opacity: 0.6; letter-spacing: 0.02em; }
.nudge span { display: block; }
.landscape { display: none; font-size: 13px; opacity: 0.6; letter-spacing: 0.02em; }
.nudge .landscape { opacity: 1; display: none; }
#landscape {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 56px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  color: var(--cream);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  transition: opacity 1.5s ease;
}
#landscape.faded { opacity: 0; }
@media (orientation: portrait) {
  .landscape, .nudge .landscape { display: block; }
}
body:has(#overlay:not(.hidden)) #landscape { display: none; }

@media (max-width: 640px) {
  /* Wrap, and stay clear of the buttons in the bottom-right corner. */
  #hint { font-size: 13px; white-space: normal; text-align: center; max-width: calc(100vw - 150px); border-radius: 14px; }
  .popup b { font-size: 24px; }
}

/* Phones either way up: smaller score and ensemble panels. */
@media (max-width: 640px), (max-height: 500px) {
  #hud { padding: max(10px, env(safe-area-inset-top)) 10px 0; gap: 8px; }
  .panel { padding: 4px 9px 5px; border-radius: 11px; border-width: 1.5px; }
  .label { font-size: 9px; }
  #score { font-size: 18px; }
  .symphony { width: 150px; }
  #mult { font-size: 14px; }
  #meter { gap: 3px; margin: 3px 0 2px; }
  #meter i { height: 6px; border-radius: 3px; }
  #level { font-size: 11px; }
  #chord { font-size: 10px; }
}
