/* ===== Cartoon Suspect Theme ===== */

:root {
  --color-bg:          #eef4fb;
  --color-surface:     #ffffff;
  --color-primary:     #1e3a5f;
  --color-accent:      #f97316;
  --color-accent-hover:#ea6a0e;
  --color-highlight:   #facc15;
  --color-danger:      #ef4444;
  --color-danger-dark: #dc2626;
  --color-text:        #1e293b;
  --color-text-muted:  #64748b;
  --color-border:      #1e3a5f;
  --color-border-light:#cbd5e1;
  --shadow-offset:     3px 3px 0;
  --radius-card:       16px;
  --radius-btn:        12px;
  --radius-input:      10px;
  --bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ===== Reset & Global ===== */

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

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  max-width: 420px;
  margin: 0 auto;
  padding: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image: url('/img/bg-pattern.png');
  background-size: 500px 500px;
  background-repeat: repeat;
  min-height: 100dvh;
}

h1 {
  margin-bottom: 8px;
  font-weight: 800;
  color: var(--color-primary);
}

h2 {
  margin-bottom: 4px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
}

/* ===== Screen management ===== */

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: bounceIn 0.35s ease-out;
}

/* ===== Buttons - Base reset (all buttons) ===== */

button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  border: 2.5px solid var(--color-primary);
  background: var(--color-surface);
  color: var(--color-primary);
  border-radius: var(--radius-btn);
  margin-bottom: 8px;
  box-shadow: var(--shadow-offset) var(--color-primary);
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce);
  position: relative;
}

/* ===== Rectangular buttons - hover & active ===== */

.btn-rect:hover:not(:disabled) {
  animation: btnWiggle 0.4s ease;
}

.btn-rect:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 1px 1px 0 var(--color-primary);
}

/* ===== Rectangular buttons - Primary CTA ===== */

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-primary);
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: var(--shadow-offset) var(--color-primary);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-accent-hover);
}

.btn-primary:disabled {
  background: var(--color-border-light);
  border: 2.5px dashed var(--color-text-muted);
  color: #94a3b8;
  cursor: default;
  box-shadow: none;
  transform: none;
}

.btn-primary.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger-dark);
  box-shadow: var(--shadow-offset) var(--color-danger-dark);
}

.btn-primary.btn-danger:active:not(:disabled) {
  background: var(--color-danger-dark);
  box-shadow: 1px 1px 0 var(--color-danger-dark);
}

/* ===== Inputs ===== */

input[type="text"] {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 2.5px solid var(--color-primary);
  border-radius: var(--radius-input);
  margin-bottom: 8px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: box-shadow 0.2s ease;
}

input[type="text"]:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.3);
}

/* ===== Divider ===== */

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--color-text-muted);
  font-weight: 600;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--color-border-light);
  border-radius: 1px;
}

/* Divider with action button on the line */
.divider-with-action {
  position: relative;
  padding-right: 48px;
}

.divider-with-action .btn-round {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-accent);
}

.divider-text-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}

.divider-subtext {
  font-size: 0.8rem;
}

/* ===== Home Screen ===== */

.home-logo {
  text-align: center;
  margin-bottom: -8px;
}

.home-logo img {
  display: inline-block;
}

.home-title {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: 4px;
}

.home-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: 20px;
  font-size: 1.05rem;
}

.home-card {
  background: var(--color-surface);
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-card);
  box-shadow: 4px 4px 0 var(--color-primary);
  padding: 20px;
}

/* ===== Info button (home screen) ===== */

.btn-info-link {
  display: block;
  width: auto;
  margin: 16px auto 0;
  padding: 6px 18px;
  background: none;
  border: none;
  box-shadow: none;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: color 0.2s ease;
}

.btn-info-link:hover {
  color: var(--color-primary);
  animation: none;
}

.btn-info-link:active {
  transform: none;
  box-shadow: none;
}

/* ===== Info Modal ===== */

.info-modal {
  max-width: 340px;
  text-align: left !important;
}

.info-modal-title {
  text-align: left;
  font-size: 1.2rem;
  margin-bottom: 6px;
  color: var(--color-primary);
}

.info-modal-body > p {
  font-size: 0.9rem;
  color: var(--color-text);
  margin-bottom: 12px;
}

