/* ── In-Game Arcade Layout ── */

body.in-game {
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(232, 191, 216, 0.38), transparent 28%),
    radial-gradient(circle at 82% 8%, rgba(236, 22, 28, 0.24), transparent 26%),
    radial-gradient(circle at 12% 92%, rgba(153, 212, 221, 0.32), transparent 30%),
    #477b36;
}

.game-shell,
.game-shell[hidden] {
  display: none;
}

.game-shell:not([hidden]) {
  display: flex;
}

.game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(232, 191, 216, 0.38), transparent 24%),
    radial-gradient(circle at top right, rgba(236, 22, 28, 0.20), transparent 28%),
    linear-gradient(180deg, #477b36 0%, #386b2b 44%, #2f5725 100%);
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

/* ── Top bar ── */
.g-topbar {
  display: flex;
  align-items: stretch;
  gap: 1px;
  background:
    linear-gradient(90deg, #ec161c, #e8bfd8 30%, #99d4dd 58%, #78bf51);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  flex: 0 0 auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding-top: max(0.21rem, env(safe-area-inset-top));
}

.g-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.35rem;
  background:
    linear-gradient(180deg, rgba(47, 87, 37, 0.9), rgba(38, 76, 30, 0.78));
  min-width: 0;
}

.g-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #d9f2d1;
  font-weight: 800;
}

.g-value {
  font-size: 0.98rem;
  font-weight: 900;
  color: #ecf5ff;
  margin-top: 0.15rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.g-timer {
  color: #99d4dd;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

/* ── Word bar ── */
.g-word-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.48rem 0.72rem;
  background:
    linear-gradient(90deg, rgba(153, 212, 221, 0.18), rgba(232, 191, 216, 0.16));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
  gap: 0.6rem;
}

.g-word {
  display: inline-flex;
  align-items: center;
  min-height: 2.15rem;
  max-width: 100%;
  font-size: 1.18rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ecf5ff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.24);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.g-actions {
  display: flex;
  gap: 0.45rem;
}

.g-btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  background: linear-gradient(180deg, #99d4dd, #78bf51);
  color: #203c19;
  white-space: nowrap;
  transition: transform 120ms ease, filter 120ms ease;
}

.g-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.g-btn:active {
  transform: translateY(0);
}

.g-btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

.g-btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #dcebd7;
  border-color: rgba(255, 255, 255, 0.12);
}

.g-btn-send {
  padding: 0.5rem 1rem;
}

/* ── Word picker ── */
.g-word-picker {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  background: linear-gradient(90deg, rgba(153, 212, 221, 0.28), rgba(232, 191, 216, 0.28));
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.g-pick-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #f7fff4;
}

.g-pick-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.g-pick-options .g-btn {
  background: linear-gradient(180deg, #99d4dd, #78bf51);
  color: #203c19;
  min-width: 100px;
  text-align: center;
}

.g-tool-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  padding: 0.18rem 0.42rem 0.08rem;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  background:
    linear-gradient(180deg, rgba(153, 212, 221, 0.17), rgba(232, 191, 216, 0.10));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.g-tool-group {
  display: flex;
  align-items: center;
  gap: 0.18rem;
  min-width: 0;
}

.g-tool-btn,
.g-color-btn,
.g-size-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 3px 10px rgba(0, 0, 0, 0.14);
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease, background 120ms ease;
}

.g-tool-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: #dbeaff;
  border-radius: 0.65rem;
  width: 2rem;
  height: 2rem;
  min-height: 2rem;
  padding: 0;
  white-space: nowrap;
}

.g-icon-tool {
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}

.g-icon-tool img,
.g-image-toggle img {
  display: block;
  width: 1.62rem;
  height: 1.62rem;
  object-fit: contain;
  pointer-events: none;
}

.g-tool-btn.active {
  background: linear-gradient(180deg, rgba(120, 191, 81, 0.42), rgba(153, 212, 221, 0.24));
  border-color: rgba(153, 212, 221, 0.72);
  color: #f2fffd;
}

