:root {
  --sky-top: #fdf7ff;
  --sky-bottom: #8dd3ff;
  --sea: #0391c5;
  --foam: #fefae0;
  --panel: #ffffff;
  --card: #fff4d9;
  --card-border: #ffc262;
  --text-dark: #1f2a44;
  --text-soft: #5d6a7a;
  --accent: #ff6f59;
  --accent-dark: #f94144;
  --shadow: rgba(30, 41, 59, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--sky-top) 10%, var(--sky-bottom) 55%, var(--sea) 100%);
  color: var(--text-dark);
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: -120px;
  right: -120px;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, #ffec99 40%, rgba(255, 236, 153, 0) 70%);
  border-radius: 50%;
  z-index: 0;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  cursor: pointer;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  position: relative;
  z-index: 1;
}

.sky-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  filter: blur(0.5px);
  animation: floatClouds 28s linear infinite;
}

.cloud-one {
  top: 20px;
  left: 5%;
  width: 160px;
  height: 60px;
}

.cloud-two {
  top: 80px;
  right: 10%;
  width: 120px;
  height: 42px;
  animation-duration: 32s;
}

.cloud-three {
  top: 150px;
  left: 40%;
  width: 110px;
  height: 35px;
  animation-duration: 36s;
}

.seagull {
  position: absolute;
  width: 40px;
  height: 18px;
  border-top: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: glide 12s ease-in-out infinite;
}

.seagull-one {
  top: 90px;
  left: 20%;
}

.seagull-two {
  top: 50px;
  right: 25%;
  animation-delay: 3s;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.8rem;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 28px;
  padding: 1.2rem 1.5rem;
  box-shadow: 0 20px 45px var(--shadow);
}

.app-header h1 {
  margin: 0;
  font-size: 2.4rem;
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--text-soft);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: linear-gradient(120deg, #fff, #ffe2c9);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  box-shadow: 0 10px 25px var(--shadow);
}

.mode-toggle input {
  appearance: none;
  width: 44px;
  height: 24px;
  background: #d8e3f5;
  border-radius: 999px;
  position: relative;
  transition: background 0.3s ease;
}

.mode-toggle input::after {
  content: "";
  width: 20px;
  height: 20px;
  background: #fff;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s ease;
}

.mode-toggle input:checked {
  background: var(--accent);
}

.mode-toggle input:checked::after {
  transform: translateX(20px);
}

.mode-toggle .label {
  font-weight: 700;
}

.game-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.8rem;
}

.characters-panel,
.lifeboat-panel,
.leaderboard-panel {
  background: rgba(255, 255, 255, 0.92);
  padding: 1.5rem;
  border-radius: 26px;
  box-shadow: 0 18px 45px var(--shadow);
}

.characters-panel h2,
.lifeboat-panel h2,
.leaderboard-panel h2 {
  margin-top: 0;
}

.character-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border: 3px solid var(--card-border);
  border-radius: 26px;
  background: radial-gradient(circle at top, #fffaf1, var(--card));
  color: inherit;
  box-shadow: 0 10px 18px rgba(255, 165, 0, 0.2);
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.character-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 26px;
  border: 2px dashed transparent;
  pointer-events: none;
}

.character-card:hover {
  transform: translateY(-4px);
}

.character-card.selected {
  box-shadow: 0 20px 35px rgba(255, 154, 0, 0.35);
  transform: translateY(-6px);
}

.character-card.selected::after {
  border-color: rgba(255, 111, 89, 0.5);
}

.portrait {
  width: 100%;
  border-radius: 22px;
  background: #fff;
  padding: 0.6rem;
  position: relative;
}