.info-modal-body ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  counter-reset: info-steps;
}

.info-modal-body li {
  counter-increment: info-steps;
  position: relative;
  padding: 6px 0 6px 32px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--color-text);
}

.info-modal-body li::before {
  content: counter(info-steps);
  position: absolute;
  left: 0;
  top: 6px;
  width: 22px;
  height: 22px;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.info-modal-body li + li {
  border-top: 1.5px dashed var(--color-border-light);
}

/* ===== Room Container (lobby + round) ===== */

.room-container {
  background: var(--color-surface);
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-card);
  box-shadow: 4px 4px 0 var(--color-primary);
  padding: 20px;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.room-header h1 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.room-logo {
  height: 50px;
  width: 50px;
  vertical-align: -0.15em;
  margin-right: 5px;
  margin-bottom: -13px;
}

.room-code-badge {
  display: inline-block;
  background: var(--color-highlight);
  padding: 1px 10px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1.25rem;
  border: 2px solid var(--color-primary);
  letter-spacing: 2px;
}

.leave-btn {
  color: var(--color-text-muted);
  border-color: var(--color-border-light);
  box-shadow: 2px 2px 0 var(--color-border-light);
}

.leave-btn:active {
  box-shadow: 1px 1px 0 var(--color-border-light);
}

.hidden {
  display: none !important;
}

/* ===== Player Section ===== */

.player-section {
  margin: 8px 0 0;
}

.player-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.player-section ul {
  list-style: none;
  padding: 0;
}

.player-section li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 2px solid var(--color-bg);
}

.player-section li:last-child {
  border-bottom: none;
}

.player-section li.disconnected {
  opacity: 0.4;
}

.player-section li .player-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
}

.player-section li.player-me {
  background: rgba(30, 58, 95, 0.06);
  margin: 0 -10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1.5px dashed rgba(30, 58, 95, 0.18);
}

/* ===== Player Avatar ===== */

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2.5px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
  text-transform: uppercase;
}

/* ===== Inline name edit form ===== */

.player-name-edit {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.player-name-edit input {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.95rem;
  font-family: inherit;
  border: 2.5px solid var(--color-primary);
  border-radius: var(--radius-input);
  margin: 0;
  min-width: 0;
}

.player-name-edit .btn-save-name {
  width: auto;
  padding: 6px 12px;
  font-size: 0.85rem;
  margin: 0;
  white-space: nowrap;
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 2px 2px 0 var(--color-primary);
}

.player-name-edit .btn-save-name:active {
  box-shadow: 1px 1px 0 var(--color-primary);
}

/* ===== Round buttons - base ===== */

.btn-round {
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  font-size: 1rem;
  line-height: 1;
  border-radius: 50%;
  border: 2.5px solid var(--color-primary);
  background: var(--color-surface);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--color-primary);
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce), background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Round buttons - hover & active */

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

.btn-round:active {
  transform: translateY(2px);
  box-shadow: 0px 0px 0 var(--color-primary);
}

/* Round buttons - kick variant */

.btn-round.kick-btn {
  color: var(--color-text-muted);
  border-color: var(--color-border-light);
  box-shadow: 2px 2px 0 var(--color-border-light);
}

.btn-round.kick-btn:hover {
  background: var(--color-danger);
  border-color: var(--color-danger-dark);
  color: #fff;
  box-shadow: 2px 2px 0 var(--color-danger-dark);
}

.btn-round.kick-btn:active {
  box-shadow: 0px 0px 0 var(--color-border-light);
}

li.disconnected .btn-round.kick-btn {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger-dark);
  box-shadow: 2px 2px 0 var(--color-danger-dark);
}

/* Round buttons - invite variant */

.btn-round.invite-btn {
  color: #fff;
  border-color: var(--color-primary);
  background: var(--color-accent);
  font-size: 1.3rem;
  font-weight: 800;
  box-shadow: 2px 2px 0 var(--color-primary);
}

.btn-round.invite-btn:hover {
  background: var(--color-surface);
  color: var(--color-accent);
}

.btn-round.invite-btn:active {
  background: var(--color-accent-hover);
  box-shadow: 0px 0px 0 var(--color-primary);
}

.player-you-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-left: 4px;
  font-weight: 400;
}

