@font-face {
  font-family: 'Starborn';
  src:
    url('/fonts/Starborn.ttf') format('truetype'),
    url('/fonts/Starborn.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #6ecff6;
  --bg-dark: #4ab8e8;
  --bg-class: #3a8fbf;
  --card: #fffef7;
  --card-border: #2d2d2d;
  --text: #2d2d2d;
  --text-muted: #5a5a5a;
  --primary: #ff6b6b;
  --primary-dark: #e85555;
  --secondary: #ffd93d;
  --secondary-dark: #f0c929;
  --success: #6bcb77;
  --bully: #ff4757;
  --snitch: #5352ed;
  --president: #ffa502;
  --student: #70a1ff;
  --nerd: #70a1ff;
  --jock: #2ed573;
  --bestfriend: #ff6b81;
  --class-clown: #ff9f43;
  --class-dark: #2f3542;
  --class-dark-accent: #57606f;
  --radius: 18px;
  --shadow: 0 6px 0 var(--card-border), 0 10px 24px rgba(0, 0, 0, 0.15);
  --font: 'Nunito', system-ui, sans-serif;
  --font-button: 'Starborn', system-ui, sans-serif;
  --avatar-preview-w: 125px;
  --avatar-preview-h: 125px;
  --phase-zone-gap: 32px;
  --action-panel-gap: 16px;
  --viewport-pad: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
  transition: background-color 0.9s ease;
}

body.class-phase {
  background: var(--bg-class);
}

body:has(#screen-game.active) {
  overflow: hidden;
  height: 100vh;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(255, 217, 61, 0.35) 0, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(255, 107, 107, 0.25) 0, transparent 40%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 20px,
      rgba(255, 255, 255, 0.08) 20px,
      rgba(255, 255, 255, 0.08) 40px
    );
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.9s ease, filter 0.9s ease;
}

body.class-phase .bg-pattern {
  opacity: 0.45;
  filter: saturate(0.65) brightness(0.75);
}

#app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--viewport-pad) 16px;
}

#app:has(#screen-game.active) {
  max-width: 1360px;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

#screen-lobby.active,
#screen-waiting.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - (var(--viewport-pad) * 2));
  max-height: calc(100vh - (var(--viewport-pad) * 2));
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

#screen-lobby.active,
#screen-waiting.active {
  display: flex;
}

.hero {
  text-align: center;
  margin-bottom: 16px;
}

.game-logo {
  display: block;
  width: min(100%, 360px);
  height: auto;
  margin: 0 auto;
  image-rendering: auto;
}

.card {
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel {
  max-width: 420px;
  min-width: 420px;
  margin: 0 auto;
}

.avatar-customizer {
  margin-bottom: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.55);
  border: 2px dashed rgba(45, 45, 45, 0.18);
  border-radius: 14px;
}

.avatar-customizer-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.avatar-nav-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  height: var(--avatar-preview-h);
}

.avatar-nav {
  width: 34px;
  height: 34px;
  border: 3px solid var(--card-border);
  border-radius: 10px;
  background: #fff;
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-border);
  padding: 0;
}

.avatar-nav-color {
  background: var(--secondary);
}

.avatar-nav:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--card-border);
}

.avatar-preview-wrap {
  width: var(--avatar-preview-w);
  height: var(--avatar-preview-h);
  border: 3px solid var(--card-border);
  border-radius: 14px;
  background: #eef6ff;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  position: relative;
}

@keyframes avatar-bounce {
  0%, 100% { transform: translateY(0); }
  15% { transform: translateY(6%); }
}

.sb-avatar.bounce .eyes,
.sb-avatar.bounce .mouth {
  animation: avatar-bounce 125ms ease-in-out;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-weight: 700;
}

.field span {
  font-size: 0.9rem;
  color: var(--text-muted);
}

input[type='text'],
select {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 14px;
  border: 3px solid var(--card-border);
  border-radius: 12px;
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.25);
}

.btn {
  font-family: var(--font);
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 20px;
  border: 3px solid var(--card-border);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 4px 0 var(--card-border);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--card-border);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--secondary-dark);
}

.btn-small {
  font-size: 0.8rem;
  padding: 6px 12px;
}

.btn-large {
  width: 100%;
  font-size: 1.2rem;
  padding: 16px;
  margin-top: 12px;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn {
  flex: 1;
}

#btn-create,
#btn-join {
  font-family: var(--font-button);
  font-weight: normal;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-secondary.loading::after {
  border-color: rgba(45, 45, 45, 0.2);
  border-top-color: var(--text);
}

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

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: rgba(45, 45, 45, 0.15);
  border-radius: 2px;
}

