:root {
  --ios-blue: #007aff;
  --ios-blue-strong: #0063d1;
  --ios-green: #34c759;
  --ios-red: #ff3b30;
  --ios-orange: #ff9500;
  --ios-gray-1: #8e8e93;
  --ios-gray-2: #aeaeb2;
  --ios-gray-3: #c7c7cc;
  --ios-gray-4: #d1d1d6;
  --ios-gray-5: #e5e5ea;
  --ios-gray-6: #f2f2f7;
  --ios-separator: rgba(60, 60, 67, 0.18);
  --ios-separator-strong: rgba(60, 60, 67, 0.28);
  --ios-fill: rgba(118, 118, 128, 0.12);
  --ios-fill-strong: rgba(118, 118, 128, 0.2);
  --ios-label-secondary: rgba(60, 60, 67, 0.65);

  --bg-1: #070b16;
  --bg-2: #083274;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-soft: rgba(255, 255, 255, 0.72);
  --text: #0b1220;
  --text-soft: var(--ios-label-secondary);
  --primary: var(--ios-blue);
  --primary-strong: var(--ios-blue-strong);
  --danger: var(--ios-red);
  --success: var(--ios-green);
  --bubble-self: var(--ios-blue);
  --bubble-opp: var(--ios-gray-5);
  --shell-gap: 16px;
  --keyboard-offset: 0px;
  --category-roll-item-height: 96px;
  --category-roll-view-height: 288px;
  --category-roll-pad: calc((var(--category-roll-view-height) - var(--category-roll-item-height)) * 0.5);
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "SF Pro Text",
    "SF Pro Display",
    "Heebo",
    "Rubik",
    "Assistant",
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 12%, rgba(0, 122, 255, 0.38) 0%, transparent 56%),
    radial-gradient(circle at 88% 0%, rgba(175, 82, 222, 0.22) 0%, transparent 48%),
    radial-gradient(circle at 50% 118%, rgba(52, 199, 89, 0.18) 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

.app-shell {
  max-width: 840px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + var(--shell-gap)) var(--shell-gap)
    calc(env(safe-area-inset-bottom, 0px) + var(--shell-gap));
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-content: start;
}

.view {
  width: 100%;
}

#lobbyView {
  display: grid;
  gap: 14px;
}

#lobbyView .panel-header {
  margin-bottom: 0;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--panel);
  border-radius: 22px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2.2rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.5rem;
  letter-spacing: -0.015em;
}

h3 {
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-soft);
  margin-bottom: 20px;
  line-height: 1.35;
}

.stack-form {
  display: grid;
  gap: 10px;
}

label {
  font-weight: 600;
}

input,
button {
  border: 0;
  border-radius: 14px;
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

input {
  padding: 12px 14px;
  border: 1px solid var(--ios-separator);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
  min-height: 44px;
}

input:focus {
  outline: none;
  border-color: rgba(0, 122, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.16);
}

input::placeholder {
  color: rgba(60, 60, 67, 0.5);
}

button {
  padding: 12px 14px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 10px 20px rgba(0, 122, 255, 0.22);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease, filter 0.12s ease;
  min-height: 44px;
}

button:hover {
  background: var(--primary-strong);
}

button:active {
  transform: scale(0.98);
  filter: brightness(0.96);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.18), 0 10px 20px rgba(0, 122, 255, 0.22);
}

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

.secondary-btn {
  background: rgba(118, 118, 128, 0.14);
  color: var(--text);
  box-shadow: none;
}

.secondary-btn:hover {
  background: rgba(118, 118, 128, 0.2);
}

.public-game-btn {
  min-height: 38px;
  padding: 10px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--ios-separator);
  box-shadow: none;
}

.public-game-btn.public-on {
  background: rgba(52, 199, 89, 0.16);
  color: #0a5d2c;
  border-color: rgba(52, 199, 89, 0.3);
}

.public-game-btn.public-off {
  background: rgba(118, 118, 128, 0.12);
  color: rgba(60, 60, 67, 0.82);
}

.panel-header {
  margin-bottom: 16px;
}

.lobby-header {
  display: grid;
  gap: 10px;
}

.lobby-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lobby-title-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.watch-pill:active {
  transform: scale(0.98);
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.16);
  color: #003a82;
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: none;
}

.me-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(118, 118, 128, 0.12);
}

.invite-wait-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(0, 122, 255, 0.12);
  color: #003a82;
}

.invite-wait-status p {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.challenge-visibility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(118, 118, 128, 0.12);
}

