/* Full-bleed 3D view with the header and HUD floating on top. */

body {
  padding: 0;
  overflow: hidden;
  background: #9fb8c8;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

header {
  position: fixed;
  inset: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 16px;
  color: #fff;
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.5);
}
header h1 { font-size: 1.25rem; margin: 0 auto 0 0.5rem; }
header a { color: #fff; text-decoration: none; opacity: 0.85; }
header button {
  color: #fff;
  background: rgb(0 0 0 / 0.25);
  border-color: rgb(255 255 255 / 0.35);
  backdrop-filter: blur(6px);
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  color: #fff;
  font-family: var(--mono);
  text-shadow: 0 1px 4px rgb(0 0 0 / 0.6);
}

.hud-top {
  position: absolute;
  top: 3.75rem;
  left: 50%;
  translate: -50% 0;
  display: flex;
  gap: 1.5rem;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: 700;
}

/* The course map, top right: the shape, start (green) and finish (white), a
   dot per boat, and an arrow for you. */
#map {
  position: absolute;
  top: 3.75rem;
  right: 16px;
  width: clamp(130px, 30vmin, 220px);
  max-height: 40vh;
  background: rgb(0 0 0 / 0.25);
  border-radius: 8px;
  overflow: visible;
}
#map.tall { width: auto; height: clamp(110px, 34vh, 220px); }
#map .line { fill: none; stroke: rgb(255 255 255 / 0.75); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
#map .start { fill: #4ade80; }
#map .finish { fill: #fff; stroke: #000; stroke-width: 1; }
#map .rival { fill: #facc15; stroke: rgb(0 0 0 / 0.6); stroke-width: 0.8; }
#map .friend { fill: #38bdf8; stroke: rgb(0 0 0 / 0.6); stroke-width: 0.8; }
#map .you { fill: #f43f5e; stroke: #fff; stroke-width: 1; }

.hud-bottom {
  position: absolute;
  inset: auto 16px 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 1rem;
}

.readout { display: grid; gap: 0.25rem; font-size: 0.9rem; }
.readout b { font-size: 1.6rem; }

#balance { width: clamp(120px, 22vw, 200px); overflow: visible; }
#balance .arc { fill: none; stroke: rgb(255 255 255 / 0.55); stroke-width: 6; stroke-linecap: round; }
#balance .danger { fill: none; stroke: #ff5a3c; stroke-width: 6; stroke-linecap: round; }
#balance line { stroke: #fff; stroke-width: 5; stroke-linecap: round; }
#balance circle { fill: #fff; }
#needle { transform-origin: 100px 100px; }

.meters { justify-self: end; display: grid; gap: 0.35rem; font-size: 0.8rem; width: clamp(100px, 20vw, 180px); }
.meters .bar { height: 10px; border-radius: 5px; background: rgb(0 0 0 / 0.35); overflow: hidden; }
#rhythm { height: 100%; width: 100%; background: linear-gradient(90deg, #4aa3ff, #b48cff); transform-origin: left; }
.bar.rhythm.locked { box-shadow: 0 0 10px #b48cff; }
#flow { font-weight: 600; color: #d9c4ff; }
.bar.sprint.spending { box-shadow: 0 0 10px #ffb347; }
#stamina { height: 100%; width: 100%; background: linear-gradient(90deg, #ff5a3c, #ffd23f 40%, #6fdc8c); transform-origin: left; }

#hud.solo #pos { display: none; }

#wash {
  position: absolute;
  top: 6.4rem;
  left: 50%;
  translate: -50% 0;
  margin: 0;
  padding: 0.2rem 0.7rem;
  border-radius: 1rem;
  background: rgb(0 0 0 / 0.3);
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.4s;
}
#wash.on { opacity: 1; }

#place {
  position: absolute;
  top: 3.6rem;
  left: 50%;
  translate: -50% 0;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgb(0 0 0 / 0.6);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.8s;
}
#place.on { opacity: 1; }

#assisted {
  position: absolute;
  inset: auto 0 9.5rem;
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  opacity: 0.8;
  display: none;
}
#hud.assisted #assisted { display: block; }

.rotate-hint { display: none; color: var(--accent); font-weight: 700; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint { display: block; }
}

/* Fingers need bigger targets than a mouse. */
@media (pointer: coarse) {
  header button, header a { min-height: 40px; display: inline-flex; align-items: center; }
  header button { padding-inline: 1rem; }
}

