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

:root {
  --bg: #eff6ff;
  --bg-2: #dbeafe;
  --card: #ffffff;
  --card-2: #f1f5f9;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #cbd5e1;
  --accent: #0ea5e9;
  --accent-warm: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #dbeafe;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(59, 130, 246, 0.15);
}

html, body {
  min-height: 100%;
}

html, body {
  /* `clip` avoids creating a scroll container on iOS, which can break
     natural body scrolling when content exceeds the viewport. */
  overflow-x: clip;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #e0f2fe 0%, #eff6ff 50%, #dbeafe 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  overscroll-behavior-y: none;
}

.app {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: calc(max(32px, env(safe-area-inset-bottom)) + 32px);
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.3s ease;
  flex: 1;
}

.screen.active {
  display: flex;
}

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

/* Branding */
.brand {
  text-align: center;
  padding: 24px 0 12px;
}

.brand.small {
  padding: 16px 0 8px;
}

.logo {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #0ea5e9, #3b82f6, #6366f1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(59, 130, 246, 0.25);
  white-space: nowrap;
}

.brand.small .logo {
  font-size: 28px;
  letter-spacing: 3px;
}

.tagline {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 10px;
  letter-spacing: 0.5px;
}

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card.center {
  text-align: center;
  align-items: center;
}

.card.scrollable {
  overflow-y: auto;
  max-height: 70vh;
}

.card h2 {
  font-size: 20px;
  text-align: center;
}

.card h3 {
  font-size: 16px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  border: none;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}

.btn-ghost:hover {
  background: var(--bg-2);
}

.btn-large {
  padding: 20px;
  font-size: 18px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.lang-buttons {
  display: grid;
  gap: 12px;
}

.lang-btn {
  font-size: 18px;
  padding: 20px;
}

.flag {
  font-size: 24px;
}

.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0 8px;
  letter-spacing: 0.2px;
}

.app-footer a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s ease;
}

.app-footer a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar h2 {
  font-size: 22px;
}

/* Forms */
.form-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.form-row label {
  font-size: 16px;
  font-weight: 500;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-step {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn-step:hover {
  background: var(--primary);
  color: white;
}

.btn-step:active {
  background: var(--primary-hover);
  color: white;
}

.stepper-value {
  min-width: 30px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  font-style: italic;
}

.hint.error {
  color: var(--danger);
}

.text-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ==========================================================================
   Setup screen: fixed-viewport 3-zone layout (topbar + config / player list /
   action button). Pattern used by Undercover, Spyfall, Werewolf, etc.:
   - Page never scrolls.
   - The player-names list is the only scrolling region.
   - Start Game stays pinned at the bottom regardless of player count.
   Scoped via :has() so other screens keep their natural body-scroll behavior.
   ========================================================================== */

html:has(#screen-setup.active),
html:has(#screen-setup.active) body {
  overflow: hidden;
  height: 100dvh;
}

html:has(#screen-setup.active) .app {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* Grid makes the zones explicit: the 1fr row is the only one that flexes;
   minmax keeps the list usable even on short viewports. */
#screen-setup.active {
  display: grid;
  grid-template-rows: auto auto minmax(80px, 1fr) auto;
  gap: 20px;
  min-height: 0;
  overflow: hidden;
}

/* Player-names card fills the 1fr row and clips; its inner list scrolls. */
#screen-setup > .card:nth-of-type(2) {
  min-height: 0;
  overflow: hidden;
}

#player-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* Small inset so the focus ring isn't clipped by the scroll container. */
  padding: 4px;
  margin: -4px;
}

/* Reveal */
.reveal-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px 0;
  flex: 1;
  justify-content: center;
}

.reveal-step {
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.reveal-name {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
}

.card-flip {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  perspective: 1000px;
  cursor: pointer;
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.6s ease;
  padding: 20px;
  text-align: center;
}

.card-back {
  background: linear-gradient(135deg, #38bdf8, #3b82f6, #6366f1);
  color: white;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  box-shadow: 0 10px 30px rgba(59, 130, 246, 0.35);
}

.card-back::before {
  content: 'E';
  position: absolute;
  font-size: 140px;
  font-weight: 900;
  opacity: 0.2;
  color: white;
}

.card-front {
  background: linear-gradient(135deg, #ffffff, #f0f9ff);
  border: 2px solid var(--primary);
  color: var(--text);
  transform: rotateY(180deg);
}

.card-flip.flipped .card-back {
  transform: rotateY(180deg);
}

.card-flip.flipped .card-front {
  transform: rotateY(360deg);
}

.role-label {
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 16px;
}

.word {
  font-size: 42px;
  font-weight: 900;
  color: var(--text);
  word-break: break-word;
  line-height: 1.1;
}

.word-hint {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 16px;
}

/* Order list */
.order-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.order-list li {
  background: var(--bg-2);
  padding: 14px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
}

.order-list li .num {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.order-list li.eliminated {
  opacity: 0.45;
  text-decoration: line-through;
}

.order-list li .role-tag {
  margin-left: auto;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
}

.role-tag.civilian { background: rgba(16, 185, 129, 0.15); color: #059669; }
.role-tag.undercover { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
.role-tag.mrwhite { background: rgba(245, 158, 11, 0.18); color: #d97706; }

/* Vote grid */
.vote-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.vote-btn {
  padding: 20px 10px;
  font-size: 16px;
}

.big-info {
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
}

.big-name {
  font-size: 36px;
  font-weight: 900;
  margin: 16px 0 8px;
}

.role-reveal {
  color: var(--text-muted);
  font-size: 18px;
  margin-bottom: 16px;
}

.hidden { display: none !important; }

.reveal-words {
  background: var(--bg-2);
  padding: 16px;
  border-radius: var(--radius);
  width: 100%;
  margin: 16px 0;
  text-align: left;
  border: 1px solid var(--border);
}

.reveal-words p {
  margin: 8px 0;
  font-size: 15px;
}

.reveal-words strong {
  color: var(--primary);
}

/* How to play */
#howto-content h3 {
  color: var(--primary);
  margin: 16px 0 8px;
  font-size: 16px;
}

#howto-content h3:first-child { margin-top: 0; }

#howto-content p, #howto-content li {
  color: var(--text);
  font-size: 14px;
  margin-bottom: 8px;
  line-height: 1.6;
}

#howto-content ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

/* Responsive tweaks */
@media (min-width: 768px) {
  .app { padding: 40px 20px; }
  .logo { font-size: 52px; letter-spacing: 6px; }
  .card-flip { max-width: 380px; }
  .word { font-size: 52px; }
}

@media (max-width: 380px) {
  .logo { font-size: 32px; letter-spacing: 3px; }
  .word { font-size: 34px; }
  .big-name { font-size: 28px; }
  .card { padding: 18px; }
  .btn { padding: 14px 16px; font-size: 15px; }
}

@media (max-height: 700px) {
  .brand { padding: 20px 0 10px; }
  .reveal-wrap { padding: 10px 0; gap: 14px; }
}