.spinner-dot {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 122, 255, 0.28);
  border-top-color: rgba(0, 122, 255, 0.9);
  border-radius: 999px;
  animation: spinner-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spinner-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.panel-header p {
  margin-top: 6px;
  color: var(--text-soft);
}

.panel {
  background: rgba(242, 242, 247, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 18px;
  padding: 12px;
}

.lobby-panel {
  display: grid;
  gap: 10px;
}

.team-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 4px;
}

.team-form button {
  white-space: nowrap;
}

#leaveTeamBtn {
  justify-self: start;
}

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

.players-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  padding: 10px 12px;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.players-list li:active {
  transform: scale(0.995);
  background: rgba(118, 118, 128, 0.12);
}

.lobby-player-row {
  border: 1px solid var(--ios-separator);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.lobby-empty {
  display: block !important;
  text-align: center;
  color: var(--text-soft);
}

.player-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.team-members {
  font-size: 0.8rem;
  color: var(--text-soft);
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-state {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.player-state.busy {
  color: var(--danger);
}

.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(145deg, #0284c7, #38bdf8);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.36);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.18);
}

.avatar-small {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
}

.challenge-btn {
  min-width: 88px;
}

.challenge-btn.loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.challenge-btn.loading::before {
  content: "";
  width: 11px;
  height: 11px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spinner-spin 0.75s linear infinite;
}

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 110px;
}

.join-team-btn {
  padding: 10px 12px;
}

.game {
  position: relative;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.52);
  padding: 16px;
  box-shadow: 0 22px 56px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  height: calc(
    100dvh -
      (env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 2 * var(--shell-gap)) -
      var(--keyboard-offset, 0px)
  );
  min-height: calc(
    100dvh -
      (env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 2 * var(--shell-gap)) -
      var(--keyboard-offset, 0px)
  );
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
}

#gameView.game {
  grid-template-rows: minmax(0, 1fr) auto auto;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-chip strong {
  display: block;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-stack {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.score-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(118, 118, 128, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 1.2rem;
  font-weight: 800;
  direction: ltr;
}

.score-pill {
  display: inline-grid;
  justify-items: center;
  min-width: 44px;
}

.score-label {
  font-size: 0.65rem;
  color: var(--text-soft);
  font-weight: 700;
  line-height: 1;
}

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

.round-banner {
  margin: 12px 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(0, 122, 255, 0.14);
  color: #003a82;
  border: 1px solid rgba(0, 122, 255, 0.22);
  font-weight: 700;
}

.round-header .round-banner {
  margin: 0;
}

.round-header {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ios-separator);
}

.turn-toast {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
  display: grid;
  place-items: center;
  padding: 10px 12px;
  border-radius: 999px;
  width: fit-content;
  max-width: calc(100% - 32px);
  background: rgba(52, 199, 89, 0.18);
  border: 1px solid rgba(52, 199, 89, 0.32);
  color: #0a5d2c;
  font-weight: 800;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
}

.turn-toast.mine {
  background: rgba(52, 199, 89, 0.18);
  border-color: rgba(52, 199, 89, 0.32);
  color: #0a5d2c;
}

.turn-toast.theirs {
  background: rgba(0, 122, 255, 0.16);
  border-color: rgba(0, 122, 255, 0.28);
  color: #003a82;
}

.chat-panel {
  border-radius: 18px;
  background: rgba(242, 242, 247, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.55);
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  grid-row: 3;
}

#gameView .chat-panel {
  grid-row: 1;
}

.chat-spacer {
  flex: 1 1 auto;
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 10px;
}

.chat-message {
  max-width: 86%;
  border-radius: 18px;
  padding: 10px 12px;
  line-height: 1.35;
  word-break: break-word;
  align-self: flex-start;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset, 0 10px 18px rgba(15, 23, 42, 0.06);
}

.chat-message.self {
  align-self: flex-end;
  background: var(--bubble-self);
  color: #fff;
}

.chat-message.opp {
  align-self: flex-start;
  background: var(--bubble-opp);
}

.chat-message.correct {
  border: 1px solid rgba(52, 199, 89, 0.35);
}

.chat-message.opp.correct {
  background: rgba(52, 199, 89, 0.16);
  color: #0a5d2c;
}

.chat-message.self.correct {
  background: var(--ios-green);
  color: #052e16;
}

.chat-message.joker-answer {
  border: 1px solid #c084fc;
  box-shadow: 0 0 0 1px rgba(192, 132, 252, 0.25) inset;
}

.chat-message.invalid {
  border: 1px solid rgba(255, 59, 48, 0.3);
  background: rgba(255, 59, 48, 0.16);
  color: #7a1916;
}

.chat-message.duplicate {
  border: 1px solid rgba(255, 149, 0, 0.32);
  background: rgba(255, 149, 0, 0.18);
  color: #7a3b00;
}

.chat-message.system {
  align-self: center;
  background: rgba(0, 122, 255, 0.12);
  color: #003a82;
  border: 1px solid rgba(0, 122, 255, 0.22);
  font-size: 0.9rem;
}

.turn-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  border-radius: 12px;
  padding: 8px 10px;
  height: 44px;
  background: rgba(118, 118, 128, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.55);
  transition: background 0.2s ease, color 0.2s ease;
  grid-row: 4;
}

