﻿@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;600;700;800&family=Fredoka:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg-a: #fff7cc;
  --bg-b: #c9f0ff;
  --bg-c: #ffd7eb;
  --panel: #fffefc;
  --panel-2: #f7fbff;
  --ink: #2d2a41;
  --muted: #655f7d;
  --line: #2d2a41;
  --cyan: #20b8ff;
  --orange: #ff8f3a;
  --green: #43c376;
  --danger: #ff4d6d;
  --shadow: 0 8px 0 rgba(45, 42, 65, 0.9);
  --chat-log-height: 300px;
}

* {
  box-sizing: border-box;
}

html,
body {
  overscroll-behavior-y: contain;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Baloo 2", "Microsoft YaHei", sans-serif;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.82), transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, 0.72), transparent 42%),
    linear-gradient(140deg, var(--bg-a), var(--bg-b) 56%, var(--bg-c));
}

.bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.2;
  background-image:
    radial-gradient(circle, rgba(45, 42, 65, 0.45) 1.4px, transparent 1.4px),
    radial-gradient(circle, rgba(45, 42, 65, 0.35) 1.2px, transparent 1.2px);
  background-size: 28px 28px, 48px 48px;
  background-position: 0 0, 12px 10px;
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px calc(34px + env(safe-area-inset-bottom));
}

.hero {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: #4a7be7;
}

h1 {
  margin: 6px 0 8px;
  font-family: "Fredoka", "Baloo 2", sans-serif;
  font-size: clamp(36px, 5vw, 68px);
  line-height: 1.02;
  color: #2f2b4b;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.65);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 20px;
}

.card {
  border-radius: 24px;
  border: 3px solid var(--line);
  background: linear-gradient(180deg, #ffffff, var(--panel-2));
  box-shadow: var(--shadow);
}

.lobby {
  max-width: 600px;
  padding: 20px;
}

.join-form {
  display: grid;
  gap: 14px;
  margin: 0;
}

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  color: var(--muted);
}

input,
button {
  font: inherit;
}

input[type="text"] {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
  font-size: 16px;
}

button {
  border: 3px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  padding: 8px 16px;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

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

button.primary {
  background: linear-gradient(130deg, #4ed3ff, #20b8ff);
  color: #012133;
  box-shadow: 0 6px 0 #1577a4;
}

button.ghost {
  background: linear-gradient(130deg, #fff2cf, #ffe3a5);
  color: #493920;
  box-shadow: 0 6px 0 #cba44d;
}

.tip {
  margin: 12px 2px 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.join-status {
  margin: 4px 2px 0;
  min-height: 22px;
  font-size: 14px;
  color: var(--muted);
}

.join-status.error {
  color: #b42318;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.round-transition {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(16, 21, 44, 0.5);
  opacity: 0;
  pointer-events: none;
}

.round-transition-card {
  min-width: min(90vw, 620px);
  text-align: center;
  border-radius: 24px;
  padding: 24px;
  border: 4px solid var(--line);
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.85), transparent 36%),
    linear-gradient(140deg, #fff6d8, #ffd6ef 55%, #d2f7ff);
  box-shadow: 0 10px 0 rgba(45, 42, 65, 0.95);
}

.transition-round {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(34px, 6vw, 62px);
  font-weight: 700;
  color: #2c2a47;
}

.transition-drawer {
  margin: 6px 0 0;
  font-size: clamp(24px, 3.5vw, 38px);
  color: #23519e;
  font-weight: 700;
}

.transition-category {
  margin: 8px 0 0;
  font-size: 18px;
  color: #8f4d00;
}

.round-transition.show {
  animation: transitionIn 1.4s ease forwards;
}

.round-transition.hide {
  animation: transitionOut 0.35s ease forwards;
}

@keyframes transitionIn {
  0% {
    opacity: 0;
    transform: scale(1.05);
  }
  14% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 1;
  }
}

@keyframes transitionOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.game {
  display: grid;
  gap: 14px;
}

[data-animate] {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  animation: cardIn 420ms ease-out forwards;
}

@keyframes cardIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.game-top {
  padding: 16px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 2fr);
  position: relative;
  overflow: hidden;
}

.game-top::after {
  content: "";
  position: absolute;
  inset: auto -12% -52% auto;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(32, 184, 255, 0.24), transparent 72%);
  pointer-events: none;
}

