:root {
  --bg: #f6f6f4;
  --ink: #14161a;
  --ink-soft: #4a4e54;
  --ink-faint: #7b7f85;
  --rule: #e4e4e1;
  --card-bg: #ffffff;
  --sand: #d99a4e;
  --sand-deep: #a8672a;
  --sea: #1f6f78;
  --sea-deep: #123a4a;
  --font-body: "Public Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  margin: 0;
  background: #eef4f5;
  color: var(--ink);
}

body {
  margin: 0;
  /* the game's split world, whispered: warm sand up top fading to cool sea */
  background: linear-gradient(180deg, #f8f2e6 0%, #f6f6f4 38%, #edf4f5 100%);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
}

/* soft fixed color washes echoing the landing page's mesh, in Tideline's palette */
.shore-mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.sblob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.16;
  will-change: transform;
}
.s1 {
  width: 480px; height: 480px;
  top: -160px; left: -140px;
  background: #d99a4e;
  animation: sdrift1 24s ease-in-out infinite alternate;
}
.s2 {
  width: 540px; height: 540px;
  bottom: -200px; right: -160px;
  background: #1f6f78;
  animation: sdrift2 30s ease-in-out infinite alternate;
}
@keyframes sdrift1 {
  to { transform: translate(50px, 60px) scale(1.08); }
}
@keyframes sdrift2 {
  to { transform: translate(-60px, -50px) scale(1.1); }
}

a { color: inherit; text-decoration: none; }

::selection { background: var(--sand); color: #14161a; }

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 60px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.back {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-bottom: 32px;
  transition: color 0.15s ease;
}
.back:hover { color: var(--ink); }

.head { padding-bottom: 20px; }

.wordmark {
  position: relative;
  width: fit-content;
  margin: 0 0 20px;
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}
.half-top { color: var(--sand-deep); }
.half-bottom { color: var(--sea); }

/* the wordmark's signature flourish: a waterline that never stops rolling */
.waveline {
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: -13px;
  width: calc(100% - 4px);
  height: 12px;
  overflow: hidden;
  pointer-events: none;
}
.wave-path { animation: waveflow 3.2s linear infinite; }
.wave-back { animation-duration: 5.1s; }
@keyframes waveflow {
  from { transform: translateX(0); }
  to { transform: translateX(-40px); }
}

.tag {
  margin: 0;
  max-width: 46ch;
  font-size: 1.02rem;
  color: var(--ink-soft);
}

.hud {
  display: flex;
  gap: 12px;
  margin: 28px 0 14px;
}
.hud-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 88px;
  padding: 10px 18px 8px;
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(20, 22, 26, 0.05);
}
.hud-item:nth-child(1) .hud-value { color: var(--sea); }
.hud-item:nth-child(2) .hud-value { color: var(--sand-deep); }
.hud-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.hud-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
}

.stage {
  position: relative;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 0 var(--rule), 0 18px 40px -20px rgba(20, 22, 26, 0.35);
  background: #000;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 450;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 18, 0.45);
  backdrop-filter: blur(2px);
  cursor: pointer;
  transition: opacity 0.2s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay-inner {
  text-align: center;
  padding: 24px;
}
.lifeguard {
  width: 210px;
  max-width: 62vw;
  height: auto;
  display: block;
  margin: 0 auto 2px;
  opacity: 0;
  transform: scale(0.3) rotate(-12deg);
}
.overlay.death .lifeguard {
  animation: lifeguardPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes lifeguardPop {
  0% { opacity: 0; transform: scale(0.3) rotate(-12deg); }
  55% { opacity: 1; transform: scale(1.12) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.lifeguard .tweet-lines {
  animation: tweetPulse 0.9s ease-in-out infinite;
}
@keyframes tweetPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay.death .lifeguard { animation: none; opacity: 1; transform: none; }
  .lifeguard .tweet-lines { animation: none; opacity: 0.8; }
}

.overlay-title {
  margin: 0 0 10px;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}
.overlay-sub {
  margin: 0;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.98rem;
  max-width: 32ch;
  margin: 0 auto;
}

.score-entry {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.score-entry.hidden { display: none; }
.score-entry input {
  width: 140px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.score-entry input::placeholder { color: rgba(255, 255, 255, 0.5); }
.score-entry input:focus {
  outline: none;
  border-color: var(--sand);
  background: rgba(255, 255, 255, 0.18);
}
.score-entry button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--sand);
  color: #14161a;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}
.score-entry button:hover { background: #eeb35c; }

.hint {
  margin: 14px 2px 0;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.mute-btn {
  margin-left: 10px;
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 0.85rem;
  cursor: pointer;
  vertical-align: middle;
}
.mute-btn:hover { border-color: var(--ink-faint); }

/* hold-to-nudge buttons, only shown on touch devices */
.touch-nudge {
  display: none;
  position: absolute;
  bottom: 12px;
  z-index: 5;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(20, 22, 26, 0.35);
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.35rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.touch-nudge.left { left: 12px; }
.touch-nudge.right { right: 12px; }
.touch-nudge:active { background: rgba(255, 255, 255, 0.25); }
@media (pointer: coarse) {
  .touch-nudge { display: block; }
}

.leaderboard {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}
.leaderboard-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.leaderboard-list li {
  position: relative;
  z-index: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.88rem;
}
/* tide-gauge bar behind each row, width proportional to the score */
.leaderboard-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: var(--w, 0%);
  background: linear-gradient(90deg, rgba(31, 111, 120, 0.14), rgba(31, 111, 120, 0.02));
  border-radius: 6px;
  z-index: -1;
}
.leaderboard-list li:last-child { border-bottom: none; }
.leaderboard-list .rank {
  color: var(--ink-faint);
  width: 1.4em;
}
.leaderboard-list .name {
  flex: 1;
  color: var(--ink);
  letter-spacing: 0.03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-list .lscore {
  color: var(--sea);
  font-weight: 600;
}
.leaderboard-list .empty {
  color: var(--ink-faint);
  font-style: italic;
}

.foot {
  position: relative;
  margin-top: auto;
  padding-top: 40px;
  color: var(--ink-faint);
  font-size: 0.8rem;
}
.foot-crab {
  position: absolute;
  right: 0;
  bottom: -2px;
  width: 26px;
  height: auto;
  animation: crabwalk 11s ease-in-out infinite alternate;
}
@keyframes crabwalk {
  0% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-34px) rotate(-4deg); }
  50% { transform: translateX(-68px) rotate(0deg); }
  75% { transform: translateX(-102px) rotate(4deg); }
  100% { transform: translateX(-136px) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .sblob, .wave-path, .foot-crab { animation: none !important; }
}