/* A phone on its side: little height, so tuck everything closer to the edges. */
@media (max-height: 500px) {
  header { padding: 0.35rem 16px; }
  header h1 { font-size: 1rem; }
  header button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
  .hud-top { top: 2.6rem; font-size: 1.1rem; }
  #map { top: 2.4rem; width: 150px; }
  #map.tall { width: auto; height: 28vh; }
  #wash { top: 4.6rem; }
  .hud-bottom { inset: auto 16px 8px; }
  #balance { width: 110px; }
  .readout b { font-size: 1.2rem; }
  #assisted { bottom: 5.5rem; }
  #touchhelp { top: 3.9rem; font-size: 0.75rem; }
  .cue { width: 48px; height: 48px; }
}

/* The beat: the ring on the side to stroke next closes in on the moment. */
.cue {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.35);
  font-weight: 700;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.cue.left { left: 16px; }
.cue.right { right: 16px; }
.cue.next { opacity: 1; }
.cue.now { background: rgb(180 140 255 / 0.45); border-color: #fff; }
.cue .ring {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 3px solid #b48cff;
  opacity: 0;
}
.cue.next .ring { opacity: 1; }

.gauges { display: grid; justify-items: center; gap: 4px; }
.rudder { position: relative; width: 90px; height: 6px; border-radius: 3px; background: rgb(0 0 0 / 0.35); }
.rudder span { position: absolute; top: -3px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #fff; }

#touchhelp {
  position: absolute;
  top: 6.2rem;
  inset-inline: 16px;
  margin: 0;
  text-align: center;
  font-family: var(--font);
  font-size: 0.85rem;
  display: none;
}
#hud.helping #touchhelp { display: block; }

/* Phones: the sprint toggle, under the right-hand beat cue. */
#sprint {
  position: absolute;
  right: 12px;
  top: calc(50% + 48px);
  display: none;
  pointer-events: auto;
  padding: 0.5rem 0.8rem;
  border-radius: 1rem;
  border: 2px solid #ffb347;
  background: rgb(0 0 0 / 0.35);
  color: #fff;
  font-weight: 700;
  touch-action: none;
}
#sprint[aria-pressed="true"] { background: #ff8a1f; }
@media (pointer: coarse) {
  #sprint { display: block; }
}

#tiltdebug {
  position: fixed;
  top: 2.5rem;
  left: 8px;
  z-index: 1;
  margin: 0;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.65);
  color: #9f9;
  font: 11px/1.35 var(--mono);
  pointer-events: none;
  white-space: pre;
}

#standings { columns: 2; column-gap: 2rem; padding-left: 1.5rem; font-family: var(--mono); font-size: 0.9rem; }
#standings .you { font-weight: 700; color: var(--accent); }

#flash {
  position: absolute;
  top: 38%;
  left: 50%;
  translate: -50% -50%;
  margin: 0;
  font-family: var(--font);
  font-size: clamp(2rem, 9vw, 5rem);
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s;
}
#flash.show { opacity: 1; transition: none; }
#flash.small { font-size: clamp(1.1rem, 4vw, 1.8rem); }

body.capsized #view { filter: saturate(0.5) brightness(0.8) hue-rotate(-15deg); }

fieldset.hulls { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 0.75rem; padding: 0.5rem 0.75rem; display: grid; gap: 0.35rem; }
fieldset.hulls legend { color: var(--dim); font-size: 0.85rem; padding: 0 0.25rem; }
fieldset.hulls label { display: flex; align-items: baseline; gap: 0.5rem; cursor: pointer; }

dialog .lede { color: var(--dim); margin-top: -0.5rem; }
dialog .warning { color: var(--accent); }
details { margin-top: 1rem; color: var(--dim); font-size: 0.9rem; }
details ul { padding-left: 1.2rem; }
summary { cursor: pointer; }

@media (max-width: 520px) {
  .readout b { font-size: 1.2rem; }
  .readout { font-size: 0.75rem; }
}

#menu .credit { font-size: 0.8rem; color: var(--dim); }

#menu .account { font-size: 0.9rem; }
#boards #boardlist { display: grid; gap: 0.6rem; font-size: 0.85rem; }
#boards ol { margin: 0.2rem 0 0; padding-left: 1.6rem; }
#boards .you, #livePlayers .you { font-weight: 700; }
#live select, #live input { font: inherit; padding: 0.3rem 0.4rem; }
#live .choice { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
#live .choice button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#live #liveMake small, #live #liveJoinBox small { display: block; margin-top: 0.4rem; color: var(--dim); }
#live input { text-transform: uppercase; letter-spacing: 0.15em; }
#livePlayers { padding-left: 1.2rem; }
#livePlayers small { opacity: 0.75; }
