:root {
  --reef-ink: #eafbf8;
  --reef-muted: #a9d1d0;
  --reef-panel: #082d38;
  --reef-panel-soft: #0b3943;
  --reef-line: rgb(133 218 208 / 20%);
  --reef-aqua: #76e0d0;
  --reef-gold: #ffd36a;
  --reef-deep: #031a25;
}

.reef-keeper-shell {
  width: min(1500px, calc(100% - 1.5rem));
  margin-inline: auto;
  padding-block: .65rem max(1rem, env(safe-area-inset-bottom));
  overflow-x: clip;
  scrollbar-gutter: stable;
}

.reef-keeper-shell button,
.reef-keeper-shell a {
  touch-action: manipulation;
}

.reef-arcade {
  overflow: hidden;
  border: 1px solid var(--reef-line);
  border-radius: 24px;
  background: linear-gradient(155deg, #062731, #031b25 72%);
  box-shadow: 0 28px 80px rgb(0 12 20 / 34%);
  color: var(--reef-ink);
}

.reef-game-topbar {
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: .85rem;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--reef-line);
  background: rgb(3 25 34 / 88%);
}

.reef-game-topbar h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  line-height: 1;
}

.reef-game-topbar .eyebrow {
  margin: 0 0 .2rem;
  color: var(--reef-aqua);
  font-size: .58rem;
}

.reef-back-link {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--reef-line);
  border-radius: 13px;
  color: var(--reef-ink);
  font-size: 1.25rem;
  text-decoration: none;
}

.reef-loop-copy {
  margin: 0 0 0 auto;
  color: var(--reef-muted);
  font-size: .74rem;
  font-weight: 800;
}

.reef-away-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid rgb(255 211 106 / 30%);
  background: linear-gradient(90deg, rgb(255 211 106 / 13%), rgb(118 224 208 / 8%));
}

.reef-away-summary[hidden] {
  display: none;
}

.reef-away-summary > div {
  display: grid;
  gap: .15rem;
}

.reef-away-summary .eyebrow,
.reef-away-summary strong,
.reef-away-summary small {
  margin: 0;
}

.reef-away-summary progress {
  width: min(300px, 65vw);
}

.reef-game-layout {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  min-height: 0;
}

.reef-section-nav {
  z-index: 4;
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: .35rem;
  padding: .65rem .45rem;
  border-right: 1px solid var(--reef-line);
  background: #041e28;
}

.reef-tab-button {
  display: grid;
  min-height: 62px;
  place-items: center;
  gap: .15rem;
  padding: .45rem .25rem;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  color: var(--reef-muted);
  font: inherit;
  font-size: .61rem;
  font-weight: 850;
  cursor: pointer;
}

.reef-tab-button > span:first-child {
  color: var(--reef-aqua);
  font-size: 1rem;
}

.reef-tab-button:is(:hover, :focus-visible),
.reef-tab-button.is-active {
  border-color: var(--reef-line);
  background: rgb(118 224 208 / 11%);
  color: #fff;
}

.reef-tab-button[hidden] {
  display: none;
}

.reef-game-content {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(310px, .72fr);
  min-width: 0;
  align-items: start;
}

.reef-game-stage,
.reef-system-dock {
  min-width: 0;
}

.reef-game-stage {
  padding: .75rem;
  border-right: 1px solid var(--reef-line);
  background: #05232d;
}

.reef-system-dock {
  max-height: calc(100vh - 100px);
  min-height: 640px;
  padding: .75rem;
  overflow: auto;
  background: #041e28;
  scrollbar-color: rgb(118 224 208 / 35%) transparent;
}

.reef-system-dock .reef-tab-panel[hidden] {
  display: none !important;
}

.reef-system-dock .persistent-panel {
  padding: .75rem;
  border: 0;
  border-radius: 18px;
  background: transparent;
  box-shadow: none;
  color: var(--reef-ink);
}