.error-msg {
  color: var(--bully);
  font-weight: 700;
  margin-top: 12px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.waiting-panel {
  text-align: center;
  max-width: 520px;
}

.room-code-display {
  background: var(--secondary);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.room-code-display .label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.room-code-display .code {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  display: block;
  margin-bottom: 8px;
}

.room-code-display .btn-small {
  margin-right: 6px;
  margin-top: 4px;
}

.invite-hint {
  margin-top: -4px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.status-text {
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.player-list {
  list-style: none;
  text-align: left;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 0;
  background: #fff;
  border: 2px solid var(--card-border);
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 0;
}

.player-list li.dead {
  opacity: 0.45;
  text-decoration: line-through;
}

.player-list li .avatar-mini {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 2px solid var(--card-border);
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  background: #eef6ff;
  display: block;
}

.player-list li .badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 8px;
  border: 2px solid var(--card-border);
  font-weight: 800;
}

.badge-host {
  background: var(--secondary);
}

.badge-bot {
  background: #dfe6e9;
}

.badge-detention {
  background: var(--class-dark-accent);
  color: #fff;
}

.badge-dead {
  background: var(--class-dark);
  color: #fff;
}

.hint {
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 12px;
}

.host-controls {
  margin-top: 16px;
}

/* GAME SCREEN */
#screen-game.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
}

.game-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 8px;
  min-height: 44px;
  flex-shrink: 0;
}

.game-header .phase-timer {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.game-header .header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.phase-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 18px;
  box-shadow: var(--shadow);
  width: fit-content;
  max-width: 100%;
}

.phase-banner.class-phase {
  background: var(--class-dark);
  color: #fff;
  border-color: #1e272e;
}

.phase-banner.class-phase .phase-sub {
  color: rgba(255, 255, 255, 0.75);
}

.phase-icon {
  font-size: 1.75rem;
  flex-shrink: 0;
}

.phase-banner-text {
  flex: 0 1 auto;
}

.phase-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.phase-label {
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
}

.phase-sub {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.8;
  white-space: nowrap;
}

.phase-sub.hidden {
  display: none;
}

.phase-timer {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bully);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  border: 3px solid var(--card-border);
  font-weight: 900;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.phase-timer.phase-timer-idle {
  visibility: hidden;
}

.phase-timer.urgent {
  animation: timer-pulse 0.8s ease-in-out infinite;
}

@keyframes timer-pulse {
  50% { transform: scale(1.05); opacity: 0.85; }
}

.phase-timer-value {
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.room-tag {
  font-weight: 700;
  background: rgba(255, 255, 255, 0.5);
  padding: 8px 14px;
  border-radius: 12px;
  border: 2px solid rgba(45, 45, 45, 0.15);
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.connection-status {
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  border: 2px solid var(--card-border);
  background: #fff;
}

.connection-status.connected {
  color: var(--success);
}

.connection-status.disconnected {
  color: var(--bully);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.6; }
}

.audio-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 120;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 190px;
  box-shadow: 0 4px 16px rgba(45, 45, 45, 0.12);
}

.audio-volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.audio-volume-row + .audio-volume-row {
  margin-top: 8px;
}

.audio-volume-row label {
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 44px;
  color: var(--text);
}

.audio-volume-row input[type='range'] {
  flex: 1;
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.game-body {
  display: grid;
  grid-template-columns: minmax(450px, 510px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.left-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  max-height: 100%;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background-color 0.9s ease, border-color 0.9s ease;
}

body.class-phase .left-sidebar {
  background: #eef3f8;
  border-color: #1e272e;
}

body.class-phase .main-column .player-grid-area {
  background: rgba(238, 243, 248, 0.92);
  border-color: #1e272e;
}

.role-icon-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px;
  border-bottom: 2px solid rgba(45, 45, 45, 0.1);
  flex-shrink: 0;
  background: #f5f5f0;
}

.role-ref {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.role-ref:hover {
  background: rgba(255, 255, 255, 0.55);
}

.role-ref:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.role-ref-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  overflow: hidden;
  background: transparent;
  box-sizing: border-box;
}

.role-ref-icon:has(img) {
  border: none;
  padding: 0;
}

.role-ref-icon img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.role-ref-placeholder {
  background: var(--student);
}

.bully-role .role-ref-placeholder { background: var(--bully); color: #fff; }
.snitch-role .role-ref-placeholder { background: var(--snitch); color: #fff; }
.president-role .role-ref-placeholder { background: var(--president); color: #fff; }
.nerd-role .role-ref-placeholder { background: var(--nerd); color: #fff; }
.jock-role .role-ref-placeholder { background: var(--jock); color: #fff; }
.bestfriend-role .role-ref-placeholder { background: var(--bestfriend); color: #fff; }
.class-clown-role .role-ref-placeholder { background: var(--class-clown); color: #fff; }

.role-ref-label {
  font-size: 0.5rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: -0.02em;
}

.role-ref.role-ref-active {
  border-color: #e74c3c;
  box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.45);
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 8px 14px;
  overflow: hidden;
}

.action-hint {
  color: var(--text-muted);
  line-height: 1.35;
  margin: 0;
}

.chat-feed {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  max-height: 100%;
  padding: 4px 6px;
  background: #fff;
  border: 2px solid rgba(45, 45, 45, 0.12);
  border-radius: 10px;
  margin-bottom: 8px;
  overscroll-behavior: contain;
}

.chat-line {
  padding: 4px 0;
  font-size: 0.82rem;
  line-height: 1.35;
  word-break: break-word;
}

.chat-system {
  color: #d633c7;
  font-weight: 700;
}

.chat-player .chat-name {
  font-weight: 800;
}

.chat-player.chat-me .chat-name {
  color: #e74c3c;
}

.chat-empty {
  color: var(--text-muted);
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: stretch;
  padding-bottom: 2px;
}

.chat-form.hidden {
  display: none;
}

.chat-form input {
  flex: 1;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 10px;
  border: 2px solid var(--card-border);
  border-radius: 10px;
  min-width: 0;
}

.btn-chat-send {
  padding: 8px 14px;
  min-width: 44px;
  flex-shrink: 0;
  align-self: center;
}

.main-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  min-width: 0;
  flex: 1;
}

.player-grid-area {
  flex: 1;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow: auto;
  transition: background-color 0.9s ease, border-color 0.9s ease;
  position: relative;
}

.player-section-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 0;
}

.player-section-middle {
  flex: 1;
  position: relative;
  width: 100%;
  min-height: 0;
}

.player-section-middle .player-grid {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 680px;
  margin: 0;
}

.phase-header-zone {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 20px 0 0;
  position: relative;
  z-index: 2;
}

.phase-description {
  position: absolute;
  left: 50%;
  top: 25%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.35;
  max-width: 420px;
  width: max-content;
  z-index: 1;
  pointer-events: none;
}

.player-grid-area .phase-banner {
  margin: 0;
  flex-shrink: 0;
}

.player-grid-area .game-action-panel {
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  margin-top: auto;
  padding-top: var(--action-panel-gap);
  border-top: 2px solid rgba(45, 45, 45, 0.12);
}

.player-grid-area.anim-bullied-section::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) - 3px);
  pointer-events: none;
  z-index: 24;
  box-shadow:
    inset 0 0 0 5px rgba(255, 71, 87, 0.95),
    0 0 24px rgba(255, 71, 87, 0.45);
  opacity: 0;
  animation: bully-death-flash 1.4s ease-out 1 forwards;
}

.player-section-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.player-section-row .player-grid-area {
  flex: 1 1 auto;
  min-width: 0;
}

.student-team-progress.nerd-tube {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  pointer-events: none;
  padding: 4px 0;
}

.nerd-tube-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.nerd-tube {
  position: relative;
  width: min(100px, 12vw);
  height: min(430px, calc(100vh - 200px));
  aspect-ratio: 164 / 700;
}

.nerd-tube-fill-zone {
  position: absolute;
  top: 7.5%;
  left: 18%;
  right: 18%;
  bottom: 5.5%;
  z-index: 1;
  overflow: hidden;
  clip-path: polygon(26% 0, 74% 0, 100% 100%, 0 100%);
}

.nerd-tube-liquid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background:
    linear-gradient(
      180deg,
      rgba(130, 225, 255, 0.98) 0%,
      rgba(75, 185, 245, 0.98) 35%,
      rgba(35, 140, 215, 1) 100%
    );
  transition: height 0.55s cubic-bezier(0.34, 1.2, 0.48, 1);
  box-shadow:
    inset 0 2px 8px rgba(255, 255, 255, 0.45),
    inset 0 -4px 10px rgba(0, 60, 120, 0.25);
}

.nerd-tube-liquid::before {
  content: '';
  position: absolute;
  left: -15%;
  right: -15%;
  top: -5px;
  height: 10px;
  background: rgba(160, 235, 255, 0.92);
  border-radius: 50%;
  animation: nerd-tube-wave 2.2s ease-in-out infinite;
}

.nerd-tube-liquid::after {
  content: '';
  position: absolute;
  top: 15%;
  left: 12%;
  width: 22%;
  height: 60%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
  pointer-events: none;
}

.nerd-tube-liquid.is-full {
  background:
    linear-gradient(
      180deg,
      rgba(255, 235, 120, 0.98) 0%,
      rgba(255, 217, 61, 0.98) 45%,
      rgba(230, 170, 35, 1) 100%
    );
}

.nerd-tube-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

.nerd-tube-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #2d2d2d;
  z-index: 3;
  pointer-events: none;
  text-shadow:
    0 0 4px rgba(255, 255, 255, 0.85),
    0 1px 0 rgba(255, 255, 255, 0.65);
}

.nerd-tube-count {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 900;
  color: var(--text);
  text-align: center;
}

@keyframes nerd-tube-wave {
  0%,
  100% {
    transform: translateY(0) scaleX(1);
  }
  50% {
    transform: translateY(-2px) scaleX(0.94);
  }
}

.game-action-panel {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

.player-grid {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 680px;
  justify-items: center;
  align-content: start;
}

.player-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.player-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.player-card {
  background: linear-gradient(180deg, #e8f4fc 0%, #d4ebf9 100%);
  border: 3px solid var(--card-border);
  border-radius: 14px;
  padding: 6px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 132px;
  position: relative;
  font-family: var(--font);
  text-align: center;
  cursor: default;
  transition: transform 0.1s, box-shadow 0.1s;
}

.player-card.clickable {
  cursor: pointer;
}

.player-card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 var(--card-border);
}

.player-grid.targeting-mode .player-card.targetable {
  cursor: crosshair;
}

.player-grid.targeting-mode .player-card:not(.targetable) {
  opacity: 0.55;
  cursor: default;
}

.player-card-target-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 72px;
  height: 72px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  z-index: 8;
}

.player-card-target-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.player-grid.targeting-mode .player-card.targetable:hover .player-card-target-indicator {
  opacity: 1;
}

.player-card-action-mark {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card-border);
  line-height: 1;
}