.g-clear-btn {
  margin-left: 0.12rem;
  color: #ffe6e6;
  border-color: rgba(236, 22, 28, 0.38);
  background: linear-gradient(180deg, rgba(236, 22, 28, 0.3), rgba(236, 22, 28, 0.13));
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.g-clear-btn:disabled {
  opacity: 0.42;
  color: #8ea1b8;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
}

.g-color-picker,
.g-size-picker {
  position: relative;
}

.g-color-toggle,
.g-color-btn,
.g-size-toggle,
.g-size-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 0.65rem;
  padding: 0;
  flex: 0 0 auto;
  position: relative;
}

.g-color-toggle,
.g-size-toggle {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 3px 10px rgba(0, 0, 0, 0.14);
}

.g-color-toggle::after,
.g-color-btn::after {
  content: '';
  position: absolute;
  inset: 0.28rem;
  border-radius: 0.45rem;
  background: var(--swatch-color, currentColor);
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.g-image-toggle::after {
  display: none;
}

.g-size-toggle,
.g-size-btn {
  display: grid;
  place-items: center;
}

.g-size-preview,
.g-size-btn span {
  display: block;
  width: var(--brush-size, 7px);
  height: var(--brush-size, 7px);
  border-radius: 999px;
  background: #ecf5ff;
  box-shadow: 0 0 0 1px rgba(3, 10, 18, 0.35);
}

.g-color-popover,
.g-size-popover {
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  display: grid;
  gap: 0.32rem;
  padding: 0.42rem;
  background: rgba(47, 87, 37, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.75rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.g-color-popover {
  grid-template-columns: repeat(3, 2rem);
}

.g-size-popover {
  grid-template-columns: repeat(4, 2rem);
}

.g-color-popover[hidden],
.g-size-popover[hidden] {
  display: none !important;
}

.g-size-toggle {
  --brush-size: 7px;
}

.g-size-btn[data-size="2"] {
  --brush-size: 4px;
}

.g-size-btn[data-size="4"] {
  --brush-size: 7px;
}

.g-size-btn[data-size="8"] {
  --brush-size: 11px;
}

.g-size-btn[data-size="12"] {
  --brush-size: 15px;
}

.g-color-btn[data-color="#111827"] {
  color: #111827;
}

.g-color-btn[data-color="#ec161c"] { color: #ec161c; }
.g-color-btn[data-color="#e8bfd8"] { color: #e8bfd8; }
.g-color-btn[data-color="#99d4dd"] { color: #99d4dd; }
.g-color-btn[data-color="#78bf51"] { color: #78bf51; }
.g-color-btn[data-color="#477b36"] { color: #477b36; }
.g-color-btn[data-color="#ffffff"] { color: #ffffff; }

.g-color-btn.active,
.g-size-btn.active {
  transform: scale(1.03);
  border: 2px solid #ecf5ff;
  box-shadow: 0 0 0 2px rgba(153, 212, 221, 0.34), 0 6px 16px rgba(0, 0, 0, 0.22);
}

/* ── Canvas ── */
.g-canvas-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.08rem 0.32rem;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(232, 191, 216, 0.12), transparent 18%, transparent 82%, rgba(153, 212, 221, 0.12));
}

.g-canvas-area canvas {
  display: block;
  width: auto;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  background: #ffffff;
  border-radius: 14px;
  border: 0;
  touch-action: none;
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(153, 212, 221, 0.8),
    0 0 0 5px rgba(232, 191, 216, 0.7),
    inset 0 0 0 1px rgba(5, 18, 32, 0.12);
}

/* ── Chat area ── */
.g-chat-area {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  max-height: 30dvh;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(47, 87, 37, 0.74);
}

.g-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0.68rem;
  min-height: 80px;
  max-height: 22dvh;
}

.g-chat-log .chat-item {
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
  line-height: 1.4;
}

.g-chat-log .chat-item strong {
  color: #f5fbff;
}

.g-chat-log .chat-item.system {
  color: #99d4dd;
  font-style: italic;
  font-size: 0.85rem;
}

.g-chat-log .chat-item.correct {
  color: #e8bfd8;
  font-weight: 600;
}

.g-chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(47, 87, 37, 0.58);
}

.g-chat-input {
  flex: 1;
  font: inherit;
  font-size: 0.92rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.14);
  color: #ecf5ff;
}

.g-chat-input::placeholder {
  color: #7b96b8;
}

/* ── Players strip ── */
.g-players {
  flex: 0 0 auto;
  padding: 0.4rem 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(47, 87, 37, 0.58);
  overflow-x: auto;
}

.g-players ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 0.45rem;
}

.g-players li {
  flex: 0 0 auto;
  padding: 0.4rem 0.7rem;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.085);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  white-space: nowrap;
  color: #aabed6;
}

.g-players li.drawing {
  border-color: rgba(232, 191, 216, 0.72);
  background: linear-gradient(180deg, rgba(232, 191, 216, 0.28), rgba(153, 212, 221, 0.16));
  color: #fff6fb;
}

/* ── Status bar ── */
.g-status-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 0.75rem;
  background: rgba(47, 87, 37, 0.82);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex: 0 0 auto;
}

.g-phase {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #091427;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #e8bfd8, #99d4dd);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.g-status-text {
  font-size: 0.85rem;
  color: #7b96b8;
}

.g-donate-float {
  position: absolute;
  right: max(0.5rem, env(safe-area-inset-right));
  bottom: max(0.42rem, env(safe-area-inset-bottom));
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.38rem 0.68rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.34), transparent 42%),
    linear-gradient(135deg, #ec161c, #e8bfd8 55%, #99d4dd);
  color: #fff8fb;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    0 4px 0 rgba(47, 87, 37, 0.4),
    0 8px 18px rgba(0, 0, 0, 0.22);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.g-donate-float:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.g-donate-float:active {
  transform: translateY(0);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    0 2px 0 rgba(47, 87, 37, 0.4),
    0 5px 12px rgba(0, 0, 0, 0.18);
}

/* ── Desktop: wider canvas, side chat ── */
@media (min-width: 861px) {
  .game-shell {
    max-width: 1200px;
    margin: 0 auto;
    border-radius: 18px;
    height: calc(100dvh - 2rem);
    margin-top: 1rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  }

  .g-canvas-area {
    flex: 1 1 60%;
  }

  .g-chat-area {
    max-height: 35dvh;
  }
}

@media (max-width: 640px) {
  .g-stat {
    padding: 0.42rem 0.24rem;
  }

  .g-label {
    font-size: 0.56rem;
  }

  .g-value {
    font-size: 0.86rem;
  }

  .g-timer {
    font-size: 1.02rem;
  }

  .g-word-bar {
    padding: 0.4rem 0.58rem;
  }

  .g-word {
    min-height: 1.9rem;
    font-size: 1rem;
    letter-spacing: 0.08em;
  }

  .g-tool-row {
    padding: 0.14rem 0.28rem 0.06rem;
    gap: 0.2rem;
  }

  .g-tool-row .g-tool-btn {
    width: 1.9rem;
    height: 1.9rem;
  }

  .g-tool-btn {
    min-height: 1.9rem;
    padding: 0;
    font-size: 0.68rem;
  }

  .g-icon-tool {
    font-size: 0.95rem;
  }

  .g-icon-tool img,
  .g-image-toggle img {
    width: 1.54rem;
    height: 1.54rem;
  }

  .g-color-toggle,
  .g-color-btn,
  .g-size-toggle,
  .g-size-btn {
    width: 1.9rem;
    height: 1.9rem;
  }

  .g-color-popover {
    grid-template-columns: repeat(3, 1.9rem);
  }

  .g-size-popover {
    grid-template-columns: repeat(4, 1.9rem);
  }

  .g-canvas-area {
    padding: 0.05rem 0.18rem;
  }

  .g-canvas-area canvas {
    border-radius: 12px;
    box-shadow:
      0 8px 20px rgba(0, 0, 0, 0.26),
      0 0 0 2px rgba(153, 212, 221, 0.8),
      0 0 0 4px rgba(232, 191, 216, 0.7),
      inset 0 0 0 1px rgba(5, 18, 32, 0.12);
  }

  .g-chat-log {
    min-height: 70px;
  }

  .g-status-bar {
    padding: 0.35rem 0.55rem;
  }
}
