* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #061826;
  /* A downward drag near the top of the page would otherwise trigger
     pull-to-refresh on Android and reload the reef mid-stroke. */
  overscroll-behavior: none;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  color: #cfe8f0;
  -webkit-font-smoothing: antialiased;
  /* The whole screen is a drag surface: never let a stroke select text or
     raise the iOS callout menu. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#reef {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;      /* the whole surface is the drawing gesture */
  cursor: crosshair;
}

/* The reef is focusable so its residents can be walked with the arrow keys.
   It comes first in the tab order, which the sound button used to hold — that
   was for WCAG 1.4.2, and nothing autoplays any more, so the reef itself is
   the better first stop. */
#reef:focus { outline: none; }
#reef:focus-visible {
  outline: 2px solid rgba(224, 245, 250, 0.45);
  outline-offset: -3px;
}

/* Reachable by a screen reader, invisible to everyone else. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Both overlays sit low and quiet. Nothing here reports state — the reef
   itself is the readout. */
#hint, #notice {
  position: fixed;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 8px rgba(0, 20, 30, 0.6);
}

/* Placed against the seabed line, which game.js publishes as --floor. Coral
   grows upward from there, so anything anchored to the bottom of the screen
   ends up written across the reef — badly so on a phone. */
#hint {
  top: calc(var(--floor, 88%) + 44px);
  color: rgba(207, 232, 240, 0.5);
  transition: opacity 1.6s ease;
}

#hint.gone { opacity: 0; }

#notice {
  top: calc(var(--floor, 88%) + 20px);
  color: rgba(228, 245, 250, 0.82);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 1.1s ease, transform 1.1s ease;
}

#notice.show {
  opacity: 1;
  transform: translateY(0);
}

/* The reef log, opposite the sound control. Everything that has moved in, in
   the order it did, against the age of the reef at the time. */
#log-controls {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 8px;
  z-index: 10;
}

#log-open {
  width: 30px;
  height: 30px;
  padding: 5px;
  border: 0;
  background: none;
  color: rgba(207, 232, 240, 0.42);
  cursor: pointer;
  transition: color 0.3s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#log-open:hover, #log-open:focus-visible { color: rgba(224, 245, 250, 0.92); }
#log-open:focus { outline: none; }
#log-open:focus-visible { outline: 1px solid rgba(224, 245, 250, 0.5); outline-offset: 3px; }

#log-open svg { width: 100%; height: 100%; display: block; }
#log-open path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

#log-panel {
  width: min(330px, calc(100vw - 44px));
  max-height: min(58vh, 420px);
  overflow-y: auto;
  padding: 15px 17px;
  border-radius: 11px;
  background: rgba(6, 24, 38, 0.9);
  border: 1px solid rgba(150, 205, 220, 0.16);
  backdrop-filter: blur(11px);
  box-shadow: 0 6px 26px rgba(0, 12, 22, 0.42);
}

#log-panel[hidden] { display: none; }

#log-age, #log-left {
  margin: 0;
  font-size: 11.5px;
  font-weight: 300;
  letter-spacing: 0.05em;
  color: rgba(140, 210, 220, 0.72);
}

#log-left {
  margin-top: 12px;
  color: rgba(207, 232, 240, 0.4);
}

#log-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

#log-list li + li {
  margin-top: 13px;
  padding-top: 13px;
  border-top: 1px solid rgba(150, 205, 220, 0.1);
}

.log-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
}

.log-name {
  font-size: 14.5px;
  color: rgba(232, 246, 250, 0.94);
}

.log-when {
  flex: none;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: rgba(140, 210, 220, 0.78);
}

.log-left-note {
  margin: 5px 0 0;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: rgba(216, 168, 160, 0.7);
}

#log-list li.gone .log-name,
#log-list li.gone .log-when { opacity: 0.5; }
#log-list li.gone .log-note { opacity: 0.45; }

.log-note {
  margin: 4px 0 0;
  font-size: 12.5px;
  font-weight: 300;
  line-height: 1.5;
  color: rgba(207, 232, 240, 0.66);
}

@media (pointer: coarse) {
  #log-open { width: 40px; height: 40px; padding: 8px; color: rgba(207, 232, 240, 0.7); }
  #log-controls { bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
}

/* Raised the first time a species is ever seen. Sits in the open water above
   the reef so it never covers the thing it is telling you about, and has no
   timer — the player closes it when they have read it. */
#card {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(320px, calc(100vw - 48px));
  padding: 18px 20px 16px;
  border-radius: 12px;
  background: rgba(6, 24, 38, 0.88);
  border: 1px solid rgba(150, 205, 220, 0.18);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(0, 12, 22, 0.45);
  text-align: left;

  /* Surfaces rather than appears. The transform has to carry the centring
     translate in both states or the card jumps sideways as it moves. */
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  transition: opacity 0.65s ease, transform 0.65s ease;
}

#card.in {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#card[hidden] { display: none; }

.card-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(140, 210, 220, 0.75);
}

#card-name {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: rgba(232, 246, 250, 0.96);
}