.player-card-action-mark-bad {
  min-width: 22px;
  padding: 0 5px;
  background: var(--bully);
  color: #fff;
}

.player-card-action-mark-good {
  background: var(--jock);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 900;
}

.ability-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 20px;
  justify-content: center;
  width: 100%;
  max-width: 520px;
  margin-bottom: 4px;
}

.ability-actions.hidden {
  display: none;
}

.ability-action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 132px;
}

.ability-action-hint {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.25;
}

.ability-action-btn {
  position: relative;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 2px solid var(--card-border);
  border-radius: 50%;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}

.ability-action-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.ability-action-emoji {
  font-size: 1.25rem;
  line-height: 1;
  pointer-events: none;
}

.ability-action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 0 var(--card-border);
}

.ability-action-btn.is-active {
  background: var(--secondary);
  box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.55);
}

.ability-action-btn.has-target:not(.is-active)::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--card-border);
}

.ability-action-btn.has-target:not(.is-active) {
  border-color: var(--success);
}

.player-card.clickable:active {
  transform: translateY(1px);
}

.player-card:disabled {
  cursor: default;
}

.player-card-vote-ballot {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card-border);
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.player-card.is-me .player-card-name {
  color: #2d9d4a;
}

.player-card.is-bully-teammate {
  border-color: #e74c3c;
  box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.35);
}

