:root {
  color-scheme: light;
  --ink: #152426;
  --muted: #6b7673;
  --panel: rgba(255, 255, 255, 0.82);
  --line: #122a2d;
  --sea: #5bb8c5;
  --land: #73c77f;
  --land-deep: #2d7d68;
  --accent: #ef8e63;
  --accent-deep: #bf5d43;
  --cream: #f6f2e9;
}

.online-panel {
  position: absolute;
  inset: 18px;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 8px;
  background: rgba(207, 237, 235, 0.62);
  backdrop-filter: blur(10px);
}

.online-panel.is-hidden {
  display: none;
}

.online-card {
  width: min(700px, 100%);
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid rgba(18, 42, 45, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 24px 70px rgba(20, 40, 42, 0.2);
}

.online-section {
  display: grid;
  gap: 14px;
}

.online-section.is-hidden {
  display: none;
}

.online-heading {
  display: grid;
  gap: 2px;
}

.online-heading span,
.password-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.online-heading h2 {
  margin: 0;
  font-size: 1.36rem;
  line-height: 1.15;
}

.room-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.room-button,
.online-actions button {
  min-height: 44px;
  border: 1px solid rgba(18, 42, 45, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(244, 251, 248, 0.92);
  font-weight: 900;
  cursor: pointer;
}

.room-button {
  padding: 8px 7px;
  font-size: 0.78rem;
  line-height: 1.2;
}

.room-button.is-selected {
  border-color: rgba(45, 125, 104, 0.42);
  background: rgba(224, 250, 236, 0.95);
  color: #155f4b;
}

.room-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.password-field {
  display: grid;
  gap: 6px;
}

.password-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(18, 42, 45, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  font: inherit;
  font-weight: 700;
}

.online-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#joinRoomButton {
  flex: 1 1 190px;
  color: #ffffff;
  border-color: rgba(31, 111, 86, 0.42);
  background: #207a63;
}

#readyButton {
  flex: 1 1 170px;
  color: #ffffff;
  border-color: rgba(34, 112, 128, 0.42);
  background: linear-gradient(135deg, #217b82, #2ba97f);
}

#readyButton.is-ready {
  border-color: rgba(191, 93, 67, 0.34);
  background: linear-gradient(135deg, #d97858, #bf5d43);
}

#readyButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#leaveRoomButton {
  flex: 0 0 auto;
  padding: 0 14px;
  background: rgba(255, 247, 239, 0.96);
}

.lobby-panel {
  position: relative;
}

.lobby-panel::before {
  content: "";
  position: absolute;
  inset: 42px 10px auto;
  height: 72px;
  pointer-events: none;
  opacity: 0.44;
  background:
    radial-gradient(ellipse at 20% 38%, rgba(255, 255, 255, 0.72), transparent 34%),
    radial-gradient(ellipse at 78% 54%, rgba(101, 192, 203, 0.35), transparent 40%);
}