.reef-system-dock .persistent-panel h2,
.reef-system-dock .persistent-panel strong {
  color: #fff;
}

.reef-system-dock .persistent-panel p,
.reef-system-dock .persistent-panel small {
  color: var(--reef-muted);
}

.reef-resource-hud {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1.1fr 1fr .7fr;
  margin: 0 0 .55rem;
  overflow: hidden;
  border: 1px solid var(--reef-line);
  border-radius: 14px;
  background: rgb(3 23 31 / 88%);
}

.reef-resource-hud > span {
  display: grid;
  grid-template-columns: 1fr !important;
  min-width: 0;
  padding: .48rem .7rem;
  border-right: 1px solid var(--reef-line);
}

.reef-resource-hud > span:last-child {
  border-right: 0;
}

.reef-resource-hud small {
  color: var(--reef-muted);
  font-size: .55rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.reef-resource-hud strong {
  overflow: hidden;
  color: #fff;
  font-size: clamp(1rem, 2vw, 1.45rem);
  text-overflow: ellipsis;
}

.reef-resource-research[hidden] {
  display: none;
}

.reef-living-aquarium {
  position: relative;
  min-height: clamp(390px, 43vw, 620px) !important;
  overflow: hidden;
  border: 1px solid rgb(143 238 225 / 24%);
  border-radius: 20px;
  outline: 0;
  background-color: #087e8c !important;
  background-image: linear-gradient(180deg, rgb(2 36 49 / 3%), rgb(2 28 39 / 24%)), image-set(url('/static/reef/backgrounds/reef-aquarium-s15-960.webp') 1x, url('/static/reef/backgrounds/reef-aquarium-s15-1600.webp') 2x) !important;
  background-position: center !important;
  background-size: cover !important;
  box-shadow: inset 0 0 70px rgb(0 23 31 / 20%);
  isolation: isolate;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.reef-living-aquarium::after {
  display: none !important;
}

.reef-living-aquarium:focus-visible {
  outline: 3px solid var(--reef-gold);
  outline-offset: 3px;
}

.reef-water-light {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 10%, rgb(213 255 242 / 10%) 32%, transparent 50%);
  transform: translateX(-30%);
  animation: reef-light-drift 14s ease-in-out infinite alternate;
}

#reef-scene-decor,
#reef-ambient-bubbles,
#reef-producer-visuals,
#reef-creatures {
  position: absolute;
  inset: 0;
}

#reef-scene-decor {
  display: none;
}

#reef-ambient-bubbles {
  z-index: 2;
  pointer-events: none;
}

#reef-ambient-bubbles i {
  position: absolute;
  bottom: -18px;
  left: var(--bubble-x);
  width: var(--bubble-size);
  height: var(--bubble-size);
  border: 1px solid rgb(226 255 250 / 68%);
  border-radius: 50%;
  animation: reef-bubble-rise var(--bubble-time) linear var(--bubble-delay) infinite;
}

#reef-producer-visuals {
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.reef-life-art {
  position: absolute;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 7px 6px rgb(0 28 37 / 35%));
  transform-origin: 50% 70%;
  animation: reef-life-bob 5.5s ease-in-out var(--life-delay, 0s) infinite alternate;
}

.reef-life-art-fish {
  animation-name: reef-life-swim;
}

#reef-creatures {
  z-index: 5;
  inset: 8% 5% 20%;
  pointer-events: none;
}

.reef-creature {
  position: absolute;
  display: block;
  width: clamp(64px, 11%, 120px);
  pointer-events: auto;
  filter: drop-shadow(0 8px 7px rgb(0 28 37 / 38%));
  animation: reef-resident-swim var(--swim-time, 15s) ease-in-out var(--swim-delay, 0s) infinite alternate;
}

.reef-creature::before,
.reef-creature::after {
  display: none !important;
}

.reef-creature-art {
  display: block;
  width: 100%;
  height: auto;
}