.player-card.is-bully-teammate .player-card-name {
  color: #e74c3c;
}

.player-card.is-me {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(107, 203, 119, 0.5);
}

.player-card.is-me.is-bully-self {
  border-color: #e74c3c;
  box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.35);
}

.player-card.is-me.is-bully-self .player-card-name {
  color: #e74c3c;
}

.player-card.is-me.is-solo-self {
  border-color: var(--snitch);
  box-shadow: 0 0 0 2px rgba(83, 82, 237, 0.45);
}

.player-card.is-me.is-solo-self .player-card-name {
  color: var(--snitch);
}

.player-card.dead,
.player-card.dead-bullied,
.player-card.dead-expelled {
  opacity: 0.55;
}

.player-card.dead .player-card-name,
.player-card.dead-bullied .player-card-name,
.player-card.dead-expelled .player-card-name {
  text-decoration: line-through;
}

.player-card.in-detention {
  border-color: var(--class-dark-accent);
  box-shadow: 0 0 0 2px rgba(87, 96, 111, 0.45);
}

.player-card.in-detention .player-card-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: repeating-linear-gradient(
    135deg,
    transparent 0,
    transparent 5px,
    rgba(47, 53, 66, 0.42) 5px,
    rgba(47, 53, 66, 0.42) 9px
  );
  pointer-events: none;
  z-index: 2;
}

.player-card.in-detention .player-card-avatar {
  filter: saturate(0.65) brightness(0.92);
}

.player-card-fx {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.player-card-bullied-overlay {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  width: 120%;
  height: calc(100% - 38px);
  z-index: 7;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 1;
}

.player-card-bullied-frame {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom center;
}

.player-card-bullied-overlay.is-fading {
  animation: bully-frame-fade-out 0.4s ease-out forwards;
}

@keyframes bully-frame-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.player-card.anim-death-bullied {
  z-index: 6;
}

.player-card.anim-death-bullied .player-card-fx {
  background: radial-gradient(circle at 50% 45%, rgba(255, 71, 87, 0.8) 0%, transparent 55%);
  animation: bully-death-flash 1.4s ease-out 1 forwards;
}

.player-card.anim-death-bullied .player-card-fx::before {
  content: '👊';
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) scale(0);
  font-size: 2rem;
  animation: bully-death-fist 1.4s ease-out 1 forwards;
}

.player-card.anim-death-bullied .player-card-avatar {
  animation: bully-death-avatar 1.4s ease-in-out 1 forwards;
}

.player-card.anim-death-expelled {
  z-index: 6;
}

.player-card.anim-death-expelled .player-card-fx {
  background: rgba(47, 53, 66, 0);
  animation: expel-stamp 2.2s ease-out 1 forwards;
}

.player-card.anim-death-expelled .player-card-fx::after {
  content: 'EXPELLED';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(2.2) rotate(-12deg);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--bully);
  border: 3px solid var(--card-border);
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  animation: expel-stamp-text 2.2s ease-out 1 forwards;
}

.player-card.anim-death-expelled .player-card-avatar {
  animation: expel-grayscale 2.2s ease 1 forwards;
}

.player-card-detention-overlay {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  pointer-events: none;
  z-index: 6;
  overflow: hidden;
}

.player-card-detention-bars {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0,
    transparent 6px,
    rgba(47, 53, 66, 0.55) 6px,
    rgba(47, 53, 66, 0.55) 10px
  );
  transform-origin: center center;
  opacity: 0;
  transform: scaleY(0.2);
}

.player-card-detention-overlay.is-playing .player-card-detention-bars {
  animation: detention-bars-once 1.2s ease-out 1 forwards;
}

.player-card-detention-overlay.is-complete .player-card-detention-bars {
  opacity: 1;
  transform: scaleY(1);
}

@keyframes bully-death-flash {
  0%,
  32%,
  100% {
    opacity: 0;
  }
  8%,
  24% {
    opacity: 1;
  }
  16% {
    opacity: 0;
  }
}

@keyframes bully-death-fist {
  0%,
  38% {
    transform: translateX(-50%) scale(0);
    opacity: 0;
  }
  48% {
    transform: translateX(-50%) scale(1.35);
    opacity: 1;
  }
  62%,
  100% {
    transform: translateX(-50%) scale(0.85);
    opacity: 0;
  }
}

@keyframes bully-death-avatar {
  0%,
  18%,
  100% {
    transform: scale(1) rotate(0);
  }
  35% {
    transform: scale(0.82) rotate(-6deg);
  }
  55% {
    transform: scale(1.06) rotate(0);
  }
  72% {
    transform: scale(1) rotate(0);
  }
}

@keyframes expel-stamp {
  0%,
  45% {
    background: rgba(47, 53, 66, 0);
  }
  60% {
    background: rgba(47, 53, 66, 0.12);
  }
  100% {
    background: rgba(47, 53, 66, 0);
  }
}

@keyframes expel-stamp-text {
  0%,
  22% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.2) rotate(-12deg);
  }
  38% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-12deg);
  }
  62% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-12deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1) rotate(-12deg);
  }
}