.lobby-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  min-height: 182px;
  overflow: hidden;
  padding: 16px;
  border: 1px solid rgba(30, 97, 104, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(237, 253, 251, 0.94), rgba(166, 224, 229, 0.58)),
    repeating-linear-gradient(166deg, rgba(255, 255, 255, 0.16) 0 2px, transparent 2px 42px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.lobby-stage::before,
.lobby-stage::after {
  content: "";
  position: absolute;
  left: -8%;
  right: -8%;
  height: 44px;
  border-top: 2px solid rgba(255, 255, 255, 0.46);
  border-radius: 50%;
  opacity: 0.72;
}

.lobby-stage::before {
  bottom: 30px;
  transform: rotate(-1deg);
}

.lobby-stage::after {
  bottom: 54px;
  opacity: 0.36;
  transform: rotate(1.2deg);
}

.lobby-player-slot {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  padding: 10px;
  color: #12363a;
  text-align: center;
}

.lobby-player-slot img {
  width: clamp(78px, 14vw, 118px);
  height: clamp(78px, 14vw, 118px);
  object-fit: contain;
  filter: drop-shadow(0 14px 16px rgba(27, 78, 88, 0.22));
}

.lobby-player-slot strong {
  font-size: 1rem;
}

.lobby-player-slot span {
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #1f6f56;
  background: rgba(230, 255, 241, 0.88);
  font-size: 0.78rem;
  font-weight: 900;
}

.lobby-vs {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(28, 76, 82, 0.16);
  border-radius: 50%;
  color: #ffffff;
  background: linear-gradient(135deg, #ef8e63, #217b82);
  font-weight: 1000;
  box-shadow: 0 12px 28px rgba(29, 86, 93, 0.24);
}

.lobby-status {
  margin: 0;
  color: #24585d;
  font-size: 0.92rem;
  font-weight: 900;
}

.chat-log {
  display: grid;
  align-content: start;
  gap: 7px;
  min-height: 124px;
  max-height: 160px;
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(18, 42, 45, 0.12);
  border-radius: 8px;
  background: rgba(248, 253, 251, 0.88);
}

.chat-message {
  display: flex;
  gap: 7px;
  align-items: baseline;
  color: #163438;
  font-size: 0.86rem;
  font-weight: 760;
  line-height: 1.35;
}

.chat-message[data-role="human"] strong {
  color: #0b766d;
}

.chat-message[data-role="enemy"] strong {
  color: #9f3f67;
}

.chat-message[data-role="system"] {
  justify-content: center;
  color: #5c7777;
  font-size: 0.78rem;
}

.chat-message strong {
  flex: 0 0 auto;
}

.chat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-row input {
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(18, 42, 45, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  font: inherit;
  font-weight: 760;
}

.chat-row button {
  min-width: 72px;
  border: 1px solid rgba(18, 42, 45, 0.14);
  border-radius: 8px;
  color: #ffffff;
  background: #296d77;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.online-message {
  min-height: 1.35em;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.online-message.good {
  color: #1f6f56;
}

.online-message.bad {
  color: #762f24;
}

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

  .online-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .lobby-stage {
    grid-template-columns: 1fr;
  }

  .lobby-vs {
    width: 46px;
    height: 46px;
    justify-self: center;
  }

  .chat-row {
    grid-template-columns: 1fr;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(61, 154, 166, 0.16), transparent 38%),
    linear-gradient(250deg, rgba(236, 166, 124, 0.13), transparent 48%),
    linear-gradient(180deg, #eff8f5 0%, #d7e9ea 58%, #ccdee2 100%);
}

button {
  font: inherit;
}

.game-shell {
  width: calc(100vw - 28px);
  max-width: 1120px;
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(18, 42, 45, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 18px 48px rgba(23, 44, 46, 0.1);
  backdrop-filter: blur(16px);
}

.title-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  width: 18px;
  height: 18px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.6rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  min-width: 76px;
  display: grid;
  gap: 1px;
  padding: 7px 10px;
  border: 1px solid rgba(18, 42, 45, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.stat span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.stat strong {
  font-size: 1.02rem;
  line-height: 1.1;
}

.board-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

#gameCanvas {
  width: min(100%, calc((100vh - 120px) * 1.6), 1120px);
  height: auto;
  max-height: calc(100vh - 120px);
  aspect-ratio: 16 / 10;
  display: block;
  border-radius: 8px;
  background: #bfe7ea;
  box-shadow: 0 28px 70px rgba(20, 40, 42, 0.16);
  cursor: crosshair;
  touch-action: none;
}

.status-chip {
  position: absolute;
  left: 16px;
  top: 16px;
  max-width: min(420px, calc(100% - 32px));
  padding: 9px 12px;
  color: #122a2d;
  border: 1px solid rgba(18, 42, 45, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 36px rgba(23, 44, 46, 0.14);
  font-size: 0.9rem;
  font-weight: 800;
  backdrop-filter: blur(12px);
  transition: transform 180ms ease, opacity 180ms ease;
}

.status-chip.bump {
  transform: translateY(-2px);
}

.status-chip.bad {
  color: #762f24;
  border-color: rgba(191, 93, 67, 0.32);
  background: rgba(255, 239, 231, 0.9);
}

.status-chip.good {
  color: #1f6f56;
  border-color: rgba(45, 125, 104, 0.24);
  background: rgba(232, 250, 238, 0.9);
}

.win-panel {
  position: absolute;
  inset: 18px;
  width: auto;
  translate: 0 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 12px;
  padding: 24px;
  border: 1px solid rgba(18, 42, 45, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(235, 252, 250, 0.88), rgba(255, 250, 237, 0.82)),
    radial-gradient(circle at 50% 88%, rgba(91, 184, 197, 0.32), transparent 52%);
  box-shadow: 0 24px 80px rgba(20, 40, 42, 0.28);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.win-panel.is-hidden {
  display: none;
}

.ending-stage {
  position: relative;
  width: min(560px, 92%);
  height: min(310px, 44vh);
}

.ending-stage::before,
.ending-stage::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  height: 22px;
  border-top: 3px solid rgba(255, 255, 255, 0.56);
  border-radius: 50%;
}

.ending-stage::before {
  top: 24%;
  transform: rotate(-2deg);
}

.ending-stage::after {
  bottom: 18%;
  transform: rotate(2deg);
}

.ending-character {
  position: absolute;
  left: 50%;
  bottom: 10px;
  width: min(250px, 44vw);
  height: min(250px, 42vh);
  object-fit: contain;
  filter: drop-shadow(0 26px 22px rgba(20, 40, 42, 0.24));
  transform-origin: 50% 72%;
  display: none;
}

.ending-bubble {
  position: absolute;
  left: 50%;
  top: 0;
  min-width: min(310px, 82vw);
  max-width: min(420px, 88vw);
  translate: -50% 0;
  padding: 14px 16px;
  color: #213c40;
  border: 1px solid rgba(18, 42, 45, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 36px rgba(23, 44, 46, 0.14);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
}

.ending-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 18px;
  height: 18px;
  border-right: 1px solid rgba(18, 42, 45, 0.14);
  border-bottom: 1px solid rgba(18, 42, 45, 0.14);
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.win-panel[data-result="win"] .ending-dolphin {
  display: block;
  animation: dolphinDance 820ms ease-in-out infinite;
}

.win-panel[data-result="lose"] .ending-octopus {
  display: block;
  animation: octopusDance 720ms ease-in-out infinite;
}

.win-panel[data-result="lose"] .ending-bubble {
  background: rgba(255, 237, 242, 0.94);
}

.win-panel h2,
.win-panel p {
  margin: 0;
}

.win-panel h2 {
  font-size: 2rem;
  letter-spacing: 0;
}

.win-panel p {
  color: var(--muted);
  font-weight: 800;
}

@keyframes dolphinDance {
  0% {
    translate: -50% 0;
    rotate: -8deg;
  }

  50% {
    translate: -50% -18px;
    rotate: 9deg;
  }

  100% {
    translate: -50% 0;
    rotate: -8deg;
  }
}

@keyframes octopusDance {
  0% {
    translate: -50% 0;
    rotate: 7deg;
  }

  34% {
    translate: -58% -13px;
    rotate: -10deg;
  }

  68% {
    translate: -42% -10px;
    rotate: 12deg;
  }

  100% {
    translate: -50% 0;
    rotate: 7deg;
  }
}

.icon-action:hover {
  border-color: rgba(239, 142, 99, 0.7);
  outline: none;
}

.icon-action {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--ink);
  border: 1px solid rgba(18, 42, 45, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 10px 24px rgba(23, 44, 46, 0.12);
  cursor: pointer;
  font-size: 1.36rem;
  font-weight: 900;
}

.rules-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 31, 33, 0.38);
  backdrop-filter: blur(10px);
}

.rules-panel.is-hidden {
  display: none;
}

.rules-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(18, 42, 45, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 28px 90px rgba(20, 40, 42, 0.32);
}

.rules-card[data-stage="duel-dolphin"],
.rules-card[data-stage="duel-thought"],
.rules-card[data-stage="duel-octopus"],
.rules-card[data-stage="duel-dolphin-thought"] {
  width: min(760px, 100%);
}

.intro-stage.is-hidden {
  display: none;
}

.rules-card[data-stage="rules"] {
  cursor: pointer;
}

.rules-card h2 {
  margin: 0 0 12px;
  font-size: 1.45rem;
  letter-spacing: 0;
}

.rules-card p {
  margin: 10px 0;
  color: #3d4c49;
  line-height: 1.55;
  font-weight: 700;
}

.trash-intro {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.trash-options {
  display: grid;
  gap: 8px;
}

.trash-option {
  position: relative;
  width: 100%;
  min-height: 48px;
  padding: 11px 15px;
  color: #213c40;
  text-align: left;
  border: 1px solid rgba(18, 42, 45, 0.13);
  border-radius: 18px;
  background: rgba(245, 251, 249, 0.86);
  cursor: pointer;
  font-weight: 900;
  line-height: 1.35;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.trash-option::after {
  content: "";
  position: absolute;
  left: 22px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-right: 1px solid rgba(18, 42, 45, 0.13);
  border-bottom: 1px solid rgba(18, 42, 45, 0.13);
  background: inherit;
  transform: rotate(45deg);
}

.trash-option:hover,
.trash-option.is-selected {
  border-color: rgba(191, 93, 67, 0.58);
  background: rgba(255, 239, 231, 0.94);
  transform: translateY(-1px);
}

.primary-action {
  width: 100%;
  height: 46px;
  margin-top: 14px;
  color: #fff;
  border: 0;
  border-radius: 8px;
  background: var(--line);
  box-shadow: 0 12px 28px rgba(18, 42, 45, 0.22);
  cursor: pointer;
  font-weight: 900;
}

.primary-action:hover {
  background: #213c40;
}

.primary-action:disabled {
  color: rgba(255, 255, 255, 0.72);
  background: rgba(18, 42, 45, 0.42);
  box-shadow: none;
  cursor: not-allowed;
}

.duel-stage {
  cursor: pointer;
  user-select: none;
}

.duel-portraits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 18px;
  min-height: 260px;
  padding: 6px 0 14px;
}

.duel-portrait {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
  opacity: 0.6;
  transform: scale(0.92);
  transition: opacity 220ms ease, transform 220ms ease, filter 220ms ease;
}

.duel-portrait img {
  width: min(240px, 100%);
  height: 230px;
  object-fit: contain;
  filter: drop-shadow(0 20px 22px rgba(20, 40, 42, 0.22));
}

.duel-portrait figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.rules-card[data-stage="duel-dolphin"] .dolphin-portrait,
.rules-card[data-stage="duel-thought"] .octopus-portrait,
.rules-card[data-stage="duel-octopus"] .octopus-portrait,
.rules-card[data-stage="duel-dolphin-thought"] .dolphin-portrait {
  opacity: 1;
  transform: scale(1);
  filter: saturate(1.08);
}

.rules-card[data-stage="duel-dolphin"] .octopus-portrait,
.rules-card[data-stage="duel-thought"] .dolphin-portrait,
.rules-card[data-stage="duel-octopus"] .dolphin-portrait,
.rules-card[data-stage="duel-dolphin-thought"] .octopus-portrait {
  opacity: 0.42;
  transform: scale(0.88);
}

.duel-dialogue {
  position: relative;
  display: grid;
  gap: 6px;
  min-height: 88px;
  padding: 15px 16px;
  border: 1px solid rgba(18, 42, 45, 0.12);
  border-radius: 18px;
  background: rgba(225, 246, 247, 0.82);
}

.duel-dialogue::after {
  content: "";
  position: absolute;
  left: 26%;
  top: -10px;
  width: 22px;
  height: 22px;
  border-left: 1px solid rgba(18, 42, 45, 0.12);
  border-top: 1px solid rgba(18, 42, 45, 0.12);
  background: inherit;
  transform: rotate(45deg);
}

.rules-card[data-stage="duel-thought"] .duel-dialogue,
.rules-card[data-stage="duel-dolphin-thought"] .duel-dialogue {
  border-style: dashed;
  background: rgba(255, 246, 221, 0.92);
}

.rules-card[data-stage="duel-thought"] .duel-dialogue::after,
.rules-card[data-stage="duel-octopus"] .duel-dialogue::after {
  left: auto;
  right: 26%;
}

.duel-dialogue span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.duel-dialogue strong {
  color: #213c40;
  font-size: 1.32rem;
  line-height: 1.32;
  font-weight: 900;
}

@media (max-width: 720px) {
  .game-shell {
    width: calc(100vw - 18px);
    gap: 10px;
    padding: 9px 0;
  }

  .topbar {
    align-items: stretch;
    padding: 10px;
  }

  .topbar {
    flex-direction: column;
  }

  .stats {
    justify-content: stretch;
  }

  .stat {
    flex: 1;
  }

  #gameCanvas {
    width: min(100%, calc((100vh - 185px) * 1.6));
    max-height: calc(100vh - 185px);
  }

  .icon-action {
    height: 40px;
    width: 40px;
  }

  .rules-card {
    padding: 22px;
  }

  .duel-portraits {
    min-height: 210px;
    gap: 10px;
  }

  .duel-portrait img {
    height: 170px;
  }

  .duel-dialogue strong {
    font-size: 1.05rem;
  }

  .win-panel {
    inset: 10px;
    padding: 18px;
  }

  .ending-stage {
    height: min(250px, 38vh);
  }

  .ending-character {
    width: min(210px, 58vw);
  }
}
