.drift-shell {
  width: min(calc(100% - 28px), 980px);
}

.drift-hud {
  display: grid;
  grid-template-columns: 1.25fr 2fr .8fr .8fr;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel);
  margin-bottom: 14px;
}

.hud-cell {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.hud-cell:last-child {
  border-right: 0;
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.hud-cell strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

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

.hud-row .hud-label {
  display: inline;
}

.hud-row strong {
  margin: 0;
}

.meter {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #292c30;
}

.meter-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  transition: width .18s linear;
}

.meter-fill.warning {
  background: #f7b955;
}

.meter-fill.danger {
  background: #ef6b65;
}

.drift-field {
  position: relative;
  overflow: hidden;
  min-height: 540px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #122335;
  isolation: isolate;
  -webkit-user-select: none;
  user-select: none;
}

.sky {
  position: absolute;
  inset: 0 0 44% 0;
  overflow: hidden;
  background: linear-gradient(to bottom, #86c7db, #c9dfe2);
  transition: background 1s linear;
}

.sun-moon {
  position: absolute;
  top: 34px;
  right: 12%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #f4e6aa;
  box-shadow: 0 0 35px rgba(255, 236, 170, .28);
  transition: background .6s ease, box-shadow .6s ease;
}

.sky.night {
  background: linear-gradient(to bottom, #132134, #354054);
}

.sky.night .sun-moon {
  background: #e8edf2;
  box-shadow: 0 0 24px rgba(230, 238, 246, .24);
}

.sky.dusk {
  background: linear-gradient(to bottom, #865e62, #d99a78);
}

.cloud {
  position: absolute;
  width: 120px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .52);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 0;
  border-radius: 50%;
  background: inherit;
}

.cloud::before {
  width: 42px;
  height: 42px;
  left: 24px;
}

.cloud::after {
  width: 54px;
  height: 54px;
  right: 22px;
}

.cloud-a {
  top: 64px;
  left: 12%;
  transform: scale(.75);
}

.cloud-b {
  top: 130px;
  right: 26%;
  transform: scale(.5);
  opacity: .72;
}

.horizon {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 56%;
  height: 1px;
  background: rgba(255,255,255,.28);
}

.sea {
  position: absolute;
  inset: 56% 0 0 0;
  overflow: hidden;
  background: linear-gradient(to bottom, #246987, #0c405c 60%, #082e46);
  transition: background 1s linear;
}

.sky.night + .horizon + .sea {
  background: linear-gradient(to bottom, #163e56, #092d43 60%, #061e30);
}

.wave {
  position: absolute;
  left: -10%;
  width: 120%;
  height: 28px;
  opacity: .35;
  background:
    radial-gradient(ellipse at 50% 100%, transparent 54%, rgba(255,255,255,.55) 56%, transparent 61%)
    0 0 / 70px 28px repeat-x;
  animation: wave-shift 6s linear infinite;
}

.wave-one { top: 22%; }
.wave-two {
  top: 62%;
  opacity: .22;
  animation-duration: 9s;
  animation-direction: reverse;
}

@keyframes wave-shift {
  to { transform: translateX(70px); }
}

.raft {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 22%;
  width: 150px;
  height: 62px;
  transform: translateX(-50%);
  animation: raft-bob 2.6s ease-in-out infinite;
}

@keyframes raft-bob {
  0%, 100% { transform: translateX(-50%) rotate(-1deg) translateY(0); }
  50% { transform: translateX(-50%) rotate(1deg) translateY(5px); }
}

.raft-log {
  position: absolute;
  left: 0;
  width: 150px;
  height: 17px;
  border-radius: 999px;
  background: #8b5a35;
  border: 2px solid #5e3b24;
}

.raft-log-1 { bottom: 0; }
.raft-log-2 { bottom: 15px; left: 4px; }
.raft-log-3 { bottom: 30px; left: -3px; }

.raft-rope {
  position: absolute;
  z-index: 2;
  left: 28px;
  bottom: 0;
  width: 6px;
  height: 48px;
  border-left: 3px solid #d6b47c;
  border-right: 3px solid #d6b47c;
  opacity: .8;
}

.survivor {
  position: absolute;
  z-index: 4;
  left: 58px;
  bottom: 44px;
  width: 42px;
  height: 76px;
  transform-origin: bottom center;
}

.survivor-head {
  position: absolute;
  top: 0;
  left: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e3b58d;
}

.survivor-head::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -2px;
  width: 25px;
  height: 10px;
  border-radius: 60% 60% 20% 20%;
  background: #25272a;
}

.survivor-body {
  position: absolute;
  top: 22px;
  left: 7px;
  width: 29px;
  height: 46px;
  border-radius: 8px 8px 4px 4px;
  background: #d8d6c5;
  transform: skewX(-3deg);
}

.survivor-arm {
  position: absolute;
  top: 31px;
  left: 29px;
  width: 30px;
  height: 8px;
  border-radius: 999px;
  background: #e3b58d;
  transform: rotate(-20deg);
  transform-origin: left center;
}

.bird-layer,
.debris-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bird {
  position: absolute;
  z-index: 8;
  width: 72px;
  height: 48px;
  pointer-events: auto;
  cursor: crosshair;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.bird-body {
  position: absolute;
  left: 27px;
  top: 19px;
  width: 28px;
  height: 13px;
  border-radius: 60% 70% 55% 65%;
  background: #23272c;
  transform: rotate(-5deg);
}

.bird-body::after {
  content: "";
  position: absolute;
  right: -8px;
  top: 2px;
  width: 12px;
  height: 8px;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
  background: #c49a47;
}

.bird-wing {
  position: absolute;
  left: 24px;
  top: 5px;
  width: 34px;
  height: 22px;
  border-radius: 65% 15% 65% 20%;
  background: #30353b;
  transform-origin: 70% 90%;
  animation: wing-flap .35s ease-in-out infinite alternate;
}

.bird-wing.second {
  left: 10px;
  top: 16px;
  transform: rotate(18deg);
  animation-direction: alternate-reverse;
}

@keyframes wing-flap {
  from { transform: rotate(-18deg) scaleY(.75); }
  to { transform: rotate(18deg) scaleY(1); }
}

.bird.hit {
  pointer-events: none;
  animation: bird-fall .65s ease-in forwards;
}

@keyframes bird-fall {
  to { transform: translateY(190px) rotate(95deg); opacity: 0; }
}

.debris {
  position: absolute;
  z-index: 7;
  width: 76px;
  height: 28px;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.debris::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 9px;
  width: 62px;
  height: 12px;
  border-radius: 999px;
  background: #9a663b;
  border: 2px solid #604126;
  transform: rotate(5deg);
}

.debris::after {
  content: "";
  position: absolute;
  left: 48px;
  top: 5px;
  width: 16px;
  height: 9px;
  border-radius: 999px;
  background: #805231;
  transform: rotate(-28deg);
}

.debris.collected {
  pointer-events: none;
  animation: collect-item .3s ease-out forwards;
}

@keyframes collect-item {
  to { transform: translateY(-20px) scale(.5); opacity: 0; }
}

.projectile {
  position: absolute;
  z-index: 20;
  width: 38px;
  height: 6px;
  border-radius: 999px;
  background: #8b5a35;
  transform-origin: center;
  pointer-events: none;
}

.field-status {
  position: absolute;
  z-index: 22;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 540px);
  text-align: center;
  pointer-events: none;
}

.field-status p {
  display: inline-block;
  margin: 0;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(7, 14, 20, .72);
  color: #f3f3f0;
  font-size: .78rem;
  backdrop-filter: blur(6px);
}

.start-overlay,
.result-overlay {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 10, 15, .72);
  backdrop-filter: blur(7px);
}

.start-card,
.result-card {
  width: min(100%, 520px);
  padding: 28px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  background: rgba(15, 20, 25, .94);
}

.start-kicker {
  margin: 0 0 9px;
  color: var(--accent);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .14em;
}

.start-card h2,
.result-card h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 7vw, 3.5rem);
  letter-spacing: -.05em;
}

.start-card > p:not(.start-kicker),
.result-card > p:not(.start-kicker) {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.rules {
  margin: 22px 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.rules div {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.rules div:last-child { border-right: 0; }

.rules dt {
  color: var(--muted);
  font-size: .65rem;
}

.rules dd {
  margin: 4px 0 0;
  font-weight: 850;
  font-size: .88rem;
}

.drift-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 17px;
  font: inherit;
  font-size: .82rem;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.drift-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
}

.drift-button.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 7px;
  background: transparent;
  color: var(--text);
}

.drift-button:disabled {
  cursor: not-allowed;
  opacity: .38;
}

.drift-controls {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.control-help {
  min-width: 0;
}

.control-help strong,
.control-help span {
  display: block;
}

.control-help strong {
  font-size: .86rem;
}

.control-help span {
  margin-top: 3px;
  color: var(--muted);
  font-size: .76rem;
}

.eat-button {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.drift-progress {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

#progress-label {
  color: var(--muted);
  font-size: .76rem;
}

.progress-fill {
  width: 0;
}

.shore {
  position: absolute;
  z-index: 14;
  right: -45%;
  bottom: 0;
  width: 42%;
  height: 100%;
  transition: right 2.6s ease-out;
}

.shore.arrive {
  right: 0;
}

.sand {
  position: absolute;
  inset: 50% 0 0 0;
  background: #d4bb7d;
  border-radius: 70% 0 0 0;
}

.palm {
  position: absolute;
  left: 48%;
  bottom: 44%;
  width: 90px;
  height: 120px;
}

.palm-trunk {
  position: absolute;
  left: 42px;
  bottom: 0;
  width: 12px;
  height: 92px;
  border-radius: 8px;
  background: #725136;
  transform: rotate(9deg);
}

.palm-leaf {
  position: absolute;
  left: 42px;
  top: 18px;
  width: 55px;
  height: 13px;
  border-radius: 100% 15% 100% 15%;
  background: #486f45;
  transform-origin: left center;
}

.leaf-1 { transform: rotate(-25deg); }
.leaf-2 { transform: rotate(24deg); }
.leaf-3 { transform: rotate(72deg); }

.result-stats {
  margin: 22px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-stats div {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.result-stats span,
.result-stats strong {
  display: block;
}

.result-stats span {
  color: var(--muted);
  font-size: .68rem;
}

.result-stats strong {
  margin-top: 4px;
  font-size: 1.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .wave,
  .raft,
  .bird-wing {
    animation: none !important;
  }

  .shore {
    transition: none;
  }
}

@media (max-width: 720px) {
  .drift-hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud-cell {
    border-bottom: 1px solid var(--line);
  }

  .hud-cell:nth-child(2) {
    border-right: 0;
  }

  .hud-cell:nth-child(3),
  .hud-cell:nth-child(4) {
    border-bottom: 0;
  }

  .drift-field {
    min-height: 500px;
  }

  .drift-controls {
    grid-template-columns: 1fr;
  }

  .eat-button {
    width: 100%;
  }

  .rules {
    grid-template-columns: 1fr;
  }

  .rules div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rules div:last-child {
    border-bottom: 0;
  }

  .drift-button.secondary {
    margin-left: 0;
    margin-top: 8px;
    width: 100%;
  }

  .result-card .primary {
    width: 100%;
  }

  .raft {
    transform: translateX(-50%) scale(.88);
  }

  @keyframes raft-bob {
    0%, 100% { transform: translateX(-50%) scale(.88) rotate(-1deg) translateY(0); }
    50% { transform: translateX(-50%) scale(.88) rotate(1deg) translateY(5px); }
  }
}

/* Fix: hidden overlays must actually be hidden. */
.start-overlay[hidden],
.result-overlay[hidden] {
  display: none !important;
}

/* Mobile start overlay fix v2 */
@media (max-width: 720px) {
  .start-overlay,
  .result-overlay {
    place-items: center;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
  }

  .start-card,
  .result-card {
    width: min(100%, 520px);
    max-height: calc(100% - 8px);
    overflow-y: auto;
    padding: 18px;
  }

  .start-card h2,
  .result-card h2 {
    margin-bottom: 8px;
  }

  .start-card > p:not(.start-kicker),
  .result-card > p:not(.start-kicker) {
    line-height: 1.55;
    font-size: .88rem;
  }

  .rules {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 14px 0 16px;
  }

  .rules div {
    padding: 9px 6px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    text-align: center;
  }

  .rules div:last-child {
    border-right: 0;
  }

  .rules dt {
    font-size: .58rem;
  }

  .rules dd {
    font-size: .76rem;
    line-height: 1.25;
  }

  .start-card .primary,
  .result-card .primary {
    width: 100%;
    min-height: 48px;
  }
}

@media (max-width: 390px) {
  .start-card,
  .result-card {
    padding: 14px;
  }

  .start-card h2,
  .result-card h2 {
    font-size: 1.8rem;
  }

  .rules {
    margin: 10px 0 12px;
  }

  .rules div {
    padding: 8px 4px;
  }
}