@keyframes expel-grayscale {
  0% {
    filter: none;
  }
  100% {
    filter: grayscale(0.9);
  }
}

@keyframes detention-bars-once {
  0% {
    opacity: 0;
    transform: scaleY(0.2);
  }
  100% {
    opacity: 1;
    transform: scaleY(1);
  }
}

.player-card-name {
  font-weight: 800;
  font-size: 0.78rem;
  text-align: center;
  word-break: break-word;
  width: 100%;
  padding: 3px 6px;
  background: rgba(45, 45, 45, 0.12);
  border-radius: 8px;
}

.player-card-avatar {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 3px solid var(--card-border);
  position: relative;
  overflow: hidden;
  background: #fff;
  flex-shrink: 0;
}

.sb-avatar {
  pointer-events: none;
  user-select: none;
  position: relative;
  width: 100%;
  height: 100%;
}

.sb-avatar.fit {
  width: 100%;
  height: 100%;
}

.sb-avatar .color,
.sb-avatar .eyes,
.sb-avatar .mouth {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  image-rendering: auto;
}

.avatar-mini {
  position: relative;
}

.avatar-mini .sb-avatar,
.avatar-preview-wrap .sb-avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.sb-avatar .color {
  background-image: url('/img/avatar/color_atlas.gif');
}

.sb-avatar .eyes {
  background-image: url('/img/avatar/eyes_atlas.gif');
}

.sb-avatar .mouth {
  background-image: url('/img/avatar/mouth_atlas.gif');
}

.player-card-avatar.avatar-dead {
  opacity: 0.45;
  filter: grayscale(0.85);
}

.player-card-avatar.avatar-reveal-bully {
  box-shadow: 0 0 0 3px var(--bully);
}

.player-card-avatar.avatar-reveal-snitch {
  box-shadow: 0 0 0 3px var(--snitch);
}

.player-card-avatar.avatar-reveal-president {
  box-shadow: 0 0 0 3px var(--president);
}

.avatar-role-badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--card-border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  line-height: 1;
  z-index: 2;
  overflow: hidden;
}

.avatar-role-badge-img {
  width: 14px;
  height: 14px;
  object-fit: contain;
  display: block;
}

.btn-leave-room {
  margin-top: 12px;
  width: 100%;
}

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

  .left-sidebar {
    max-height: 220px;
  }

  .game-header .phase-timer {
    position: static;
    transform: none;
    margin: 0 auto;
  }

  .game-header {
    flex-direction: column;
    align-items: stretch;
  }

  .player-grid.cols-3,
  .player-grid.cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .player-section-row {
    flex-direction: column;
    align-items: stretch;
  }

  .student-team-progress.nerd-tube {
    align-self: center;
    padding: 8px 0 0;
  }

  .nerd-tube {
    width: 64px;
    height: min(240px, 32vh);
  }
}

@media (max-width: 480px) {
  .role-icon-bar {
    grid-template-columns: repeat(4, 1fr);
  }

  .player-card {
    max-width: none;
  }
}

.snitch-private {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #e8e6ff;
  border: 2px solid var(--snitch);
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.85rem;
}

.player-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.player-card-badges .badge {
  font-size: 0.6rem;
  padding: 2px 6px;
  border-radius: 6px;
  border: 2px solid var(--card-border);
  font-weight: 800;
}

.player-card-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
}

@keyframes game-results-pop {
  from {
    opacity: 0;
    transform: scale(0.88);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.game-results-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(30, 39, 46, 0.65);
  border-radius: calc(var(--radius) - 3px);
}

.game-results-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  width: min(100%, 520px);
  flex-shrink: 0;
}

.game-results-stack.has-drawings {
  max-height: 100%;
}

.game-results-panel {
  width: 100%;
  max-height: none;
  flex-shrink: 0;
  overflow: visible;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 0 var(--card-border), 0 18px 40px rgba(0, 0, 0, 0.18);
  padding: 20px;
  text-align: center;
  animation: game-results-pop 0.22s ease-out;
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .game-results-overlay {
    background: rgba(30, 39, 46, 0.42);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
  }
}

.game-results-panel.bullies-win .game-results-title {
  color: var(--bully);
}

.game-results-panel.students-win .game-results-title {
  color: var(--success);
}

.game-results-panel.clown-win .game-results-title {
  color: var(--class-clown);
}

.game-results-title {
  font-size: 1.85rem;
  font-weight: 900;
  margin-bottom: 8px;
  line-height: 1.15;
}

.game-results-subtitle {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.game-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.game-results-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 14px;
}

.game-results-player.is-me .game-results-name {
  color: #e74c3c;
}

.game-results-player.is-loser .game-results-avatar {
  opacity: 0.45;
  filter: grayscale(0.85);
}

.game-results-player.is-loser .game-results-name,
.game-results-player.is-loser .game-results-role {
  opacity: 0.55;
  color: var(--text-muted);
}

.game-results-avatar {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 3px solid var(--card-border);
  position: relative;
  overflow: hidden;
  background: #fff;
  flex-shrink: 0;
}

.game-results-avatar.avatar-dead {
  opacity: 0.55;
}

.game-results-avatar.avatar-reveal-bully {
  box-shadow: 0 0 0 3px var(--bully);
}

.game-results-avatar.avatar-reveal-snitch {
  box-shadow: 0 0 0 3px var(--snitch);
}

.game-results-avatar.avatar-reveal-president {
  box-shadow: 0 0 0 3px var(--president);
}

.game-results-player.is-winner .game-results-avatar {
  box-shadow: 0 0 0 3px rgba(107, 203, 119, 0.65);
}