.reef-creature.swims-left .reef-creature-art {
  transform: scaleX(-1);
}

.reef-creature span {
  position: absolute;
  top: 84%;
  left: 50%;
  width: max-content;
  max-width: 160px;
  padding: .2rem .42rem;
  border-radius: 999px;
  background: rgb(2 24 32 / 88%);
  color: #fff;
  font-size: .58rem;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity .2s;
}

.reef-creature:is(:hover, :focus-visible) span {
  opacity: 1;
}

.reef-view-actions {
  position: absolute;
  z-index: 12;
  top: .65rem;
  right: .65rem;
  display: flex;
  gap: .35rem;
}

.reef-view-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 12px;
  background: rgb(1 30 40 / 75%);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.reef-stage-badge {
  position: absolute;
  z-index: 8;
  bottom: .7rem;
  left: .7rem;
  display: grid;
  padding: .4rem .58rem;
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 11px;
  background: rgb(2 30 39 / 73%);
  color: #fff;
  line-height: 1.1;
  backdrop-filter: blur(7px);
}

.reef-stage-badge small {
  color: #c8e9e5;
  font-size: .55rem;
}

.reef-tap-prompt {
  position: absolute;
  z-index: 7;
  top: 50%;
  left: 50%;
  display: grid;
  min-width: 150px;
  padding: .65rem .9rem;
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 999px;
  background: rgb(2 34 44 / 62%);
  color: #fff;
  text-align: center;
  transform: translate(-50%, -50%);
  transition: opacity .35s, transform .35s;
  backdrop-filter: blur(7px);
}

.reef-tap-prompt small {
  color: #d6f4ef;
  font-size: .65rem;
}

.reef-water[data-income-state="building"] .reef-tap-prompt,
.reef-water[data-income-state="ready"] .reef-tap-prompt {
  opacity: .48;
  transform: translate(-50%, -50%) scale(.9);
}

.reef-feed-button {
  display: none !important;
}

.reef-random-event {
  position: absolute;
  z-index: 15;
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  border: 2px solid #fff3bd;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe1 0 18%, #ffd667 20% 48%, #e69725 70%);
  color: #5c3100;
  box-shadow: 0 0 0 8px rgb(255 220 105 / 18%), 0 0 34px rgb(255 215 95 / 72%);
  cursor: pointer;
  animation: reef-shimmer 1.6s ease-in-out infinite alternate;
}

.reef-random-event[hidden] {
  display: none;
}

.reef-random-event span {
  font-size: 1.6rem;
  line-height: 1;
}

.reef-random-event small {
  font-size: .58rem;
  font-weight: 900;
}

.reef-next-goal-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, .75fr);
  align-items: center;
  gap: .75rem;
  margin-top: .55rem;
  padding: .7rem .8rem;
  border: 1px solid var(--reef-line);
  border-radius: 15px;
  background: linear-gradient(100deg, rgb(118 224 208 / 9%), rgb(255 211 106 / 7%));
}

.reef-next-goal-panel h2,
.reef-next-goal-panel p {
  margin: 0;
}

.reef-next-goal-panel h2 {
  color: #fff;
  font-size: .95rem;
}

.reef-next-goal-panel p:not(.eyebrow),
.reef-next-goal-panel small {
  color: var(--reef-muted);
  font-size: .65rem;
}

.reef-objective-progress {
  display: grid;
  gap: .2rem;
  text-align: right;
}

.reef-objective-progress strong {
  color: #fff;
}

.reef-objective-progress progress {
  width: 100%;
  height: .5rem;
  accent-color: var(--reef-aqua);
}

#reef-recommendation {
  display: none !important;
}

.reef-action-deck {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(3, auto);
  align-items: center;
  gap: .45rem;
  margin-top: .55rem;
}

.reef-level-progress {
  display: grid;
  gap: .15rem;
  min-width: 0;
}

