:root {
  --deep-ocean: #06394f;
  --ocean: #087ca7;
  --lagoon: #19b5c9;
  --reef-blue: #7de3e8;
  --sand: #f4d58d;
  --gold: #ffbf3f;
  --coral: #ff6f8f;
  --coral-dark: #d94b70;
  --limu: #3fbf6f;
  --limu-dark: #1f8f52;
  --ink: #073042;
  --white: #ffffff;
  --panel: rgba(255, 255, 255, 0.93);
  --shadow: rgba(3, 31, 44, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #b5f7ff 0, transparent 35%),
    linear-gradient(to bottom, #06455f 0%, #0b91b5 45%, #7de3e8 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

button, select, input { font: inherit; }

.hidden { display: none !important; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* setup */
.setup-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.setup-card {
  width: min(980px, 100%);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border: 4px solid rgba(255,255,255,0.8);
  border-radius: 32px;
  box-shadow: 0 24px 70px var(--shadow);
  padding: clamp(24px, 4vw, 48px);
}

.brand-row {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.mini-uhu {
  width: 96px;
  height: 54px;
  position: relative;
  flex: 0 0 auto;
}

.mini-uhu .body {
  width: 72px;
  height: 42px;
  background: linear-gradient(135deg, #4ee4bd, #276fd9 52%, #a855f7);
  border-radius: 60% 45% 45% 60%;
  position: absolute;
  left: 14px;
  top: 6px;
}

.mini-uhu .tail {
  position: absolute;
  left: 0;
  top: 14px;
  width: 0;
  height: 0;
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
  border-right: 24px solid #ffbf3f;
}

.mini-uhu .beak {
  position: absolute;
  right: 0;
  top: 21px;
  width: 18px;
  height: 12px;
  background: #ffe08a;
  border-radius: 0 12px 12px 0;
}

.mini-uhu .eye {
  position: absolute;
  right: 22px;
  top: 16px;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  border: 2px solid #073042;
}

.title-kicker {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: #087ca7;
  font-weight: 800;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 5rem);
  line-height: 0.92;
  margin: 0;
  color: var(--deep-ocean);
  letter-spacing: -0.06em;
}

.subtitle {
  font-size: 1.06rem;
  line-height: 1.6;
  margin: 12px 0 24px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.field {
  background: #f4fcff;
  border: 2px solid #c5edf3;
  border-radius: 20px;
  padding: 16px;
}

.field label {
  display: block;
  font-weight: 850;
  color: var(--deep-ocean);
  margin-bottom: 8px;
}

.field select {
  width: 100%;
  border: 2px solid #8bdbe6;
  border-radius: 14px;
  padding: 12px 14px;
  background: white;
  color: var(--ink);
}

.share-row,
.setup-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 22px;
}

.copy-status {
  font-size: 0.95rem;
  color: #07536c;
  font-weight: 700;
}

a.secondary-button {
  display: inline-block;
  text-decoration: none;
}

.start-button,
.secondary-button,
.story-panel button {
  border: none;
  border-radius: 18px;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 900;
}

.start-button {
  background: linear-gradient(135deg, #ffbf3f, #ff7b54);
  color: #351a00;
  box-shadow: 0 12px 0 #c95f2f;
}

.secondary-button,
.story-panel button {
  background: var(--deep-ocean);
  color: white;
}

.secondary-link {
  display: inline-block;
  text-decoration: none;
  background: white;
  color: var(--deep-ocean);
  border: 2px solid #c5edf3;
  padding: 12px 16px;
  border-radius: 16px;
  font-weight: 800;
}

.secondary-link.compact {
  padding: 10px 14px;
}

/* top */
.game-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: rgba(3, 48, 69, 0.88);
  color: white;
  padding: 12px 18px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border-bottom: 3px solid rgba(255,255,255,0.25);
  z-index: 20;
}

.resource-links-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 20px;
}

.compact {
  padding: 10px 14px;
  font-size: 0.95rem;
}

.game-title {
  font-size: 1.25rem;
  font-weight: 950;
}

.dashboard {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.24);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 750;
  font-size: 0.92rem;
}

.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.meter-track {
  width: 100px;
  height: 12px;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffbf3f, #f4d58d);
  transition: width 0.35s ease;
}

.health-fill {
  background: linear-gradient(90deg, #3fbf6f, #9cffc0);
}

.game-actions-bar {
  display: flex;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(255,255,255,0.72);
  border-bottom: 1px solid rgba(6,57,79,0.1);
  flex-wrap: wrap;
}

/* reef */
.reef-stage {
  position: relative;
  flex: 1;
  min-height: 720px;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.45), transparent 9%),
    radial-gradient(circle at 75% 20%, rgba(255,255,255,0.25), transparent 13%),
    linear-gradient(to bottom, #0a6e91 0%, #15b2c8 45%, #71dde5 72%, #e7c979 72%, #d6ad5f 100%);
}

.sun-rays {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, rgba(255,255,255,0.2) 0 7%, transparent 7% 16%, rgba(255,255,255,0.11) 16% 22%, transparent 22%),
    linear-gradient(75deg, rgba(255,255,255,0.13) 0 5%, transparent 5% 22%);
  opacity: 0.45;
  pointer-events: none;
}

.story-panel {
  position: absolute;
  left: 24px;
  top: 24px;
  width: min(430px, calc(100% - 48px));
  background: rgba(255,255,255,0.94);
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.22);
  z-index: 12;
}

.story-panel h2 {
  margin: 0 0 8px;
  color: var(--deep-ocean);
}

.story-panel p {
  margin: 0 0 10px;
  line-height: 1.55;
}

.reef-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28%;
  background:
    radial-gradient(circle at 8% 60%, #f5dc99 0 3px, transparent 4px),
    radial-gradient(circle at 26% 70%, #c99746 0 2px, transparent 3px),
    radial-gradient(circle at 55% 64%, #f6e2ab 0 3px, transparent 4px),
    radial-gradient(circle at 79% 76%, #c99746 0 2px, transparent 3px),
    linear-gradient(to bottom, #edd28a, #c99a50);
  border-top: 6px solid rgba(244, 213, 141, 0.85);
}

.grain-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 90px;
  pointer-events: none;
  z-index: 4;
}

.floor-grain {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fff2c4;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(255,255,255,0.35);
}

/* reef patch */
.reef-patch {
  position: absolute;
  width: 120px;
  height: 110px;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 8;
  filter: drop-shadow(0 9px 7px rgba(0,0,0,0.18));
  transition: transform 0.2s ease, filter 0.2s ease;
}

.reef-patch:hover,
.reef-patch:focus {
  transform: translateY(-6px) scale(1.04);
}

.reef-patch:focus-visible {
  outline: 4px solid #ffbf3f;
  border-radius: 24px;
}

.patch-complete {
  opacity: 0.42;
  transform: scale(0.92);
  filter: grayscale(0.25) brightness(0.85);
  cursor: wait;
}

.patch-regrow {
  animation: reefRegrow 0.5s ease;
}

@keyframes reefRegrow {
  0% {
    opacity: 0.45;
    transform: scale(0.92);
    filter: grayscale(0.25) brightness(0.85);
  }

  50% {
    opacity: 1;
    transform: scale(1.08);
    filter: saturate(1.35) brightness(1.15);
  }

  100% {
    opacity: 1;
    transform: scale(1);
    filter: saturate(1) brightness(1);
  }
}

.coral-base {
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 0;
  height: 30px;
  background: #965d46;
  border-radius: 50% 50% 20% 20%;
}

.coral-branch {
  position: absolute;
  bottom: 20px;
  width: 18px;
  background: linear-gradient(to bottom, var(--coral), var(--coral-dark));
  border-radius: 999px;
}

.branch1 { left: 28px; height: 72px; transform: rotate(-8deg); }
.branch2 { left: 52px; height: 88px; }
.branch3 { left: 76px; height: 62px; transform: rotate(10deg); }

.coral-dot {
  position: absolute;
  width: 24px;
  height: 24px;
  background: #ff9fb4;
  border-radius: 50%;
  box-shadow:
    20px 12px 0 #ff86a3,
    -16px 22px 0 #ffb3c3,
    8px 36px 0 #ff7394;
  top: 12px;
  left: 44px;
}

.limu {
  position: absolute;
  bottom: 18px;
  background: linear-gradient(to top, var(--limu-dark), var(--limu));
  width: 12px;
  height: 58px;
  border-radius: 999px 999px 4px 4px;
  transform-origin: bottom;
  animation: sway 2.5s ease-in-out infinite;
}

.limu:nth-child(6) { left: 20px; height: 48px; animation-delay: 0.2s; }
.limu:nth-child(7) { left: 88px; height: 62px; animation-delay: 0.5s; }
.limu:nth-child(8) { left: 101px; height: 42px; animation-delay: 0.8s; }

@keyframes sway {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(8deg); }
}

/* uhu */
.uhu {
  position: absolute;
  left: 80px;
  top: 260px;
  width: 150px;
  height: 82px;
  z-index: 10;
  transition: left 0.95s cubic-bezier(.2,.9,.3,1), top 0.95s cubic-bezier(.2,.9,.3,1), transform 0.35s ease;
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -10px; }
}

.uhu-body {
  position: absolute;
  left: 28px;
  top: 14px;
  width: 100px;
  height: 58px;
  border-radius: 60% 45% 45% 60%;
  background:
    radial-gradient(circle at 72% 36%, white 0 5px, #073042 6px 8px, transparent 9px),
    linear-gradient(135deg, #4ee4bd 0%, #16a2b8 32%, #276fd9 58%, #a855f7 100%);
  overflow: hidden;
}

.uhu-body::after {
  content: "";
  position: absolute;
  left: 25px;
  top: 0;
  width: 16px;
  height: 100%;
  background: rgba(255, 191, 63, 0.55);
  transform: skewX(-15deg);
}

.uhu-tail {
  position: absolute;
  left: 4px;
  top: 27px;
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-right: 34px solid #ffbf3f;
  animation: tail 0.55s ease-in-out infinite;
}

@keyframes tail {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: rotate(9deg); }
}

.uhu-beak {
  position: absolute;
  right: 4px;
  top: 36px;
  width: 28px;
  height: 18px;
  background: #ffe08a;
  border-radius: 0 20px 20px 0;
}

.uhu-fin {
  position: absolute;
  left: 72px;
  top: 55px;
  width: 34px;
  height: 18px;
  background: rgba(255,255,255,0.45);
  border-radius: 50%;
  transform: rotate(-18deg);
}

/* question modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 31, 44, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.question-card {
  width: min(700px, 100%);
  background: white;
  border-radius: 30px;
  padding: 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.35);
  border: 5px solid #c7f2f7;
}

.question-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tag {
  display: inline-flex;
  background: #e8fbff;
  color: #07536c;
  border: 1px solid #bcecf4;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 0.82rem;
}

.question-text {
  font-size: 1.2rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.choice-button {
  border: 3px solid #bdeaf1;
  background: #f4fcff;
  border-radius: 18px;
  padding: 16px;
  font-weight: 950;
  cursor: pointer;
  font-size: 1.05rem;
}

.feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  line-height: 1.45;
  font-weight: 700;
}

.feedback.correct {
  background: #e8fff0;
  color: #136b35;
  border: 2px solid #a5efbd;
}

.feedback.incorrect {
  background: #fff3ee;
  color: #9d3a1b;
  border: 2px solid #ffc0a8;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

/* fact panel */
.fact-panel {
  position: absolute;
  right: 24px;
  top: 84px;
  width: min(360px, calc(100% - 48px));
  background: rgba(255,255,255,0.96);
  border-left: 8px solid var(--gold);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.2);
  z-index: 18;
}

.fact-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.icon-close {
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  color: var(--deep-ocean);
}

/* completion */
.completion-card {
  position: absolute;
  inset: auto 24px 24px 24px;
  background: rgba(255,255,255,0.97);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 46px rgba(0,0,0,0.22);
  z-index: 30;
  border: 4px solid #fff1b8;
}

.completion-card h2 {
  margin: 0 0 8px;
  color: var(--deep-ocean);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.report-box {
  background: #f6fcff;
  border: 2px solid #d6f2f7;
  border-radius: 18px;
  padding: 14px;
}

.report-box h3 {
  margin-top: 0;
  color: var(--deep-ocean);
}

.report-box ul {
  margin: 0;
  padding-left: 18px;
}

.completion-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* sand falling */
.sand-grain {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fff1b8;
  border-radius: 50%;
  z-index: 11;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
  animation: fall 1.3s cubic-bezier(0.45, 0, 0.7, 1) forwards;
  --fall-x: 0px;
  --fall-y: 360px;
}

@keyframes fall {
  0% {
    transform: translate(0, 0) scale(0.8);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--fall-x), var(--fall-y)) scale(1);
    opacity: 1;
  }
}

/* bubbles */
.bubble {
  position: absolute;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 50%;
  animation: rise 6s linear infinite;
  opacity: 0.8;
  z-index: 2;
}

@keyframes rise {
  from { transform: translateY(0) scale(0.7); opacity: 0; }
  15% { opacity: 0.8; }
  to { transform: translateY(-650px) scale(1.4); opacity: 0; }
}

@media (max-width: 800px) {
  .setup-grid,
  .report-grid,
  .choices {
    grid-template-columns: 1fr;
  }

  .brand-row {
    align-items: flex-start;
  }

  .reef-stage {
    min-height: 780px;
  }
}