.game-results-panel.bullies-win .game-results-player.is-winner .game-results-avatar {
  box-shadow: 0 0 0 3px rgba(255, 71, 87, 0.65);
}

.game-results-name {
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.15;
  word-break: break-word;
  max-width: 100%;
}

.game-results-role {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.1;
}

.game-drawings-gallery {
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
}

.game-drawings-heading {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 900;
  text-align: center;
  color: #fffef7;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.game-drawings-viewer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-drawings-nav {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 3px solid var(--card-border);
  border-radius: 10px;
  background: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--card-border);
}

.game-drawings-nav:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--card-border);
}

.game-drawings-frame {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border-radius: 16px;
}

.game-drawings-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: contain;
  background: #fff;
  border-radius: 16px;
}

.game-drawings-avatar {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  border: 2px solid var(--card-border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.game-drawings-artist {
  margin: 0;
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.95);
}

.game-drawings-counter {
  margin: 8px 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  color: rgba(255, 254, 247, 0.9);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

#game-drawings-download {
  display: block;
  margin: 0 auto;
}

.game-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.game-results-actions .btn {
  min-width: 140px;
}

.game-results-actions .btn-large {
  width: auto;
  margin-top: 0;
}

.player-grid-area.is-ended {
  overflow: hidden;
  min-height: min(62vh, 520px);
}

.player-grid-area.is-ended .player-section-body,
.player-grid-area.is-ended .game-action-panel {
  display: none;
}

.free-period-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
  max-width: 420px;
}

.free-period-actions.hidden {
  display: none;
}

.action-status {
  margin-top: 8px;
  font-weight: 700;
  color: var(--success);
  font-size: 0.85rem;
}

.action-status.error {
  color: var(--bully);
}

