:root {
  color-scheme: light;
  --bg: #f5f2eb;
  --ink: #202126;
  --muted: #69707c;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(29, 32, 40, 0.13);
  --shadow: 0 20px 60px rgba(31, 40, 54, 0.14);
  --accent: #176c73;
  --accent-strong: #0e5056;
  --tube-glass: rgba(255, 255, 255, 0.47);
  --tube-edge: rgba(20, 35, 49, 0.34);
  --tube-width: clamp(54px, 8vw, 82px);
  --tube-height: clamp(190px, 34vh, 270px);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(239, 104, 74, 0.22), transparent 31rem),
    radial-gradient(circle at 80% 14%, rgba(32, 142, 134, 0.2), transparent 28rem),
    linear-gradient(140deg, #f8f3e9 0%, #e9f1ef 48%, #f2f3f6 100%);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: clamp(14px, 2.5vw, 28px);
}

.app[hidden],
.profile-screen[hidden] {
  display: none;
}

.profile-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 42px);
}

.profile-shell {
  width: min(960px, 100%);
}

.profile-hero {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-bottom: clamp(22px, 5vw, 42px);
  text-align: center;
}

.profile-hero p {
  color: var(--muted);
  font-size: 1rem;
}

.large-logo {
  width: 76px;
  height: 76px;
  border-radius: 8px 8px 24px 24px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2.5vw, 22px);
}

.profile-grid.is-busy {
  pointer-events: none;
  opacity: 0.7;
}

.profile-loading {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  gap: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  box-shadow: var(--shadow);
}

.loading-dot {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(23, 108, 115, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

.profile-card {
  min-height: 260px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.profile-card:hover,
.profile-card:focus-visible {
  outline: 3px solid rgba(23, 108, 115, 0.24);
  outline-offset: 2px;
  transform: translateY(-2px);
}

.profile-card strong {
  font-size: 1.55rem;
}

.avatar {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 2rem;
  font-weight: 900;
  box-shadow:
    inset 10px 10px 18px rgba(255, 255, 255, 0.25),
    0 14px 26px rgba(31, 40, 54, 0.15);
}

.profile-card.teal .avatar {
  background: linear-gradient(145deg, #176c73, #2da89a);
}

.profile-card.rose .avatar {
  background: linear-gradient(145deg, #c34f7a, #ef8b77);
}

.profile-card.gold .avatar {
  background: linear-gradient(145deg, #d69c22, #f2c84b);
  color: #553f0a;
}

.profile-progress {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
}

.profile-progress span {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  font-size: 0.86rem;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 18px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

.logo {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 2px solid rgba(18, 31, 45, 0.7);
  border-top: 0;
  border-radius: 5px 5px 16px 16px;
  background:
    linear-gradient(to top, #ef6c43 0 34%, #35a7a0 34% 67%, #f2c84b 67% 100%);
  box-shadow: inset 8px 0 12px rgba(255, 255, 255, 0.32);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.45rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats {
  display: flex;
  gap: 8px;
}

.stats div {
  min-width: 68px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.56);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.stats strong {
  display: block;
  margin-top: 2px;
  font-size: 1.15rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.level-button,
.primary-button,
.text-button,
.icon-button,
.win-actions button {
  min-height: 40px;
  border-radius: 7px;
  color: var(--ink);
  background: transparent;
}

.level-button {
  min-width: 48px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.level-button.is-active {
  color: #fff;
  background: var(--accent);
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  font-size: 1.5rem;
  line-height: 1;
}

.primary-button {
  padding: 0 17px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.text-button {
  padding: 0 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  font-weight: 700;
}

.text-button:hover,
.icon-button:hover,
.win-actions button:not(.primary-button):hover {
  background: rgba(255, 255, 255, 0.86);
}

.primary-button:hover,
.level-button.is-active:hover {
  background: var(--accent-strong);
}

.board-wrap {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 22px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.1)),
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(255, 255, 255, 0.16) 34px 35px);
  box-shadow: var(--shadow);
  overflow: auto;
}

.board {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(calc(var(--tube-width) + 20px), 1fr));
  gap: clamp(18px, 3vw, 34px) clamp(14px, 2.6vw, 26px);
  align-items: end;
  justify-items: center;
  padding: 10px 0 24px;
}

.tube-button {
  position: relative;
  width: calc(var(--tube-width) + 18px);
  min-height: calc(var(--tube-height) + 42px);
  display: grid;
  place-items: end center;
  padding: 18px 9px 12px;
  border-radius: 8px;
  background: transparent;
}

.tube-button:focus-visible,
.tube-button.is-selected {
  outline: 3px solid rgba(23, 108, 115, 0.32);
  outline-offset: 2px;
}

.tube-button.can-receive .tube {
  transform: translateY(-4px);
  border-color: rgba(23, 108, 115, 0.72);
}

.tube {
  position: relative;
  width: var(--tube-width);
  height: var(--tube-height);
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  overflow: hidden;
  border: 3px solid var(--tube-edge);
  border-top: 0;
  border-radius: 0 0 24px 24px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.55), transparent 22% 74%, rgba(255, 255, 255, 0.3)),
    var(--tube-glass);
  box-shadow:
    inset 10px 0 12px rgba(255, 255, 255, 0.26),
    inset -8px 0 12px rgba(60, 75, 94, 0.08),
    0 18px 26px rgba(34, 45, 58, 0.13);
  transition:
    transform 180ms ease,
    border-color 180ms ease;
}

.tube::before {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  right: -8px;
  height: 9px;
  border: 3px solid var(--tube-edge);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: rgba(255, 255, 255, 0.5);
  z-index: 2;
}

.liquid {
  height: 25%;
  width: 100%;
  transform-origin: center bottom;
  box-shadow: inset 0 8px 14px rgba(255, 255, 255, 0.22);
}

.liquid:first-child {
  border-radius: 0 0 19px 19px;
}

.tube-button.is-source .tube {
  transform: translateY(-12px) rotate(-2deg);
}

.tube-button.is-complete::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 28px;
  height: 4px;
  border-radius: 999px;
  background: rgba(23, 108, 115, 0.72);
}

.pour-ghost {
  position: fixed;
  z-index: 5;
  width: 16px;
  height: 58px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(15deg);
  animation: pour 420ms ease-out;
}

@keyframes pour {
  0% {
    opacity: 0;
    transform: translate(-50%, -80%) scaleY(0.35) rotate(15deg);
  }
  28%,
  72% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 20%) scaleY(1) rotate(15deg);
  }
}

.win-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 27, 34, 0.38);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.win-dialog[hidden] {
  display: none;
}

.win-panel {
  width: min(390px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

.win-panel p {
  margin-top: 10px;
  color: var(--muted);
}

.win-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.win-actions button:not(.primary-button) {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 760px) {
  .app {
    gap: 12px;
  }

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

  .profile-card {
    min-height: 190px;
  }

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

  .stats,
  .controls {
    justify-content: flex-start;
  }

  .controls {
    width: 100%;
  }

  .segmented {
    order: 2;
    width: 100%;
  }

  .level-button {
    flex: 1;
  }

  .board {
    grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  }
}

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