#turnLabel {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-track {
  width: 100%;
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(118, 118, 128, 0.18);
  overflow: visible;
  position: relative;
  grid-row: 5;
}

#gameView .timeline-track {
  grid-row: 2;
}

.timeline-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ios-green) 0%, var(--ios-orange) 55%, var(--ios-red) 100%);
  transform-origin: right center;
  transition: transform 0.2s linear;
}

.timeline-badge {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 2;
}

.timeline-track #timerLabel {
  display: none;
}

.timeline-fill.theirs {
  background: linear-gradient(90deg, rgba(0, 122, 255, 0.85) 0%, rgba(0, 122, 255, 0.55) 55%, rgba(88, 86, 214, 0.85) 100%);
}

.game.turn-self .turn-row {
  background: rgba(52, 199, 89, 0.16);
  color: #0a5d2c;
}

.game.turn-opponent .turn-row {
  background: rgba(0, 122, 255, 0.14);
  color: #003a82;
}

#timerLabel {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(118, 118, 128, 0.14);
  color: rgba(60, 60, 67, 0.82);
}

.game.turn-self #timerLabel {
  background: rgba(52, 199, 89, 0.22);
  color: #0a5d2c;
}

.game.turn-opponent #timerLabel {
  background: rgba(0, 122, 255, 0.2);
  color: #003a82;
}

.answer-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  grid-row: 6;
  padding-top: 10px;
  border-top: 1px solid var(--ios-separator);
}

#gameView .answer-form {
  grid-row: 3;
}

#answerInput {
  min-width: 0;
}

.joker-btn {
  min-width: 96px;
}

.joker-btn.used {
  opacity: 0.75;
}

.category-view {
  height: calc(
    100dvh -
      (env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 2 * var(--shell-gap)) -
      var(--keyboard-offset, 0px)
  );
  min-height: calc(
    100dvh -
      (env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 2 * var(--shell-gap)) -
      var(--keyboard-offset, 0px)
  );
  display: grid;
  place-items: center;
}

.category-page-card {
  width: min(460px, 100%);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 20px;
  padding: 20px 16px;
  display: grid;
  gap: 12px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
}

.category-roller {
  position: relative;
  min-height: var(--category-roll-view-height);
  height: var(--category-roll-view-height);
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--ios-separator);
  background: linear-gradient(180deg, rgba(242, 242, 247, 0.92) 0%, rgba(242, 242, 247, 0.72) 100%);
  perspective: 900px;
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
}

.category-roller::before,
.category-roller::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 13px;
  z-index: 1;
  pointer-events: none;
}

.category-roller::before {
  top: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0));
}

.category-roller::after {
  bottom: 0;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0));
}

.category-roll-track {
  display: flex;
  flex-direction: column;
  will-change: transform;
  transform: translate3d(0, 0, 0);
  padding-top: var(--category-roll-pad);
  padding-bottom: var(--category-roll-pad);
  transform-style: preserve-3d;
}

.category-roll-item {
  --roll-rot: 0deg;
  --roll-z: 0px;
  --roll-scale: 1;
  --roll-opacity: 1;
  --roll-blur: 0px;
  min-height: var(--category-roll-item-height);
  height: var(--category-roll-item-height);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.44rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.18;
  padding: 0 14px;
  transform: translateZ(var(--roll-z)) rotateX(var(--roll-rot)) scale(var(--roll-scale));
  opacity: var(--roll-opacity);
  filter: blur(var(--roll-blur));
  transform-style: preserve-3d;
  backface-visibility: hidden;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85), 0 10px 18px rgba(15, 23, 42, 0.08);
  transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease;
}

.category-roller.rolling .category-roll-item {
  transition: none;
  will-change: transform, opacity, filter;
}

.category-roll-item.roll-center {
  filter: none;
}

.category-roller.rolling {
  box-shadow:
    inset 0 0 0 1px rgba(0, 122, 255, 0.2),
    0 0 0 2px rgba(0, 122, 255, 0.08),
    0 12px 26px rgba(0, 0, 0, 0.12);
}

