:root {
  color-scheme: dark;
  --surface: rgba(2, 34, 52, 0.72);
  --surface-strong: rgba(1, 21, 34, 0.86);
  --text: #f2fffb;
  --muted: #b9e9e5;
  --accent: #ffd166;
  --coral: #ff7d6e;
  --teal: #1dd5c8;
  --deep: #043858;
  --card-w: clamp(58px, 9vw, 96px);
  --card-h: calc(var(--card-w) * 1.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: #042f4f;
  overflow: hidden;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  min-height: 100vh;
  padding: clamp(14px, 2vw, 24px);
  display: grid;
  grid-template-rows: auto auto 1fr 1.35fr auto;
  gap: clamp(10px, 1.6vh, 18px);
  isolation: isolate;
  background:
    radial-gradient(circle at 18% 20%, rgba(29, 213, 200, 0.34), transparent 26%),
    radial-gradient(circle at 78% 8%, rgba(255, 209, 102, 0.18), transparent 24%),
    linear-gradient(180deg, #0eb6b9 0%, #077591 38%, #043858 75%, #021b2e 100%);
}

.ocean-light {
  position: absolute;
  top: -15%;
  width: 26vw;
  height: 125vh;
  transform: rotate(15deg);
  background: linear-gradient(180deg, rgba(246, 255, 210, 0.26), transparent 72%);
  filter: blur(16px);
  opacity: 0.55;
  z-index: -1;
  animation: driftLight 11s ease-in-out infinite alternate;
}

.light-one { left: 12%; }
.light-two { right: 18%; animation-delay: -5s; }

.bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

.bubbles span {
  position: absolute;
  bottom: -70px;
  width: clamp(10px, 1.8vw, 24px);
  aspect-ratio: 1;
  border: 2px solid rgba(220, 255, 252, 0.58);
  border-radius: 50%;
  animation: bubbleUp 13s linear infinite;
}

.bubbles span:nth-child(1) { left: 8%; animation-delay: -2s; }
.bubbles span:nth-child(2) { left: 24%; animation-delay: -8s; width: 17px; }
.bubbles span:nth-child(3) { left: 48%; animation-delay: -4s; width: 22px; }
.bubbles span:nth-child(4) { left: 67%; animation-delay: -11s; width: 14px; }
.bubbles span:nth-child(5) { left: 82%; animation-delay: -6s; width: 26px; }
.bubbles span:nth-child(6) { left: 92%; animation-delay: -1s; width: 12px; }

.seaweed {
  position: absolute;
  bottom: -8px;
  display: flex;
  gap: 9px;
  z-index: 0;
  opacity: 0.62;
}

.seaweed-left { left: 20px; }
.seaweed-right { right: 28px; }

.seaweed span {
  width: 18px;
  height: clamp(90px, 17vh, 170px);
  border-radius: 100% 0;
  background: linear-gradient(180deg, #4ce08e, #096747);
  transform-origin: bottom;
  animation: sway 3.8s ease-in-out infinite alternate;
}

.seaweed span:nth-child(2) { height: clamp(120px, 22vh, 210px); animation-delay: -.8s; }
.seaweed span:nth-child(3) { animation-delay: -1.5s; }

.topbar,
.scoreboard,
.table-zone,
.hand-zone,
.opponent-zone {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 54px;
  height: 54px;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .28));
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: .9;
  letter-spacing: 0;
  text-shadow: 0 5px 18px rgba(0, 25, 40, .35);
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.icon-button,
.rank-button {
  border: 1px solid rgba(230, 255, 251, .34);
  color: var(--text);
  background: rgba(1, 36, 56, .65);
  box-shadow: 0 12px 28px rgba(0, 15, 28, .24);
  cursor: pointer;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 1.45rem;
}

.scoreboard {
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(88px, 130px) 140px minmax(88px, 130px);
  align-items: end;
  gap: clamp(8px, 2vw, 18px);
}

.score-box {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid rgba(221, 255, 250, .2);
  text-align: center;
}

.score-box span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-box strong {
  display: block;
  font-size: 2rem;
}

.treasure {
  position: relative;
  height: 82px;
}

.chest-lid,
.chest-body {
  position: absolute;
  left: 16px;
  right: 16px;
  border: 3px solid #643519;
  background: linear-gradient(90deg, #a5542f, #e3a247 48%, #8e421f);
}

.chest-lid {
  top: 12px;
  height: 34px;
  border-radius: 48px 48px 8px 8px;
}

.chest-body {
  bottom: 0;
  height: 46px;
  border-radius: 6px;
}

.pearls {
  position: absolute;
  left: 32px;
  right: 32px;
  bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.pearls span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #fff, #c7f7f4 64%, #80cbc4);
}

.opponent-zone,
.table-zone,
.hand-zone {
  display: grid;
  place-items: center;
}

.cpu-hand,
.player-hand {
  position: relative;
  width: min(92vw, 920px);
  height: calc(var(--card-h) + 76px);
  display: grid;
  place-items: center;
}

.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  transition: transform .28s ease, filter .2s ease;
  box-shadow: 0 16px 28px rgba(0, 16, 30, .34);
}

.card-face {
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 9px;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,.95), rgba(232,255,250,.82) 38%, rgba(143,231,217,.82) 39%, rgba(255,255,255,.9) 58%),
    linear-gradient(145deg, #fffdf1, #b8fff3);
  border: 2px solid rgba(255, 255, 255, .9);
  color: #14374c;
}

.card-face.red {
  color: #af3152;
}

.card-face strong {
  align-self: center;
  justify-self: center;
  font-size: clamp(1.7rem, 4vw, 3.1rem);
}

.corner,
.suit {
  font-weight: 900;
}

.suit {
  justify-self: end;
}

.card-back {
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .78);
  background:
    radial-gradient(circle, rgba(255,255,255,.72) 0 16%, transparent 17% 100%) 0 0 / 22px 22px,
    linear-gradient(145deg, #ffcf66, #ff7d6e 58%, #14bbb2);
}

.card-back span {
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 7px;
}

.rank-stack {
  position: absolute;
  width: calc(var(--card-w) + 30px);
  height: calc(var(--card-h) + 34px);
  border: 0;
  background: transparent;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform .28s ease, filter .2s ease;
}

.rank-stack .card {
  left: 0;
  bottom: 0;
}

.rank-stack:hover .card,
.rank-stack:focus-visible .card {
  filter: brightness(1.08);
}

.rank-stack:focus-visible {
  outline: 3px solid rgba(255, 209, 102, .9);
  outline-offset: 8px;
  border-radius: 10px;
}

.stack-count {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  z-index: 10;
  color: #07334b;
  background: var(--accent);
  border: 2px solid rgba(255, 255, 255, .88);
  font-weight: 950;
  box-shadow: 0 8px 16px rgba(0, 16, 30, .32);
}

.motion-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
}

