:root {
  --ink: #2b2418;
  --ink-soft: rgba(43, 36, 24, 0.62);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b3a5a;
  font-family: "Nunito Sans", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.title {
  position: fixed;
  top: calc(18px + var(--safe-top));
  left: calc(20px + var(--safe-left));
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.title .eyebrow {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  font-size: clamp(26px, 3.4vw, 44px);
  line-height: 0.95;
  letter-spacing: -0.01em;
}

.title .hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

@media (max-width: 600px) {
  .title { top: calc(12px + var(--safe-top)); left: calc(14px + var(--safe-left)); }
  .title .eyebrow { font-size: 9px; }
  .title .hint { display: none; }
}

/* ---- creature dock ------------------------------------------------------- */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 8px 10px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 10px 30px rgba(0, 30, 60, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  transition: opacity 0.4s ease;
  max-width: calc(100vw - 24px);
}

.dock-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 6px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(10, 40, 60, 0.75);
  letter-spacing: 0.02em;
}

.dock-full { color: #9a3b1b; }

.cards { display: flex; gap: 8px; }

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 88px;
  padding: 6px 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.32);
  font: inherit;
  color: #13334a;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.2s ease;
}

.card:hover { background: rgba(255, 255, 255, 0.5); transform: translateY(-2px); }
.card:active, .card.lifting { cursor: grabbing; transform: scale(0.96); }
.card:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.card:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }

.card img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 20, 40, 0.3));
}

.card span {
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}

@media (max-width: 600px) {
  .dock { padding: 6px 6px 8px; border-radius: 16px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .cards { gap: 4px; }
  .card { width: calc((100vw - 60px) / 7); max-width: 74px; padding: 4px 2px 5px; border-radius: 11px; }
  .card img { width: 36px; height: 36px; }
  .card span { font-size: 8px; }
}

/* ---- controls -------------------------------------------------------------- */
.controls {
  position: fixed;
  top: calc(14px + var(--safe-top));
  right: calc(14px + env(safe-area-inset-right, 0px));
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 8px 24px rgba(0, 30, 60, 0.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  transition: opacity 0.4s ease;
}

.controls button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.3);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #13334a;
  cursor: pointer;
  transition: background 0.15s ease;
}

.controls button:hover { background: rgba(255, 255, 255, 0.55); }
.controls button[aria-pressed="true"] { background: #13334a; color: #f2fbff; }
.controls button:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }

.controls svg, .show-ui svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.controls kbd {
  font: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(19, 51, 74, 0.12);
  opacity: 0.8;
}
.controls button[aria-pressed="true"] kbd { background: rgba(255, 255, 255, 0.2); }

.whirl-handle {
  position: fixed;
  left: -28px;
  top: -28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.12);
  cursor: grab;
  touch-action: none;
  animation: whirl-spin 3s linear infinite;
}
.whirl-handle.dragging { cursor: grabbing; border-style: solid; }
@keyframes whirl-spin { to { rotate: 360deg; } }

.show-ui {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  color: #13334a;
  opacity: 0.55;
  cursor: pointer;
}
.show-ui:hover { opacity: 1; }

body.ui-hidden .title,
body.ui-hidden .dock,
body.ui-hidden .controls,
body.ui-hidden .minimap,
body.ui-hidden .whirl-handle { opacity: 0; pointer-events: none; }

@media (max-width: 900px) {
  .controls .label, .controls kbd, .head-home kbd { display: none; }
  .controls button { padding: 8px; }
}