.category-roller.rolling .category-roll-track {
  filter: none;
}

.category-roll-label {
  max-width: 100%;
  width: 100%;
  text-align: center;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  word-break: break-word;
}

.category-roll-window {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  transform: translateY(-50%) translateZ(45px);
  height: var(--category-roll-item-height);
  border-radius: 12px;
  border: 1px solid rgba(0, 122, 255, 0.28);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 0 1px rgba(0, 122, 255, 0.12), 0 10px 18px rgba(15, 23, 42, 0.08);
  pointer-events: none;
  z-index: 2;
}

.end-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  border-radius: 24px;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}

.end-card {
  position: relative;
  width: min(420px, 100%);
  border-radius: 18px;
  padding: 22px 16px;
  text-align: center;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.end-card.win {
  border: 2px solid var(--ios-green);
  box-shadow: 0 20px 40px rgba(52, 199, 89, 0.28);
}

.end-card.lose {
  border: 2px solid var(--ios-red);
  box-shadow: 0 20px 40px rgba(255, 59, 48, 0.24);
}

.end-card.draw {
  border: 2px solid var(--ios-blue);
  box-shadow: 0 20px 40px rgba(0, 122, 255, 0.22);
}

.end-subtitle {
  margin-top: 6px;
  color: var(--text-soft);
}

.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 8px;
  height: 14px;
  border-radius: 3px;
  opacity: 0.85;
  animation: confetti-fall 1.8s linear forwards;
}

@keyframes confetti-fall {
  from {
    transform: translateY(0) rotate(0deg);
  }
  to {
    transform: translateY(220px) rotate(480deg);
    opacity: 0;
  }
}

.overlay-card {
  background: rgba(255, 255, 255, 0.9);
  width: min(420px, 100%);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 10px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.overlay-card h3 {
  font-size: 1.5rem;
}

.ready-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: initial;
}

.ready-indicators {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

#readyBtn {
  flex: 1 1 200px;
}

.ready-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ready-grid .ready-pill {
  width: 100%;
  justify-content: center;
}

.ready-pill {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 10px;
  background: rgba(118, 118, 128, 0.08);
  border: 1px solid var(--ios-separator);
  color: rgba(60, 60, 67, 0.82);
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: -0.01em;
  user-select: none;
  pointer-events: none;
  cursor: default;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ready-pill::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: rgba(118, 118, 128, 0.55);
  box-shadow: 0 0 0 3px rgba(118, 118, 128, 0.14);
  flex: 0 0 auto;
}

.ready-pill.ready {
  background: rgba(52, 199, 89, 0.18);
  color: #0a5d2c;
  border-color: rgba(52, 199, 89, 0.32);
}

.ready-pill.ready::before {
  background: var(--ios-green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.14);
}

.invite-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.5);
}

.invite-card {
  width: min(360px, 100%);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  padding: 16px;
  display: grid;
  gap: 12px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.invite-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 720px) {
  :root {
    --shell-gap: 10px;
    --category-roll-item-height: 88px;
    --category-roll-view-height: 264px;
  }

  body {
    overflow-x: hidden;
  }

  .app-shell {
    max-width: 100%;
  }

  .card,
  .game {
    border-radius: 22px;
    padding: 14px 12px;
  }

  .category-view {
    border-radius: 22px;
  }

  .category-page-card {
    padding: 18px 12px;
  }

  .category-roll-item {
    font-size: 1.28rem;
  }

  .chat-panel {
    min-height: 0;
    height: 100%;
    max-height: none;
  }

  .chat-message {
    max-width: 92%;
  }

  .game-header {
    gap: 8px;
    align-items: flex-start;
  }

  .score-box {
    min-width: 98px;
    justify-content: center;
  }

  .player-chip strong {
    max-width: 80px;
  }

  .game {
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
  }

  .answer-form {
    position: sticky;
    bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(242, 242, 247, 0.86);
    border-top: 1px solid var(--ios-separator);
    padding-top: 10px;
    padding-bottom: 6px;
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "input input"
      "joker send";
  }

  #answerInput {
    grid-area: input;
  }

  .joker-btn {
    grid-area: joker;
    width: 100%;
  }

  .answer-form button[type="submit"] {
    grid-area: send;
    width: 100%;
  }

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

  .ready-row {
    flex-wrap: wrap;
    justify-content: center;
  }

  #readyBtn {
    flex: 1 1 100%;
    width: 100%;
  }

  .ready-indicators {
    width: 100%;
    justify-content: center;
  }

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

@media (max-width: 420px) {
  body {
    font-size: 15.5px;
  }

  .chat-message {
    font-size: 0.95rem;
  }
}