.avatar-mini.bully-bg { background: var(--bully); color: #fff; }
.avatar-mini.snitch-bg { background: var(--snitch); color: #fff; }
.avatar-mini.president-bg { background: var(--president); color: #fff; }
.avatar-mini.student-bg { background: var(--student); color: #fff; }
.avatar-mini.dead-bg { background: var(--class-dark); color: #fff; }

.player-card-avatar.bully-bg { background: var(--bully); color: #fff; }
.player-card-avatar.snitch-bg { background: var(--snitch); color: #fff; }
.player-card-avatar.president-bg { background: var(--president); color: #fff; }
.player-card-avatar.student-bg { background: var(--student); color: #fff; }
.player-card-avatar.dead-bg { background: var(--class-dark); color: #fff; }

.avatar-placeholder {
  width: 80px;
  height: 80px;
  margin: 0 auto 8px;
  border-radius: 16px;
  border: 3px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.25rem;
  line-height: 1;
}

.bully-role .avatar-placeholder {
  background: var(--bully);
  color: #fff;
}

.snitch-role .avatar-placeholder {
  background: var(--snitch);
  color: #fff;
}

.president-role .avatar-placeholder {
  background: var(--president);
  color: #fff;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(47, 53, 66, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.role-reveal-avatar {
  width: 100px;
  height: 100px;
  margin: 16px auto;
}

.role-reveal-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.role-reveal-name {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 10px;
}

.role-reveal-desc {
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.student-task-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(30, 39, 46, 0.55);
  border-radius: calc(var(--radius) - 3px);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .student-task-overlay {
    background: rgba(30, 39, 46, 0.4);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
}

.student-task-panel {
  width: min(92vw, 460px);
  border: 3px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 8px 0 var(--card-border), 0 14px 28px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.student-task-panel.is-success {
  border-color: var(--success);
  box-shadow:
    0 0 0 3px rgba(107, 203, 119, 0.55),
    0 0 28px rgba(107, 203, 119, 0.65),
    0 8px 0 #4fa85b,
    0 14px 32px rgba(107, 203, 119, 0.35);
  animation: student-task-success-pulse 0.9s ease-out;
}

@keyframes student-task-success-pulse {
  0% {
    box-shadow:
      0 8px 0 var(--card-border),
      0 14px 28px rgba(0, 0, 0, 0.12);
  }
  35% {
    box-shadow:
      0 0 0 4px rgba(107, 203, 119, 0.7),
      0 0 36px rgba(107, 203, 119, 0.8),
      0 8px 0 #4fa85b,
      0 14px 36px rgba(107, 203, 119, 0.45);
  }
  100% {
    box-shadow:
      0 0 0 3px rgba(107, 203, 119, 0.55),
      0 0 28px rgba(107, 203, 119, 0.65),
      0 8px 0 #4fa85b,
      0 14px 32px rgba(107, 203, 119, 0.35);
  }
}

.student-task-playfield {
  position: relative;
  width: 100%;
  height: 260px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.student-task-playfield::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('/img/minigames/sharpen-pencil/bg.png') center / cover no-repeat;
  filter: blur(3px);
  transform: scale(1.04);
  z-index: 0;
  pointer-events: none;
}

.student-task-sharpener {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 100px;
  height: 140px;
  z-index: 3;
  transform-origin: center center;
}

.student-task-sharpener.is-shaking {
  animation: student-sharpener-shake 0.1s infinite;
}

@keyframes student-sharpener-shake {
  0%,
  100% {
    transform: translateY(-50%) translateX(0) rotate(0deg);
  }
  25% {
    transform: translateY(calc(-50% - 2px)) translateX(-3px) rotate(-2deg);
  }
  75% {
    transform: translateY(calc(-50% + 2px)) translateX(3px) rotate(2deg);
  }
}

.student-task-sharpener-mouth {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  height: 46px;
  z-index: 4;
  pointer-events: none;
}

.student-task-sharpener-img,
.student-task-pencil img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(3px 0 0 #000)
    drop-shadow(-3px 0 0 #000)
    drop-shadow(0 3px 0 #000)
    drop-shadow(0 -3px 0 #000)
    drop-shadow(0 6px 0 var(--card-border))
    drop-shadow(0 10px 24px rgba(0, 0, 0, 0.15));
}

.student-task-pencil {
  position: absolute;
  left: 0;
  top: 0;
  width: 220px;
  height: 28px;
  z-index: 1;
  cursor: grab;
  will-change: transform;
}

.student-task-pencil.is-animated {
  transition: transform 0.35s ease;
}

.student-task-pencil.is-entering {
  transition: none !important;
  animation: student-pencil-enter 0.55s ease-out forwards;
}

.student-task-pencil.is-dropping {
  pointer-events: none;
  transition: none !important;
  animation: student-pencil-drop 0.65s ease-in forwards;
}

.student-task-pencil.is-sharp.is-dropping {
  z-index: 4;
}

@keyframes student-pencil-enter {
  from {
    transform: translate(var(--enter-x, 0), var(--enter-y, 0));
  }
  to {
    transform: translate(var(--rest-x, 0), var(--rest-y, 0));
  }
}

@keyframes student-pencil-drop {
  from {
    transform: translate(var(--drop-x, 0), var(--drop-y, 0));
    opacity: 1;
  }
  to {
    transform: translate(var(--drop-x, 0), calc(var(--drop-y, 0) + 200px)) rotate(14deg);
    opacity: 0;
  }
}

.student-task-pencil.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.student-task-pencil.is-dragging {
  cursor: grabbing;
}

.student-task-pencil.is-sharp {
  z-index: 4;
}

.student-minigame-pane.hidden {
  display: none;
}

#student-minigame-draw {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.student-task-panel:has(#student-minigame-draw:not(.hidden)) {
  overflow: visible;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.student-task-panel:has(#student-minigame-math:not(.hidden)) {
  overflow: visible;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

#student-minigame-math {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.student-math-playfield {
  display: flex;
  flex-direction: column;
}

.student-math-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 44px 14px 14px;
}

.student-math-progress {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-muted);
}

.student-math-question {
  margin: 0;
  font-size: 2rem;
  font-weight: 900;
  color: var(--text);
  letter-spacing: 0.02em;
}

.student-math-feedback {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-green, #2ecc71);
}

.student-math-feedback.is-error {
  color: #e74c3c;
}

.student-math-keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 280px);
}

.student-math-key {
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 900;
  padding: 10px 0;
  border: 2px solid var(--card-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-border);
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.student-math-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--card-border);
}

.student-math-key:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.student-task-panel:has(#student-minigame-frog:not(.hidden)) {
  overflow: visible;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

#student-minigame-frog {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.student-frog-playfield {
  position: relative;
  width: 100%;
  height: 260px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  border: 3px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 8px 0 var(--card-border), 0 14px 28px rgba(0, 0, 0, 0.12);
  background: url('/img/minigames/frog/bg.png') center / cover no-repeat;
}

.student-frog-dish-zone {
  position: absolute;
  left: 14px;
  top: 54%;
  transform: translateY(-50%);
  width: 88px;
  z-index: 2;
}

.student-frog-dish-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(3px 0 0 #000)
    drop-shadow(-3px 0 0 #000)
    drop-shadow(0 3px 0 #000)
    drop-shadow(0 -3px 0 #000)
    drop-shadow(0 6px 0 var(--card-border))
    drop-shadow(0 10px 24px rgba(0, 0, 0, 0.15));
}

.student-frog-dish-part {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 52%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.student-frog-dish-part img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.student-frog-dish-part[data-part='heart'] {
  top: 34%;
  width: 38%;
}

.student-frog-dish-part[data-part='belly'] {
  top: 50%;
  width: 44%;
}

.student-frog-dish-part[data-part='liver'] {
  top: 66%;
  width: 40%;
}

.student-frog-stack {
  position: absolute;
  right: 16px;
  top: 54%;
  transform: translateY(-50%);
  width: 118px;
  height: 209px;
  z-index: 1;
  transition: transform 0.08s ease;
}

.student-frog-stack.is-shocked {
  animation: student-frog-shock 0.55s ease-in-out;
}

.student-frog-base,
.student-frog-part img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.student-frog-part {
  position: absolute;
  right: 16px;
  top: 54%;
  width: 118px;
  height: 209px;
  transform: translateY(-50%);
  z-index: 3;
  touch-action: none;
  pointer-events: none;
}

.student-frog-part.is-hovered {
  z-index: 6;
}

.student-frog-part.is-dragging {
  z-index: 12;
  pointer-events: none;
}

.student-frog-part.is-snapping {
  transition: left 0.24s ease-out, top 0.24s ease-out;
}

.student-frog-part.is-secured.hidden {
  display: none;
}

.student-frog-shock-flash {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: rgba(255, 45, 45, 0.35);
  animation: student-frog-flash 0.55s ease-out;
}

.student-frog-slow-warning {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 25;
  transform: translateX(-50%);
  margin: 0;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ff2d2d;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  pointer-events: none;
  animation: student-frog-slow-blink 0.45s step-end infinite;
}

@keyframes student-frog-slow-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.15;
  }
}

@keyframes student-frog-shock {
  0%,
  100% {
    transform: translateY(-50%) translateX(0);
  }
  15% {
    transform: translateY(calc(-50% - 3px)) translateX(-6px);
  }
  30% {
    transform: translateY(calc(-50% + 2px)) translateX(7px);
  }
  45% {
    transform: translateY(calc(-50% - 2px)) translateX(-5px);
  }
  60% {
    transform: translateY(calc(-50% + 3px)) translateX(4px);
  }
  75% {
    transform: translateY(calc(-50% - 1px)) translateX(-3px);
  }
}

@keyframes student-frog-flash {
  0% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
  }
}

.student-draw-title {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  z-index: 2;
  margin: 0;
  padding: 0 12px;
  text-align: center;
  font-size: clamp(0.72rem, 2.8vw, 1rem);
  font-weight: 900;
  line-height: 1.15;
  color: var(--text-muted);
  pointer-events: none;
}

.student-draw-title.is-long {
  font-size: clamp(0.62rem, 2.2vw, 0.82rem);
  line-height: 1.2;
  top: 8px;
}

.student-draw-playfield {
  position: relative;
  width: 100%;
  height: 260px;
  touch-action: none;
  user-select: none;
  overflow: hidden;
  border: 3px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 8px 0 var(--card-border), 0 14px 28px rgba(0, 0, 0, 0.12);
  background: url('/img/minigames/draw-monster/bg.png') center / cover no-repeat;
}

#student-draw-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#student-draw-canvas.is-eraser {
  cursor: cell;
}

.student-draw-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.student-draw-tool-btn {
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 6px 10px;
  border: 3px solid var(--card-border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 4px 0 var(--card-border);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s ease;
}

#student-draw-eraser {
  background: #fff;
}

#student-draw-eraser.is-active {
  background: #f5a8bc;
}

.student-draw-tool-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--card-border);
}

.student-draw-tool-btn.is-active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--card-border);
}

.student-draw-tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.student-task-panel.is-task-done {
  border-color: var(--success);
  box-shadow:
    0 0 0 2px rgba(107, 203, 119, 0.45),
    0 8px 0 #4fa85b,
    0 14px 28px rgba(107, 203, 119, 0.25);
}

.student-task-panel.is-task-done:has(#student-minigame-draw:not(.hidden)) {
  border-color: transparent;
  box-shadow: none;
}

.student-task-panel.is-task-done:has(#student-minigame-draw:not(.hidden)) .student-draw-playfield {
  border-color: var(--success);
  box-shadow:
    0 0 0 2px rgba(107, 203, 119, 0.45),
    0 8px 0 #4fa85b,
    0 14px 28px rgba(107, 203, 119, 0.25);
}

.dev-mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.dev-mode-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.debug-panel {
  position: fixed;
  right: 16px;
  bottom: 64px;
  z-index: 1000;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: auto;
}

.debug-panel-shell {
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  overflow: hidden;
}

.debug-panel-toggle {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 14px;
  border: 2px solid var(--card-border);
  border-radius: 12px;
  background: #fff3cd;
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
}

.debug-panel-body {
  margin-top: 8px;
  padding: 4px 2px 2px;
  background: transparent;
  border: none;
  box-shadow: none;
  max-height: min(60vh, 460px);
  overflow: auto;
}

.debug-status {
  min-height: 2em;
  margin-bottom: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.25;
  border-radius: 10px;
  border: 2px solid transparent;
}

.debug-status.ok {
  color: #1e6b2e;
  background: #e8f9eb;
  border-color: rgba(107, 203, 119, 0.55);
}

.debug-status.error {
  color: var(--bully);
  background: #fff0f1;
  border-color: rgba(255, 71, 87, 0.45);
}

.debug-section + .debug-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed rgba(45, 45, 45, 0.12);
}

.debug-heading {
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.debug-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.debug-btn-row .btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.72rem;
}

.debug-full-width {
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 0.72rem;
}

.debug-jump-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.debug-select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 2px solid var(--card-border);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 700;
  background: #fff;
}

.audio-panel {
  display: none;
}

.settings-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 130;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 10px 14px;
  border: 3px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.settings-panel {
  position: fixed;
  bottom: 64px;
  right: 16px;
  z-index: 130;
  width: min(92vw, 240px);
  padding: 14px;
  border: 3px solid var(--card-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.settings-panel.hidden {
  display: none;
}

.settings-heading {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 900;
}

.lobby-layout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

.lobby-panel {
  margin: 0;
  flex: 0 1 420px;
}

.lobby-howto {
  flex: 0 1 340px;
  min-width: 280px;
  max-width: 380px;
  margin: 0;
}

.lobby-howto-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  font-weight: 900;
  text-align: center;
}

.howto-carousel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.howto-slide {
  display: block;
  width: 100%;
  height: auto;
  min-height: 180px;
  object-fit: contain;
  border-radius: 12px;
  border: 2px solid rgba(45, 45, 45, 0.12);
  background: #fff;
}

.howto-dots {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  min-height: 18px;
  margin-top: 4px;
  padding: 4px 0;
}

.howto-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(45, 45, 45, 0.35);
  background: #c8c8c8;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.2s ease;
}

.howto-dot:hover {
  background: #a8a8a8;
}

.howto-dot.is-active {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.15);
}

#screen-lobby.lobby-join-only #lobby-host-section {
  display: none;
}

.chat-channel-label {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.chat-channel-label.hidden {
  display: none;
}

.chat-player.chat-dead .chat-name {
  color: var(--class-dark-accent);
}

.chat-player.chat-bullies .chat-name {
  color: var(--bully);
}