.reef-level-progress strong,
.reef-level-progress small {
  overflow: hidden;
  color: var(--reef-muted);
  font-size: .62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reef-level-progress progress {
  width: 100%;
  height: .4rem;
}

.reef-action-deck .button {
  min-height: 44px;
  padding: .5rem .75rem;
}

.reef-action-deck .button small {
  display: block;
  margin-left: .25rem;
}

.reef-action-deck .button[hidden] {
  display: none;
}

.reef-keeper-shell .status-message {
  min-height: 1.25rem;
  margin: .35rem 0 0;
  color: var(--reef-aqua);
  font-size: .7rem;
}

.reef-keeper-shell .status-message.error {
  color: #ffaaa2;
}

.reef-shop-intro {
  margin: .35rem 0 .65rem;
  font-size: .74rem;
}

.reef-buy-quantity {
  display: flex;
  gap: .25rem;
  margin-bottom: .55rem;
}

.reef-buy-quantity[hidden] {
  display: none;
}

.reef-buy-quantity button {
  min-height: 36px;
  flex: 1;
  border: 1px solid var(--reef-line);
  border-radius: 9px;
  background: #0b3a43;
  color: var(--reef-muted);
  font: inherit;
  font-size: .66rem;
  font-weight: 850;
}

.reef-buy-quantity button.is-active {
  border-color: var(--reef-aqua);
  color: #fff;
}

.reef-producers {
  display: grid;
  gap: .55rem;
}

.reef-arcade .reef-producer-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: .55rem;
  min-height: 0;
  padding: .65rem;
  border: 1px solid var(--reef-line);
  border-radius: 14px;
  background: rgb(14 62 69 / 62%);
  color: #eafbf8;
}

.reef-arcade .reef-producer-card strong,
.reef-arcade .reef-producer-card .reef-producer-heading span {
  color: #fff;
}

.reef-arcade .reef-producer-card.is-affordable {
  border-color: rgb(118 224 208 / 68%);
  box-shadow: 0 0 0 3px rgb(118 224 208 / 8%);
}

.reef-arcade .reef-producer-card.is-locked {
  opacity: .58;
}

.reef-producer-art {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--reef-line);
  border-radius: 14px;
  background: rgb(118 224 208 / 9%);
}

.reef-producer-art-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reef-producer-copy {
  min-width: 0;
}

.reef-producer-heading {
  display: flex;
  justify-content: space-between;
  gap: .45rem;
}

.reef-arcade .reef-producer-heading strong {
  font-size: .83rem;
}

.reef-arcade .reef-producer-heading span,
.reef-arcade .reef-producer-copy > small,
.reef-arcade .reef-producer-stats,
.reef-arcade .reef-producer-milestone,
.reef-arcade .reef-producer-milestone-percent {
  color: var(--reef-muted) !important;
  font-size: .59rem;
}

.reef-producer-stats {
  margin-top: .2rem;
}

.reef-producer-milestone-progress {
  width: 100%;
  height: .35rem;
}

.reef-producer-buy {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 42px;
}

.reef-system-dock .panel-heading {
  align-items: center;
  margin-bottom: .25rem;
}

.reef-system-dock .panel-heading .eyebrow {
  margin: 0 0 .1rem;
}

.reef-system-dock .panel-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.reef-activity-panel[hidden] {
  display: none !important;
}

.reef-reveal-layer {
  background: rgb(0 17 24 / 78%);
}