#card-note {
  margin: 0;
  font-size: 13.5px;
  font-weight: 300;
  line-height: 1.55;
  color: rgba(207, 232, 240, 0.8);
}

#card-more {
  margin: 10px 0 0;
  font-size: 11.5px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: rgba(207, 232, 240, 0.45);
}

#card-close {
  margin-top: 14px;
  padding: 7px 16px;
  border: 1px solid rgba(150, 205, 220, 0.28);
  border-radius: 7px;
  background: none;
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: rgba(207, 232, 240, 0.8);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s ease, border-color 0.25s ease;
}

#card-close:hover, #card-close:focus-visible {
  color: rgba(232, 246, 250, 1);
  border-color: rgba(150, 205, 220, 0.6);
}

#card-close:focus { outline: none; }
#card-close:focus-visible { outline: 1px solid rgba(224, 245, 250, 0.5); outline-offset: 3px; }

@media (pointer: coarse) {
  /* A comfortable target, and clear of the notch on a phone. */
  #card { top: max(18%, calc(24px + env(safe-area-inset-top, 0px))); }
  #card-close { padding: 11px 20px; font-size: 14px; }
}

/* Mirrors the sound control in the opposite corner, and sits in the same
   band of seabed so it never overlaps coral. */
#kofi {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.05em;
  color: rgba(207, 232, 240, 0.38);
  text-decoration: none;
  text-shadow: 0 1px 8px rgba(0, 20, 30, 0.6);
  transition: color 0.3s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#kofi:hover, #kofi:focus-visible {
  color: rgba(224, 245, 250, 0.9);
  text-decoration: underline;
}

#kofi:focus { outline: none; }
#kofi:focus-visible { outline: 1px solid rgba(224, 245, 250, 0.5); outline-offset: 3px; }

/* The only UI in the game. Kept as quiet as the rest of the screen — it
   should be findable, not noticeable. Anchored bottom-right; the panel opens
   upward from the button so it never covers the seabed. */
#audio-controls {
  position: fixed;
  /* Insets keep the control clear of a notch or home indicator when the
     page is laid out edge to edge. */
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  /* Reversed: the trigger comes first in the DOM so Tab moves from it into
     the panel it opens, but reads bottom-of-stack on screen. */
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 8px;
  z-index: 10;
}

#soundhint {
  margin: 0;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: rgba(207, 232, 240, 0.5);
  text-shadow: 0 1px 8px rgba(0, 20, 30, 0.6);
  pointer-events: none;
  transition: opacity 1.2s ease;
}

#soundhint.gone { opacity: 0; }

#sound {
  width: 34px;
  height: 34px;
  padding: 6px;
  align-self: flex-end;
}

#sound, .mix-toggle {
  border: 0;
  background: none;
  color: rgba(207, 232, 240, 0.42);
  cursor: pointer;
  transition: color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;      /* no double-tap zoom, no 300ms delay */
}

#sound:hover, .mix-toggle:hover,
#sound:focus-visible, .mix-toggle:focus-visible { color: rgba(224, 245, 250, 0.92); }

#sound:focus, .mix-toggle:focus, #mixer input:focus { outline: none; }
#sound:focus-visible, .mix-toggle:focus-visible, #mixer input:focus-visible {
  outline: 1px solid rgba(224, 245, 250, 0.5);
  outline-offset: 3px;
}

#sound svg, .mix-toggle svg { width: 100%; height: 100%; display: block; }
.cone { fill: currentColor; }
.wave, .slash {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.slash { display: none; }
#sound.muted .wave, .mix-toggle.off .wave { display: none; }
#sound.muted .slash, .mix-toggle.off .slash { display: block; }

#mixer {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(6, 24, 38, 0.82);
  border: 1px solid rgba(150, 205, 220, 0.16);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 22px rgba(0, 12, 22, 0.4);
}

#mixer[hidden] { display: none; }

.mix-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mix-row + .mix-row { margin-top: 10px; }

.mix-toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  flex: none;
}

.mix-label {
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.05em;
  color: rgba(207, 232, 240, 0.72);
  width: 46px;
  flex: none;
}

#mixer input[type="range"] {
  width: 104px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: rgba(140, 210, 220, 0.9);
  background: none;
}

@media (max-width: 600px) {
  #hint, #notice { font-size: 12px; padding: 0 24px; }
}

/* Touch, not mouse. There is no hover to reveal the control, so it sits
   brighter, and every target grows to a comfortable size. */
@media (pointer: coarse) {
  #sound { width: 44px; height: 44px; padding: 10px; }
  /* Same brighter resting state as the sound control, and enough padding
     that the link is a real touch target rather than a 16px line of text. */
  #kofi { color: rgba(207, 232, 240, 0.62); padding: 8px 0; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .mix-toggle { width: 32px; height: 32px; }
  #mixer { padding: 14px 16px; }
  #mixer input[type="range"] { width: 104px; height: 28px; }
  .mix-row + .mix-row { margin-top: 14px; }
  #sound, .mix-toggle { color: rgba(207, 232, 240, 0.7); }
}