/* ===== Round Screen ===== */

#round-number {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: 2px;
}

/* ── 3D Card Flip: perspective wrapper ── */
#round-card-perspective {
  perspective: 800px;
  margin-bottom: 16px;
}

/* ── The card itself (rotates in 3D) ── */
#round-word-container {
  position: relative;
  transform-style: preserve-3d;
  height: 140px;
  animation: cardFlip3D 0.9s cubic-bezier(0.4, 0, 0.2, 1) 0.6s both;
}

/* ── Shared face styling ── */
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-card);
  padding: 28px 24px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Playing card inner frame on both faces */
.card-face::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1.5px solid rgba(30, 58, 95, 0.18);
  border-radius: 11px;
  pointer-events: none;
}

/* ── Back face (visible first, empty card) ── */
.card-face-back {
  border: 2.5px solid var(--color-primary);
  background:
    repeating-linear-gradient(
      45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    repeating-linear-gradient(
      -45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    var(--color-highlight);
}

/* ── Front face (revealed after flip, contains word) ── */
.card-face-front {
  transform: rotateX(180deg);
  border: 2.5px solid var(--color-primary);
  background:
    repeating-linear-gradient(
      45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    repeating-linear-gradient(
      -45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    var(--color-highlight);
}

/* ── Word text ── */
#round-word {
  font-size: 1.6rem;
  font-weight: 800;
  color: rgba(30, 58, 95, 0.78);
  position: relative;
  z-index: 1;
}

#round-word.impostor {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.3rem;
}

/* ── Impostor state: red card ── */
#round-word-container.impostor-active .card-face-back {
  background:
    repeating-linear-gradient(
      45deg, transparent, transparent 7px,
      rgba(0, 0, 0, 0.06) 7px, rgba(0, 0, 0, 0.06) 8px
    ),
    repeating-linear-gradient(
      -45deg, transparent, transparent 7px,
      rgba(0, 0, 0, 0.06) 7px, rgba(0, 0, 0, 0.06) 8px
    ),
    var(--color-danger);
  border-color: var(--color-danger-dark);
}

#round-word-container.impostor-active .card-face-back::after {
  border-color: rgba(255, 255, 255, 0.2);
}

#round-word-container.impostor-active .card-face-front {
  background:
    repeating-linear-gradient(
      45deg, transparent, transparent 7px,
      rgba(0, 0, 0, 0.06) 7px, rgba(0, 0, 0, 0.06) 8px
    ),
    repeating-linear-gradient(
      -45deg, transparent, transparent 7px,
      rgba(0, 0, 0, 0.06) 7px, rgba(0, 0, 0, 0.06) 8px
    ),
    var(--color-danger);
  border-color: var(--color-danger-dark);
  gap: 14px;
}

#round-word-container.impostor-active .card-face-front::after {
  border-color: rgba(255, 255, 255, 0.2);
}

.impostor-mask {
  width: 72px;
  height: auto;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.impostor-mask.hidden {
  display: none !important;
}

/* ── Reveal state: back face forced yellow while front stays red ── */
#round-word-container.reveal-active .card-face-back {
  background:
    repeating-linear-gradient(
      45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    repeating-linear-gradient(
      -45deg, transparent, transparent 7px,
      rgba(30, 58, 95, 0.05) 7px, rgba(30, 58, 95, 0.05) 8px
    ),
    var(--color-highlight);
  border-color: var(--color-primary);
}

#round-word-container.reveal-active .card-face-back::after {
  border-color: rgba(30, 58, 95, 0.18);
}

/* ── Round-end Reveal ── */

.reveal-word-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  z-index: 1;
}

.reveal-word-content.hidden {
  display: none !important;
}

.reveal-word-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(30, 58, 95, 0.5);
}

.reveal-word {
  font-size: 1.6rem;
  font-weight: 800;
  color: rgba(30, 58, 95, 0.78);
}

/* Countdown state for the end-round button during reveal */
.btn-rect.btn-primary.btn-countdown {
  transform: translateY(2px);
  box-shadow: 1px 1px 0 var(--color-primary);
  background: var(--color-accent-hover);
  color: #fff;
  border: 2.5px solid var(--color-primary);
  cursor: default;
  pointer-events: none;
}