.reef-reveal-card {
  border-color: rgb(118 224 208 / 55%);
  background: linear-gradient(160deg, #f5fffb, #d9f1eb);
}

.reef-game-stage.is-reef-pip {
  background: #05232d;
}

.reef-game-stage.is-reef-pip .reef-next-goal-panel,
.reef-game-stage.is-reef-pip .reef-action-deck,
.reef-game-stage.is-reef-pip .status-message {
  display: none;
}

.reef-game-stage:fullscreen {
  padding: .75rem;
  background: #031a25;
}

.reef-game-stage:fullscreen .reef-living-aquarium {
  min-height: 0 !important;
}

@keyframes reef-light-drift {
  to { transform: translateX(28%); }
}

@keyframes reef-bubble-rise {
  from { opacity: 0; transform: translate(0, 0) scale(.75); }
  15% { opacity: .75; }
  to { opacity: 0; transform: translate(var(--bubble-drift), -520px) scale(1.15); }
}

@keyframes reef-life-bob {
  to { transform: translateY(-5px) rotate(1deg); }
}

@keyframes reef-life-swim {
  from { transform: translateX(-10px) translateY(2px); }
  to { transform: translateX(28px) translateY(-4px); }
}

@keyframes reef-resident-swim {
  from { transform: translateX(calc(var(--swim-distance) * -.25)) translateY(-3px); }
  to { transform: translateX(var(--swim-distance)) translateY(5px); }
}

@keyframes reef-shimmer {
  from { transform: rotate(-7deg) scale(.94); }
  to { transform: rotate(7deg) scale(1.07); }
}

@media (max-width: 1050px) {
  .reef-game-content {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr);
  }

  .reef-action-deck {
    grid-template-columns: 1fr 1fr;
  }

  .reef-level-progress {
    grid-column: 1 / -1;
  }
}

@media (max-width: 800px) {
  .reef-keeper-shell {
    width: calc(100% - .75rem);
    padding-top: .35rem;
  }

  .reef-arcade {
    border-radius: 18px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .reef-game-layout {
    grid-template-columns: 1fr;
  }

  .reef-section-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    min-width: 0;
    flex-direction: row;
    gap: .25rem;
    padding: .35rem;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--reef-line);
    scrollbar-width: none;
  }

  .reef-tab-button {
    min-width: 66px;
    min-height: 48px;
    flex: 0 0 auto;
  }

  .reef-game-content {
    grid-template-columns: 1fr;
  }

  .reef-game-stage {
    padding: .5rem;
    border-right: 0;
    border-bottom: 1px solid var(--reef-line);
  }

  .reef-system-dock {
    min-height: 0;
    max-height: none;
    padding: .35rem;
    overflow: visible;
  }

  .reef-living-aquarium {
    min-height: clamp(300px, 90vw, 430px) !important;
  }

  .reef-next-goal-panel {
    grid-template-columns: 1fr;
  }

  .reef-objective-progress {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .reef-game-topbar {
    min-height: 56px;
    padding: .5rem .6rem;
  }

  .reef-game-topbar .eyebrow,
  .reef-loop-copy {
    display: none;
  }

  .reef-back-link {
    width: 38px;
    height: 38px;
  }

  .reef-away-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .reef-resource-hud {
    margin-bottom: .4rem;
  }

  .reef-resource-hud > span {
    padding: .36rem .45rem;
  }

  .reef-resource-hud strong {
    font-size: .95rem;
  }

  .reef-living-aquarium {
    min-height: clamp(280px, 92vw, 360px) !important;
    border-radius: 15px;
  }

  .reef-view-button {
    width: 36px;
    height: 36px;
  }

  .reef-random-event {
    width: 62px;
    height: 62px;
  }

  .reef-next-goal-panel {
    padding: .55rem .62rem;
  }

  .reef-action-deck {
    grid-template-columns: 1fr 1fr;
  }

  .reef-action-deck .button {
    width: 100%;
    min-width: 0;
  }

  .reef-system-dock .persistent-panel {
    padding: .55rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reef-water-light,
  #reef-ambient-bubbles i,
  .reef-life-art,
  .reef-creature,
  .reef-random-event,
  .reef-feed-reward,
  .reef-food-particle,
  .reef-feed-ripple {
    animation: none !important;
  }

  .reef-tap-prompt,
  .reef-creature span {
    transition: none;
  }
}