.status-head {
  display: grid;
  gap: 8px;
  align-content: start;
}

.round-title {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(30px, 3vw, 48px);
}

.tiny {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted {
  margin: 0;
  color: var(--muted);
}

.phase-pill {
  margin: 2px 0 0;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 999px;
  border: 3px solid var(--line);
  background: #f0f3ff;
  color: #2d2a41;
  font-family: "Fredoka", sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.game.is-drawer .phase-pill {
  background: #ddffe9;
  color: #1d6a42;
}

.game.is-guesser .phase-pill {
  background: #ffe8d4;
  color: #8a4a0f;
}

.headline-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  border-radius: 16px;
  border: 3px solid var(--line);
  background: #ffffff;
  padding: 10px 12px;
  min-height: 98px;
  display: grid;
  align-content: space-between;
  box-shadow: 0 5px 0 rgba(45, 42, 65, 0.72);
}

.metric.emph {
  grid-column: span 2;
  background: linear-gradient(130deg, #ffffff, #f1faff 35%, #fff4ea);
}

.metric-value {
  margin: 6px 0 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(24px, 2.3vw, 34px);
  line-height: 1;
  font-weight: 700;
}

.metric-value.name {
  font-size: clamp(20px, 2vw, 28px);
}

.metric-value.countdown {
  font-size: clamp(30px, 2.8vw, 42px);
  color: #1489cb;
}

.metric-value.countdown.urgent {
  color: var(--danger);
  animation: urgentPulse 0.7s linear infinite;
}

@keyframes urgentPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08) rotate(-1deg);
  }
}

.word-display {
  margin: 6px 0 0;
  font-size: clamp(22px, 2.1vw, 34px);
  font-weight: 700;
  line-height: 1.18;
  color: #2f2b4b;
  word-break: break-word;
}

.word-display.mine {
  color: #1f8d52;
}

.clue-sub {
  margin: 7px 0 0;
  font-size: 13px;
  color: #7f5c2b;
}

.bump {
  animation: bumpIn 240ms ease-out;
}

@keyframes bumpIn {
  0% {
    opacity: 0.35;
    transform: scale(0.95);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 2.25fr) minmax(300px, 0.95fr);
  gap: 14px;
  align-items: stretch;
}

.board-card {
  padding: 14px;
  background: linear-gradient(180deg, #fffdf7, #edf8ff);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

#board {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 14px;
  border: 3px solid var(--line);
  background: #ffffff;
  display: block;
  cursor: crosshair;
}

#board.disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.board-actions {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.board-actions label {
  display: grid;
  gap: 4px;
}

.board-actions input[type="range"] {
  width: 130px;
}

.board-actions input[type="color"] {
  width: 46px;
  height: 36px;
  border-radius: 8px;
  padding: 0;
  border: 2px solid var(--line);
}