.moving-card {
  position: fixed;
  width: var(--card-w);
  height: var(--card-h);
  filter: drop-shadow(0 22px 28px rgba(0, 18, 32, .34));
  will-change: transform, opacity;
}

.moving-card .card {
  position: relative;
  transform: none !important;
}

.moving-pearl {
  position: fixed;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #fff, #d8fffb 56%, #73d6ce 100%);
  box-shadow: 0 0 22px rgba(255, 255, 255, .84), 0 16px 24px rgba(0, 18, 32, .24);
  will-change: transform, opacity;
}

.rank-picker {
  min-height: 46px;
  margin-bottom: -8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.rank-button {
  min-width: 42px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  font-weight: 900;
}

.rank-button:hover:not(:disabled),
.icon-button:hover {
  background: rgba(29, 213, 200, .7);
}

.rank-button:disabled {
  opacity: .48;
  cursor: not-allowed;
}

.table-zone {
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(100%, 980px);
  justify-self: center;
}

.pond {
  position: relative;
  width: clamp(116px, 16vw, 168px);
  height: clamp(92px, 13vw, 124px);
  border: 0;
  background: transparent;
  cursor: default;
}

.clam-top,
.clam-bottom {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 54%;
  border: 3px solid rgba(255, 255, 255, .62);
  background: linear-gradient(145deg, #f9e4ff, #8ed8ff 52%, #3b92bd);
}

.clam-top {
  top: 8px;
  border-radius: 90px 90px 12px 12px;
}

.clam-bottom {
  bottom: 8px;
  border-radius: 12px 12px 90px 90px;
}

.pond strong {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #092d43;
  font-size: 2rem;
  z-index: 2;
}

.pond.ripple::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 3px solid rgba(217, 255, 251, .72);
  border-radius: 50%;
  animation: ripple .72s ease-out;
}

.mascot {
  justify-self: end;
  display: grid;
  justify-items: center;
  gap: 8px;
  opacity: .96;
}

.speech {
  padding: 8px 13px;
  border-radius: 999px;
  color: #07334b;
  background: #e9fffb;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(0, 20, 36, .24);
}

.fish-body {
  position: relative;
  width: 76px;
  height: 42px;
  border-radius: 70% 45% 45% 70%;
  background: linear-gradient(90deg, #ffd166, #ff7d6e);
}

.fish-body::before {
  content: "";
  position: absolute;
  right: -23px;
  top: 7px;
  border-left: 28px solid #ff7d6e;
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
}

.fish-body span {
  position: absolute;
  left: 18px;
  top: 12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10344b;
}

.mascot.pop {
  animation: pop .56s cubic-bezier(.2, 1.5, .4, 1);
}

.books {
  justify-self: start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 280px;
}

.book {
  padding: 6px 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 900;
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .22);
}

.book.player { color: #fff1a8; }
.book.cpu { color: #c7f7f4; }

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 5;
}

.toast {
  padding: 10px 14px;
  border-radius: 999px;
  color: #07334b;
  background: #e9fffb;
  font-weight: 900;
  animation: toastFloat 2.6s ease forwards;
}

.wave {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  transform: translateX(-120%);
  background: linear-gradient(90deg, transparent, rgba(218, 255, 251, .3), transparent);
}

.wave.sweep {
  animation: waveSweep .8s ease;
}

@keyframes driftLight {
  to { transform: translateX(36px) rotate(19deg); }
}

@keyframes bubbleUp {
  from { transform: translateY(0) translateX(0); opacity: 0; }
  15% { opacity: .85; }
  to { transform: translateY(-112vh) translateX(32px); opacity: 0; }
}

@keyframes sway {
  to { transform: rotate(7deg); }
}

@keyframes ripple {
  to { transform: scale(2.1); opacity: 0; }
}

@keyframes pop {
  0% { transform: translateY(24px) scale(.8); }
  72% { transform: translateY(-7px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes toastFloat {
  0% { transform: translateY(20px); opacity: 0; }
  15%, 78% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-28px); opacity: 0; }
}

@keyframes waveSweep {
  from { transform: translateX(-120%); }
  to { transform: translateX(120%); }
}

.sparkle span {
  animation: pop .5s ease;
}

@media (max-width: 760px) {
  body {
    overflow-y: auto;
  }

  .game-shell {
    min-height: 100svh;
    grid-template-rows: auto auto minmax(110px, .7fr) minmax(150px, .9fr) auto;
    padding-bottom: 8px;
  }

  .brand-icon {
    width: 44px;
    height: 44px;
  }

  .brand p {
    font-size: .9rem;
  }

  .scoreboard {
    grid-template-columns: 86px 96px 86px;
  }

  .treasure {
    transform: scale(.78);
  }

  .table-zone {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .mascot,
  .books {
    justify-self: center;
  }

  .cpu-hand,
  .player-hand {
    width: 100%;
    height: calc(var(--card-h) + 54px);
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    justify-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
