:root {
  --glass: rgba(12, 30, 32, 0.46);
  --glass-strong: rgba(12, 30, 32, 0.72);
  --edge: rgba(255, 255, 255, 0.14);
  --ink: #edf5f2;
  --ink-dim: rgba(237, 245, 242, 0.66);
  --accent: #f0a37f;
  --ui-font: ui-rounded, 'Segoe UI', system-ui, -apple-system, sans-serif;
  --title-font: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #183634;
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#water {
  z-index: 1;
}

#surface {
  z-index: 2;
  touch-action: none;
  cursor: default;
}

/* ---------- toolbar ---------- */
#hud {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  opacity: 0.55;
  transition: opacity 0.35s ease;
}

#hud:hover,
#hud:focus-within {
  opacity: 1;
}

#hud button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

#hud button:hover {
  background: rgba(255, 255, 255, 0.12);
}

#hud button:active {
  transform: scale(0.92);
}

#hud button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#hud button.on {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

#hud svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#hud [data-act='sound'] .wave {
  display: none;
}
#hud [data-act='sound'].on .wave {
  display: inline;
}
#hud [data-act='sound'].on .mute {
  display: none;
}

#count {
  padding: 0 12px 0 6px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  white-space: nowrap;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 5;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- help card ---------- */
#help {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 15, 16, 0.35), rgba(5, 15, 16, 0) 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#help.show {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.card {
  width: min(380px, 100%);
  padding: 24px 26px 20px;
  border-radius: 20px;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  line-height: 1.55;
}

.card h1 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 500;
  font-size: 28px;
  letter-spacing: 0.01em;
}

.card .sub {
  margin: 2px 0 14px;
  color: var(--ink-dim);
  font-style: italic;
  font-family: var(--title-font);
}

.card ul {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.card li {
  padding: 3px 0 3px 18px;
  position: relative;
}

.card li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.75em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.card b {
  font-weight: 600;
}

.card .keys {
  margin: 0;
  color: var(--ink-dim);
  font-size: 12px;
  line-height: 2;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-right: 2px;
  border-radius: 6px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.08);
  font: 600 11px/18px var(--ui-font);
  text-align: center;
  color: var(--ink);
}

.card .hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  text-transform: lowercase;
}

@media (max-width: 480px) {
  #hud button {
    width: 34px;
    height: 34px;
  }
  #count {
    display: none;
  }
}

/* Credit: a quiet link back to the main site, top right, clear of the controls */
#credit {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 30; /* above the help card, so the first tap follows the link */
  padding: 10px 4px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  opacity: 0.55;
  transition: opacity 0.35s ease;
}
#credit:hover,
#credit:focus-visible {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 4px;
}
