:root {
  --ink: #26355d;
  --muted: #7180a4;
  --primary: #5b7cfa;
  --primary-dark: #3f5ed0;
  --panel: rgba(255, 255, 255, 0.9);
  --shadow: 0 16px 40px rgba(53, 76, 141, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.9) 0 4%, transparent 5%),
    linear-gradient(160deg, #dff8ff 0%, #eef3ff 48%, #fff3de 100%);
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid rgba(255, 187, 54, 0.75);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
}

.screen {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.hidden {
  display: none !important;
}

.home-screen {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.lobby-link {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  z-index: 2;
  min-height: 44px;
  padding: 11px 16px;
  border: 2px solid rgba(86, 108, 172, 0.13);
  border-radius: 999px;
  color: #5369bb;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 7px 16px rgba(67, 84, 145, 0.13);
  font-weight: 800;
  text-decoration: none;
}

.lobby-link:focus-visible {
  outline: 4px solid rgba(255, 187, 54, 0.75);
  outline-offset: 3px;
}

.home-screen h1 {
  z-index: 1;
  margin: 12px 0 4px;
  color: #425dcc;
  font-size: clamp(38px, 7vw, 72px);
  letter-spacing: 0.08em;
  text-shadow: 0 5px 0 #fff, 0 9px 20px rgba(65, 87, 170, 0.2);
}

.tagline {
  z-index: 1;
  margin: 0 0 22px;
  color: var(--muted);
  font-size: clamp(16px, 2.4vw, 22px);
}

.hero-art {
  display: flex;
  height: 125px;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
}

.hero-bottle {
  position: relative;
  display: block;
  width: 60px;
  height: 96px;
  border: 6px solid rgba(62, 86, 145, 0.68);
  border-radius: 16px 16px 23px 23px;
  background: linear-gradient(to top, var(--liquid) 0 54%, rgba(255, 255, 255, 0.55) 55%);
  box-shadow: inset 8px 0 rgba(255, 255, 255, 0.32), 0 10px 18px rgba(48, 67, 125, 0.16);
  transform: rotate(var(--tilt));
  transform-origin: 50% 85%;
}

.hero-bottle::before {
  position: absolute;
  top: -20px;
  left: 8px;
  box-sizing: border-box;
  width: 32px;
  height: 16px;
  border: 6px solid rgba(62, 86, 145, 0.68);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  content: "";
  z-index: 2;
}

.hero-bottle::after {
  position: absolute;
  top: -3px;
  left: 14px;
  z-index: 1;
  width: 20px;
  height: 9px;
  background: rgba(255, 255, 255, 0.78);
  content: "";
}

.bottle-red { --liquid: #ff607b; --tilt: -8deg; }
.bottle-yellow { --liquid: #ffd650; --tilt: 0deg; height: 112px; }
.bottle-blue { --liquid: #48a9ff; --tilt: 8deg; }

.difficulty-card {
  z-index: 1;
  width: min(680px, 100%);
  padding: 18px 22px 22px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.difficulty-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.difficulty-button {
  display: flex;
  min-height: 112px;
  padding: 12px 8px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  border: 3px solid transparent;
  border-radius: 20px;
  color: var(--ink);
  background: #f4f6ff;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.difficulty-button:hover {
  transform: translateY(-3px);
}

.difficulty-button.selected {
  border-color: #6d86f3;
  background: #e8edff;
  box-shadow: 0 8px 18px rgba(78, 103, 204, 0.16);
}

.difficulty-button strong {
  margin-top: 4px;
  font-size: 19px;
}

.difficulty-button small {
  margin-top: 2px;
  color: var(--muted);
}

.difficulty-icon {
  font-size: 30px;
}

.home-actions {
  z-index: 1;
  display: flex;
  margin-top: 20px;
  align-items: center;
  gap: 12px;
}

.primary-button {
  min-width: 210px;
  padding: 14px 28px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #718cff, var(--primary));
  box-shadow: 0 8px 0 var(--primary-dark), 0 14px 24px rgba(58, 80, 176, 0.25);
  font-size: 22px;
  font-weight: 800;
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.primary-button:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 var(--primary-dark), 0 7px 16px rgba(58, 80, 176, 0.22);
}

.round-button {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 2px solid rgba(86, 108, 172, 0.13);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 7px 16px rgba(67, 84, 145, 0.13);
  font-size: 24px;
}

.cloud {
  position: absolute;
  width: 140px;
  height: 48px;
  border-radius: 999px;
  opacity: 0.52;
  background: #fff;
}

.cloud::before,
.cloud::after {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  content: "";
}

.cloud::before { width: 66px; height: 66px; left: 20px; top: -30px; }
.cloud::after { width: 54px; height: 54px; right: 18px; top: -22px; }
.cloud-one { top: 16%; left: 4%; }
.cloud-two { right: 5%; bottom: 18%; transform: scale(0.75); }

.game-screen {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  overflow: hidden;
}

.game-header {
  display: grid;
  align-items: center;
  grid-template-columns: 60px 1fr 60px;
}

.game-stats {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 3vw, 28px);
}

.game-stats > div,
.result-grid > div {
  display: flex;
  min-width: 84px;
  padding: 7px 14px;
  flex-direction: column;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  text-align: center;
}

.game-stats span,
.result-grid span {
  color: var(--muted);
  font-size: 12px;
}

.game-stats strong,
.result-grid strong {
  font-size: 20px;
}

.game-title-row {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.game-title-row p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.difficulty-badge {
  padding: 6px 14px;
  border-radius: 999px;
  color: #fff;
  background: #788be4;
  font-size: 14px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.78);
  border-radius: 32px;
  background:
    radial-gradient(circle at 50% 15%, rgba(255,255,255,0.82), transparent 28%),
    linear-gradient(180deg, rgba(186, 230, 255, 0.58), rgba(241, 234, 255, 0.72));
  box-shadow: inset 0 -20px 40px rgba(102, 118, 180, 0.08), var(--shadow);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loading-panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  background: rgba(242, 247, 255, 0.85);
  backdrop-filter: blur(6px);
}

.loading-panel p {
  color: var(--muted);
  font-weight: 700;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 6px solid #d7defe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.game-controls {
  display: flex;
  padding-top: 14px;
  justify-content: center;
  gap: 12px;
}

.control-button {
  display: flex;
  min-width: 100px;
  padding: 9px 18px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 16px rgba(60, 76, 133, 0.12);
  font-weight: 800;
}

.control-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.control-button span {
  font-size: 21px;
}

.modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  padding: 20px;
  place-items: center;
  background: rgba(36, 49, 92, 0.45);
  backdrop-filter: blur(7px);
}

.modal-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 3px solid #fff;
  border-radius: 30px;
  background: #fafdff;
  box-shadow: 0 24px 70px rgba(30, 40, 80, 0.28);
  text-align: center;
  animation: pop-in 260ms cubic-bezier(.2, 1.4, .5, 1);
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.78); }
}

.celebration { font-size: 52px; }
.modal-card h2 { margin: 4px 0; font-size: 32px; }
.modal-card > p { margin: 4px 0 20px; color: var(--muted); }

.result-grid {
  display: grid;
  margin-bottom: 24px;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.modal-card .primary-button {
  display: block;
  width: min(240px, 100%);
  margin: 0 auto 14px;
}

.text-button {
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

@media (max-width: 620px) {
  .screen {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .hero-art {
    height: 102px;
    transform: scale(0.84);
    transform-origin: bottom center;
  }

  .home-screen h1 {
    margin-top: 4px;
    font-size: clamp(34px, 12vw, 52px);
  }

  .tagline {
    margin-bottom: 14px;
  }

  .difficulty-card { padding: 14px; }
  .difficulty-options { gap: 7px; }
  .difficulty-button { min-height: 96px; padding: 8px 4px; }
  .difficulty-button strong { font-size: 16px; }

  .game-header {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    gap: 4px;
  }

  .round-button {
    width: 46px;
    height: 46px;
    font-size: 21px;
  }

  .game-stats {
    min-width: 0;
    gap: 4px;
  }

  .game-stats > div {
    min-width: 0;
    padding: 5px 4px;
    flex: 1;
    border-radius: 12px;
  }

  .game-stats strong {
    font-size: 17px;
  }

  .game-title-row {
    min-height: 44px;
    gap: 7px;
  }

  .game-title-row p {
    overflow: hidden;
    max-width: 68vw;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .difficulty-badge {
    padding: 5px 10px;
    font-size: 12px;
  }

  .canvas-wrap {
    border-width: 2px;
    border-radius: 20px;
  }

  .game-controls { gap: 7px; }
  .control-button {
    min-width: 0;
    padding: 8px 7px;
    flex: 1;
    border-radius: 13px;
    font-size: 14px;
  }

  .result-grid > div {
    min-width: 0;
    padding: 7px 6px;
  }

  .modal-card {
    padding: 22px 18px;
    border-radius: 24px;
  }
}

@media (max-width: 380px) {
  .difficulty-card {
    padding: 11px;
  }

  .difficulty-button {
    min-height: 88px;
  }

  .difficulty-icon {
    font-size: 25px;
  }

  .primary-button {
    min-width: 184px;
    font-size: 20px;
  }

  .game-stats span {
    font-size: 10px;
  }
}

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