.portrait img {
  width: 100%;
  border-radius: 16px;
  aspect-ratio: 1;
  object-fit: cover;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.name-plate {
  position: absolute;
  left: 50%;
  bottom: -12px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.9rem;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 14px rgba(249, 65, 68, 0.35);
}

.role-tag {
  font-size: 0.85rem;
  color: var(--text-soft);
  background: rgba(3, 145, 197, 0.12);
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(3, 145, 197, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.round-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.round-stats > div {
  background: rgba(4, 130, 184, 0.1);
  border-radius: 20px;
  padding: 0.8rem 1rem;
  border: 2px solid rgba(3, 145, 197, 0.15);
}

.round-stats strong {
  display: block;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--text-soft);
  letter-spacing: 0.1em;
}

.round-stats span {
  font-size: 1.6rem;
  font-weight: 800;
}

.hint-text {
  display: block;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.star-meter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.2rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.8);
  border: 2px dashed rgba(255, 159, 89, 0.5);
  box-shadow: inset 0 0 12px rgba(255, 196, 98, 0.2);
}

.star-label strong {
  display: block;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.15em;
}

.star-label {
  display: flex;
  flex-direction: column;
}

.star-caption {
  font-size: 0.78rem;
  color: var(--text-soft);
}

.stars {
  display: flex;
  gap: 0.3rem;
  font-size: 1.4rem;
}

.star {
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.star.filled {
  color: #ffd057;
  text-shadow: 0 4px 10px rgba(255, 173, 0, 0.6);
}

.lifeboat-area {
  min-height: 360px;
  border-radius: 30px;
  position: relative;
  overflow: hidden;
  padding: 1.5rem;
  border: 3px solid rgba(4, 40, 70, 0.12);
  background: linear-gradient(180deg, #5ec4ff, #027ab1 65%, #01486f 100%);
}

.lifeboat-graphics {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.boat-hull {
  position: absolute;
  bottom: 50px;
  left: 50%;
  width: 320px;
  height: 90px;
  background: linear-gradient(90deg, #d85b18, #af3e0c);
  border-radius: 0 0 140px 140px;
  transform: translateX(-50%);
  box-shadow: inset 0 -8px rgba(0, 0, 0, 0.25);
}

.boat-cabin {
  position: absolute;
  bottom: 120px;
  left: 50%;
  width: 260px;
  height: 80px;
  background: #fff8ee;
  border-radius: 40px 40px 10px 10px;
  transform: translateX(-50%);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.15);
}

.mast {
  position: absolute;
  bottom: 120px;
  left: 50%;
  width: 10px;
  height: 160px;
  background: #fdd365;
  transform: translateX(-50%);
}

.flag {
  position: absolute;
  bottom: 235px;
  left: 50%;
  width: 80px;
  height: 40px;
  background: var(--accent);
  clip-path: polygon(0 0, 80% 0, 100% 50%, 80% 100%, 0 100%);
  transform: translateX(-5px);
}

.wave {
  position: absolute;
  bottom: 0;
  width: 160%;
  height: 80px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 45% 55% 0 0;
  animation: waveMove 8s linear infinite;
}

.wave-one {
  left: -30%;
  animation-duration: 10s;
}

.wave-two {
  bottom: 20px;
  left: -20%;
  opacity: 0.35;
  animation-duration: 12s;
}

.wave-three {
  bottom: 35px;
  left: -40%;
  opacity: 0.5;
  animation-duration: 14s;
}

.boat-hint {
  margin: 0;
  text-align: center;
  color: #f0fbff;
  font-weight: 600;
  font-size: 1rem;
  position: relative;
  z-index: 1;
}

.boat-avatar {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  margin: 0.3rem;
  border: 2px solid rgba(0, 78, 119, 0.15);
  box-shadow: 0 10px 18px rgba(1, 20, 43, 0.4);
  opacity: 0;
  transform: translateY(18px);
  position: relative;
  z-index: 1;
}

.boat-avatar img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid #fff1d6;
}

.boat-avatar span {
  font-weight: 700;
  letter-spacing: 0.05em;
}

.boat-avatar.active {
  animation: jump 0.9s ease;
  opacity: 1;
  transform: translateY(0);
}

.droplet {
  position: absolute;
  top: 10px;
  width: 12px;
  height: 18px;
  border-radius: 50% 50% 40% 40%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
  animation: droplet 1.2s ease forwards;
  pointer-events: none;
}

.controls {
  margin-top: 1.2rem;
  display: flex;
  gap: 1rem;
}

.primary,
.ghost {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 0.95rem 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fffdf9;
}

.ghost {
  background: #fff;
  border: 2px dashed rgba(3, 145, 197, 0.6);
  color: var(--text-dark);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 0.5rem 0.35rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.leaderboard-table th {
  color: var(--text-soft);
  font-size: 0.95rem;
}

.leaderboard-table tbody tr:nth-child(odd) {
  background: rgba(255, 241, 214, 0.4);
}

.leaderboard-notice {
  margin-bottom: 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 92, 92, 0.4);
  background: rgba(255, 92, 92, 0.12);
  color: #b62929;
  font-size: 0.9rem;
  line-height: 1.35;
}

.final-form {
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  padding-top: 1rem;
}

.form-row {
  display: flex;
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.form-row input {
  flex: 1;
  border-radius: 12px;
  border: 2px solid rgba(3, 145, 197, 0.3);
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
}

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 23, 41, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.result-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-box {
  background: #fff8ef;
  padding: 1.8rem 2.4rem;
  border-radius: 26px;
  min-width: 260px;
  text-align: center;
  border: 3px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 25px 45px rgba(0, 16, 38, 0.35);
}

.overlay-box.win {
  border-color: #7bf1a8;
  box-shadow: 0 0 35px rgba(123, 241, 168, 0.4);
}

.overlay-box.lose {
  border-color: #ff8fab;
  box-shadow: 0 0 35px rgba(255, 143, 171, 0.4);
}

.hidden {
  display: none !important;
}

@keyframes jump {
  0% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-18px);
  }
  60% {
    transform: translateY(6px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes droplet {
  0% {
    opacity: 0;
    transform: translateY(-12px) scale(0.4);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(95px) scale(0.85);
  }
}

@keyframes floatClouds {
  from {
    transform: translateX(-30px);
  }
  to {
    transform: translateX(30px);
  }
}

@keyframes glide {
  0% {
    transform: translateX(0) translateY(0);
  }
  50% {
    transform: translateX(30px) translateY(10px);
  }
  100% {
    transform: translateX(-10px) translateY(0);
  }
}

@keyframes waveMove {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-30%);
  }
}

@media (max-width: 720px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .character-list {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .controls,
  .form-row {
    flex-direction: column;
  }
}