.side {
  display: grid;
  gap: 14px;
  align-content: stretch;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.side .card {
  padding: 14px;
  background: linear-gradient(180deg, #fefeff, #f2f8ff);
}

h3 {
  margin: 0 0 10px;
  font-family: "Fredoka", sans-serif;
  font-size: 26px;
}

.players {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.player-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 9px 11px;
  background: #ffffff;
}

.player-row.me {
  background: #e6f8ff;
}

.player-row.drawer {
  background: #fff1e4;
}

.player-row.offline {
  opacity: 0.55;
}

.player-name {
  font-weight: 700;
}

.player-score {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  color: #1f6fff;
  font-size: 20px;
}

.chat-card {
  display: grid;
  gap: 10px;
  grid-template-rows: auto minmax(0, var(--chat-log-height)) auto;
  overflow: hidden;
  min-height: 0;
}

.chat-scroll-wrap {
  height: var(--chat-log-height);
  min-height: var(--chat-log-height);
  max-height: var(--chat-log-height);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9px;
  gap: 8px;
  align-items: stretch;
}

.chat-log {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  min-height: 0;
  max-height: none;
  height: 100%;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #2aa7ff #dbe8ff;
  scrollbar-gutter: stable;
}

.chat-log::-webkit-scrollbar {
  width: 10px;
}

.chat-log::-webkit-scrollbar-track {
  background: #dbe8ff;
  border-radius: 999px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #6fd6ff, #2aa7ff);
  border-radius: 999px;
  border: 1px solid #8ac8ff;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4ec6ff, #1898f0);
}

.chat-progress {
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #eef3ff;
  overflow: hidden;
  position: relative;
}

.chat-progress-fill {
  position: absolute;
  inset: auto 0 0;
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #6fd6ff, #2aa7ff);
  transform-origin: bottom center;
  transform: scaleY(1);
  transition: transform 0.14s linear;
}

.chat-item {
  padding: 7px 8px;
  border-radius: 9px;
  border: 2px solid #7a9ae6;
  background: #edf3ff;
  font-size: 15px;
  animation: chatIn 170ms ease-out both;
}

@keyframes chatIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-item.system {
  border-color: #ffb164;
  background: #fff1df;
  color: #744112;
}

.guess-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.guess-form input {
  border: 3px solid var(--line);
  border-radius: 999px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
}

@media (max-width: 1120px) {
  .game-top {
    grid-template-columns: 1fr;
  }

  .headline-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric.emph {
    grid-column: span 2;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side {
    grid-template-rows: auto auto;
  }

  .chat-card {
    --chat-log-height: min(38vh, 320px);
    grid-template-rows: auto minmax(0, var(--chat-log-height)) auto;
  }

  .chat-scroll-wrap {
    min-height: 140px;
    height: var(--chat-log-height);
    max-height: var(--chat-log-height);
  }
}

@media (max-width: 640px) {
  .page {
    padding: max(10px, env(safe-area-inset-top)) 10px calc(18px + env(safe-area-inset-bottom));
  }

  .hero {
    margin-bottom: 10px;
  }

  .eyebrow {
    font-size: 10px;
  }

  .subtitle {
    font-size: 16px;
    line-height: 1.3;
  }

  .tip {
    margin-top: 14px;
    font-size: 13px;
  }

  h1 {
    margin: 4px 0 6px;
    font-size: clamp(30px, 9vw, 46px);
  }

  .game-top {
    padding: 12px;
    gap: 10px;
  }

  .headline-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 82px;
    padding: 8px 10px;
    border-width: 2px;
  }

  .metric-value {
    font-size: clamp(20px, 6vw, 30px);
  }

  .metric-value.name {
    font-size: clamp(18px, 5.5vw, 24px);
  }

  .metric.emph {
    grid-column: 1 / -1;
  }

  #board {
    aspect-ratio: 4 / 3;
  }

  .board-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .board-actions input[type="range"] {
    width: 100%;
  }

  .board-actions input[type="color"] {
    width: 100%;
    height: 40px;
  }

  .board-actions button {
    width: 100%;
  }

  .chat-card {
    --chat-log-height: min(34vh, 290px);
    gap: 8px;
    max-height: none;
  }

  .chat-scroll-wrap {
    min-height: 130px;
    height: var(--chat-log-height);
    max-height: var(--chat-log-height);
    grid-template-columns: minmax(0, 1fr) 8px;
  }

  .guess-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .guess-form button {
    width: auto;
    min-width: 84px;
  }

  #lobby button,
  .board-actions button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .headline-metrics {
    grid-template-columns: 1fr;
  }

  .metric.emph {
    grid-column: auto;
  }

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

  .guess-form {
    grid-template-columns: 1fr;
  }

  .guess-form button {
    width: 100%;
  }

  .chat-progress {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