@media (max-width: 600px) {
  .controls { flex-direction: column; top: calc(10px + var(--safe-top)); right: calc(10px + env(safe-area-inset-right, 0px)); padding: 5px; gap: 4px; }
  .controls svg { width: 18px; height: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .whirl-handle { animation: none; }
}

.show-ui[hidden] { display: none; }

/* ---- play mode: score, cast button, score pops ------------------------------- */
body.play-mode .title,
body.play-mode .dock { opacity: 0; pointer-events: none; }

.hud {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: calc(16px + var(--safe-left));
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 10px;
  padding: 8px 14px 9px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 24px rgba(0, 30, 60, 0.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  color: #13334a;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.hud[hidden], .cast[hidden], .head-home[hidden] { display: none; }
.hud-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.7;
}
.hud-score {
  font-family: "Fraunces", Georgia, serif;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hud-caught { grid-column: 1 / -1; margin-top: 3px; font-size: 11px; font-weight: 600; opacity: 0.75; }
.hud { grid-template-columns: auto auto auto; }
.hud-time {
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 9px;
  background: rgba(19, 51, 74, 0.12);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.hud-time.low { background: #b3412a; color: #fff6ee; }
.hud-time[hidden] { display: none; }
.hud:has(.hud-time[hidden]) { grid-template-columns: auto auto; }

.home-arrow {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px 5px 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 6px 18px rgba(0, 30, 60, 0.22);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #13334a;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  translate: -50% -50%;
}
.home-arrow[hidden] { display: none; }
.home-arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
body.ui-hidden .home-arrow { opacity: 0; }

.fade {
  position: fixed;
  inset: 0;
  background: #06202e;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.fade.on { opacity: 1; pointer-events: auto; }

/* ---- the village pond ----------------------------------------------------------------- */
body.pond-mode .hud,
body.pond-mode .cast,
body.pond-mode .head-home,
body.pond-mode .title,
body.pond-mode .dock,
body.pond-mode .controls,
body.pond-mode .minimap,
body.pond-mode .whirl-handle { opacity: 0; pointer-events: none; }

.pond-panel {
  position: fixed;
  top: calc(14px + var(--safe-top));
  right: calc(14px + env(safe-area-inset-right, 0px));
  width: min(320px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  padding: 14px 16px 16px;
  border-radius: 20px;
  /* the same frosted glass as the creature dock */
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 10px 30px rgba(0, 30, 60, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  color: #13334a;
}
.pond-panel[hidden] { display: none; }
.pond-panel .eyebrow { margin: 0; font-size: 10px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft); }
.pond-panel h2 { margin: 2px 0 4px; font-family: "Fraunces", Georgia, serif; font-weight: 400; font-size: 26px; }
.pond-summary { margin: 0 0 8px; font-size: 12px; color: #0f5d63; font-weight: 700; }
.pond-stats { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; }
.pond-panel h3 { margin: 14px 0 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.pond-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; }
.pond-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.pond-list li > span:first-child { min-width: 0; }
.pond-btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.pond-list li.pond-empty { color: var(--ink-soft); font-style: italic; }
.pond-panel button {
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #13334a;
  cursor: pointer;
}
.pond-panel button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.7); }
.pond-panel button:disabled { opacity: 0.45; cursor: default; }
.pond-panel button.quiet { background: transparent; }
.pond-panel button.primary { background: #13334a; border-color: #13334a; color: #f2fbff; }
.pond-panel button.primary:hover { background: #0d2536; }
.pond-panel button:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }
.pond-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pond-actions button { flex: 1 1 auto; padding: 9px 12px; }

@media (max-width: 600px) {
  .pond-panel { top: auto; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); right: 10px; left: 10px; width: auto; max-height: 62vh; }
}

.cast {
  position: fixed;
  right: calc(22px + env(safe-area-inset-right, 0px));
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  box-shadow: 0 10px 28px rgba(0, 30, 60, 0.28);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  font: inherit;
  color: #13334a;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, opacity 0.2s ease;
}
.cast:active { transform: scale(0.94); }
.cast:focus-visible { outline: 2px solid #ffffff; outline-offset: 3px; }
.cast-icon { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.cast-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; }
.cast-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.cast-ring circle { fill: none; stroke-width: 4; }
.cast-ring-track { stroke: rgba(19, 51, 74, 0.18); }
.cast-ring-fill { stroke: #0f5d63; stroke-linecap: round; stroke-dasharray: 213.63; }
.cast[aria-pressed="true"] { background: #13334a; color: #f2fbff; }
.cast[aria-pressed="true"] .cast-ring-track { stroke: rgba(242, 251, 255, 0.2); }
.cast[aria-pressed="true"] .cast-ring-fill { stroke: #5cd4cc; }
.cast.low .cast-ring-fill { stroke: #b3412a; animation: mana-pulse 1.2s ease-in-out infinite; }
.cast.low[aria-pressed="true"] .cast-ring-fill { stroke: #ffb4a6; }
@keyframes mana-pulse { 50% { opacity: 0.45; } }
.cast[aria-disabled="true"] { cursor: not-allowed; }
.cast[aria-disabled="true"] .cast-icon, .cast[aria-disabled="true"] .cast-label { opacity: 0.55; }
.cast[aria-disabled="true"]:active { transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Minimap: the whole sea, top-right under the toolbar */
.minimap {
  position: fixed;
  top: calc(72px + var(--safe-top));
  right: calc(14px + env(safe-area-inset-right, 0px));
  padding: 5px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 24px rgba(0, 30, 60, 0.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.minimap[hidden] { display: none; }
.minimap canvas { display: block; width: 200px; height: 108px; border-radius: 9px; }

/* Head home: a frosted pill left of the Cast net circle, vertically centred on it */
.head-home {
  position: fixed;
  right: calc(110px + env(safe-area-inset-right, 0px));
  bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  height: 40px;
  padding: 0 14px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.32);
  box-shadow: 0 10px 28px rgba(0, 30, 60, 0.28);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #13334a;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, opacity 0.2s ease;
}
.head-home svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.head-home kbd {
  font: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(19, 51, 74, 0.12);
  opacity: 0.6;
}
.head-home:active { transform: scale(0.96); }
.head-home:focus-visible { outline: 2px solid #ffffff; outline-offset: 3px; }

.pops { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.score-pop {
  position: absolute;
  left: 0;
  top: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 2px 6px rgba(0, 20, 40, 0.45);
  animation: score-pop 1.1s ease-out forwards;
}
.score-pop.plus { color: #f4ffe9; }
.score-pop.minus { color: #ffb4a6; }
@keyframes score-pop {
  from { opacity: 0; translate: -50% -30%; }
  15% { opacity: 1; }
  to { opacity: 0; translate: -50% -190%; }
}

body.ui-hidden .hud,
body.ui-hidden .cast,
body.ui-hidden .head-home { opacity: 0; pointer-events: none; }

@media (max-width: 600px) {
  .hud { top: calc(10px + var(--safe-top)); left: calc(12px + var(--safe-left)); padding: 6px 12px 7px; }
  .hud-score { font-size: 24px; }
  .cast { width: 68px; height: 68px; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
  .head-home { right: calc(94px + env(safe-area-inset-right, 0px)); bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }
  .minimap { top: calc(10px + var(--safe-top)); right: calc(66px + env(safe-area-inset-right, 0px)); padding: 4px; border-radius: 12px; }
  .minimap canvas { width: 132px; height: 71px; border-radius: 8px; }
}

@media (max-width: 340px) {
  .minimap canvas { width: 104px; height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .score-pop { animation-duration: 0.6s; }
  .cast.low .cast-ring-fill { animation: none; }
}