/* Impostor reveal badge in player list */
.impostor-reveal-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  animation: revealFadeIn 0.5s ease 0.3s both;
}

.impostor-reveal-text {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-danger);
  white-space: nowrap;
}

.impostor-reveal-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  animation: revealIconPop 0.5s var(--bounce) 0.6s both;
}

.impostor-revealed {
  background: rgba(239, 68, 68, 0.06);
  margin: 0 -10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1.5px dashed rgba(239, 68, 68, 0.25);
}

/* ===== Overlay (QR code) ===== */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(30, 58, 95, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: var(--color-surface);
  padding: 24px;
  border-radius: var(--radius-card);
  border: 3px solid var(--color-primary);
  box-shadow: 6px 6px 0 var(--color-primary);
  text-align: center;
  max-width: 300px;
  position: relative;
  animation: bounceIn 0.35s ease-out;
}

.overlay-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  font-size: 0.9rem;
}

.overlay-content canvas {
  max-width: 100%;
  border-radius: 8px;
}

.qr-url-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 4px;
}

.qr-url-row span {
  word-break: break-all;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-block;
  background: #dbeafe;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1.5px solid #3b82f6;
  color: #1d4ed8;
}

.qr-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  text-align: left;
}

.qr-hint p {
  margin: 0 0 4px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.qr-hint ul {
  margin: 0;
  padding-left: 1.2em;
}

.qr-hint li {
  padding: 2px 0;
}

/* Room code badge in QR modal – matches lobby header style */
.qr-room-code {
  display: inline-block;
  background: var(--color-highlight);
  padding: 0 7px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.85rem;
  border: 2px solid var(--color-primary);
  letter-spacing: 1.5px;
  color: var(--color-primary);
}

/* URL highlight in QR modal – distinct blue pill */
.qr-url-highlight {
  display: inline-block;
  background: #dbeafe;
  padding: 0 6px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1.5px solid #3b82f6;
  color: #1d4ed8;
}

/* ===== Toast ===== */

#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
}

.toast {
  background: var(--color-surface);
  color: var(--color-text);
  padding: 10px 20px;
  border-radius: var(--radius-btn);
  border: 2.5px solid var(--color-primary);
  box-shadow: 3px 3px 0 var(--color-primary);
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.3s ease, transform 0.3s var(--bounce);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger-dark);
  box-shadow: 3px 3px 0 var(--color-danger-dark);
}

/* ===== Kicked Screen ===== */

.kicked-card {
  background: var(--color-surface);
  border: 3px solid var(--color-danger);
  border-radius: var(--radius-card);
  box-shadow: 4px 4px 0 var(--color-danger-dark);
  padding: 24px;
  text-align: center;
}

.kicked-illustration {
  margin-bottom: 8px;
}

.kicked-title {
  color: var(--color-danger);
  font-size: 1.8rem;
}

#screen-kicked p {
  color: var(--color-text-muted);
  margin-bottom: 20px;
}

/* ===== Animations ===== */

@keyframes bounceIn {
  0%   { transform: scale(0.9); opacity: 0; }
  60%  { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes cardFlip3D {
  0%   { transform: rotateX(0deg); }
  75%  { transform: rotateX(185deg); }
  88%  { transform: rotateX(177deg); }
  100% { transform: rotateX(180deg); }
}

@keyframes cardFlipReverse {
  0%   { transform: rotateX(180deg); }
  75%  { transform: rotateX(-5deg); }
  88%  { transform: rotateX(3deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes revealFadeIn {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes revealIconPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  70%  { transform: scale(1.15) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes shakeWobble {
  0%, 100% { transform: rotate(0deg); }
  15%      { transform: rotate(-6deg); }
  30%      { transform: rotate(5deg); }
  45%      { transform: rotate(-3deg); }
  60%      { transform: rotate(2deg); }
  75%      { transform: rotate(-1deg); }
}

@keyframes maskDrop {
  0%   { transform: translateY(-30px) scale(0.5); opacity: 0; }
  60%  { transform: translateY(4px) scale(1.1); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes btnWiggle {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(-2deg); }
  40%      { transform: rotate(2deg); }
  60%      { transform: rotate(-1deg); }
  80%      { transform: rotate(1deg); }
}

