/* RajaRani — colors sampled from product/rajarani reference UI */
:root {
  --rr-primary: #5C2F8F;
  --rr-primary-light: #6D4498;
  --rr-accent-gold: #F5BB41;
  --rr-accent-gold-dark: #E5A82E;
  --rr-coins-bg: #F3E8FF;
  --rr-stat-bg: #F6F4FC;
  --rr-icon-bg: #EAE6F2;
  --rr-heading: #111111;
  --rr-body-muted: #9EA3AE;
  --rr-subtext: #8B9099;
  --rr-surface: #FFFFFF;
  --rr-shadow: 0 8px 24px rgba(92, 47, 143, 0.10);
  --rr-shadow-sm: 0 4px 16px rgba(92, 47, 143, 0.08);
  --rr-radius: 1.25rem;
  --rr-font: "Nunito", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Kingdom theme (login splash palette) */
  --rr-kingdom-bg: #241418;
  --rr-kingdom-bg-deep: #1a0f14;
  --rr-kingdom-card-top: #6b2840;
  --rr-kingdom-card-mid: #4a1c30;
  --rr-kingdom-card-bottom: #321422;
  --rr-kingdom-gold: #d4a843;
  --rr-kingdom-gold-bright: #f5bb41;
  --rr-kingdom-cream: #f5e6b8;
  --rr-kingdom-text-muted: rgba(245, 230, 184, 0.72);
  --rr-kingdom-card-bg: linear-gradient(165deg, var(--rr-kingdom-card-top) 0%, var(--rr-kingdom-card-mid) 42%, var(--rr-kingdom-card-bottom) 100%);
  --rr-kingdom-card-shadow: 0 0 0 1px rgba(212, 168, 67, 0.25), inset 0 1px 0 rgba(255, 220, 150, 0.15), 0 12px 32px rgba(0, 0, 0, 0.35);

  /* legacy aliases */
  --purple-600: var(--rr-primary);
  --purple-700: var(--rr-primary);
  --purple-800: var(--rr-primary);
  --purple-100: var(--rr-coins-bg);
  --purple-50: var(--rr-stat-bg);
  --purple-200: #DDD6FE;
  --purple-500: var(--rr-primary-light);
  --gold-500: var(--rr-accent-gold);
  --orange-500: var(--rr-accent-gold);
  --slate-400: var(--rr-body-muted);
  --slate-500: var(--rr-subtext);
  --slate-900: var(--rr-heading);
  --white: var(--rr-surface);
  --shadow: var(--rr-shadow-sm);
  --radius: var(--rr-radius);
  --font: var(--rr-font);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--rr-kingdom-bg);
  color: var(--rr-kingdom-cream);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* Mobile-first stage wrappers (transparent on phone) */
.desktop-stage {
  width: 100%;
  min-height: 100dvh;
}

.phone-frame {
  width: 100%;
  min-height: 100dvh;
  position: relative;
}

.phone-notch {
  display: none;
}

.app-shell {
  min-height: 100dvh;
  max-width: 390px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--rr-kingdom-bg);
  position: relative;
}

.app-main {
  flex: 1;
  padding: 0 0 5.5rem;
}

.app-shell:has(.home-screen),
.app-shell:has(.login-page),
.app-shell:has(.themed-page),
.app-shell:has(.create-page),
.app-shell:has(.lobby-page),
.app-shell:has(.game-page) {
  min-height: 0;
  height: auto;
}

.phone-frame:has(.home-screen),
.phone-frame:has(.login-page),
.phone-frame:has(.themed-page),
.phone-frame:has(.create-page),
.phone-frame:has(.lobby-page),
.phone-frame:has(.game-page) {
  min-height: 0;
  height: auto;
}

.app-main:has(.home-screen) {
  flex: 0 0 auto;
  padding-bottom: calc(3.625rem + env(safe-area-inset-bottom, 0px));
  background: var(--rr-kingdom-bg);
}

.app-main:has(.login-page),
.app-main:has(.create-page),
.app-main:has(.themed-page),
.app-main:has(.lobby-page),
.app-main:has(.game-page) {
  flex: 0 0 auto;
  min-height: 0;
}

.app-main:has(.lobby-page) { padding: 0; display: flex; flex-direction: column; }
.app-main:has(.login-page) {
  padding: 0;
  display: flex;
  flex-direction: column;
  background: var(--rr-kingdom-bg);
}
.app-main:has(.create-page) { padding: 1rem 1.25rem 2rem; background: var(--rr-kingdom-bg); }
.app-main:has(.themed-page) { background: var(--rr-kingdom-bg); }
.app-main:has(.placeholder-page) {
  padding-bottom: calc(3.625rem + env(safe-area-inset-bottom, 0px));
}
.app-main:has(.game-page) { padding: 0; display: flex; flex-direction: column; background: var(--rr-kingdom-bg); }

.home-screen .stat-grid {
  margin-bottom: 0;
}

/* Kingdom card frame — shared with login popup */
.card,
.home-screen .action-card,
.home-screen .stat-card,
.home-hero-wrap .hero-title-box,
.game-role-card {
  position: relative;
  background: var(--rr-kingdom-card-bg);
  border: 2px solid var(--rr-kingdom-gold);
  box-shadow: var(--rr-kingdom-card-shadow);
}

.card::before,
.home-screen .action-card::before,
.home-screen .stat-card::before,
.home-hero-wrap .hero-title-box::before,
.game-role-card::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: calc(var(--rr-radius) - 4px);
  border: 1px solid rgba(212, 168, 67, 0.2);
  pointer-events: none;
}

/* Flash toast */
.flash-toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: calc(100% - 2rem);
  text-align: center;
}
.flash-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash-error { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }

/* Header profile */
.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.profile-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--purple-200), var(--purple-500));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--white);
  font-size: 1.125rem;
  flex-shrink: 0;
}
.profile-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--rr-primary);
  line-height: 1.2;
}
.profile-level {
  font-size: 0.8125rem;
  color: var(--rr-body-muted);
  margin-top: 0.125rem;
  font-weight: 500;
}
.coins-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(212, 168, 67, 0.45);
  padding: 0.4375rem 0.75rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--rr-kingdom-cream);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.coins-badge svg { color: var(--rr-accent-gold); }

/* Home — kingdom theme */
.home-screen {
  background: var(--rr-kingdom-bg);
}

.home-hero-wrap {
  position: relative;
  margin-bottom: 1.75rem;
}

.home-hero {
  position: relative;
  height: 18rem;
  overflow: hidden;
}

.home-hero::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6rem;
  background: linear-gradient(180deg, rgba(36, 20, 24, 0) 0%, rgba(36, 20, 24, 0.88) 72%, var(--rr-kingdom-bg) 100%);
  pointer-events: none;
  z-index: 1;
}

.home-hero-bg,
.home-hero-bg.theme-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
}

.home-hero-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.625rem;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1.25rem 0;
}

.home-hero-header .profile-info {
  gap: 0.625rem;
  min-width: 0;
}

.home-hero-header .profile-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--rr-kingdom-cream);
  line-height: 1.25;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.home-hero-header .profile-level {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--rr-kingdom-text-muted);
  margin-top: 0.125rem;
}

.home-hero-header .avatar {
  width: 2.75rem;
  height: 2.75rem;
}

.home-hero-header .avatar-photo {
  border: 2px solid var(--rr-accent-gold);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.home-hero-header .coins-badge {
  padding: 0.375rem 0.6875rem;
  font-size: 0.875rem;
  font-weight: 700;
  gap: 0.3125rem;
  margin-top: 0.125rem;
}

.home-hero-wrap .hero-title-box {
  position: absolute;
  left: 50%;
  bottom: -1.625rem;
  transform: translateX(-50%);
  z-index: 3;
  width: calc(100% - 2.5rem);
  max-width: 17.5rem;
  border-radius: 1.25rem;
  padding: 0.875rem 1.375rem;
  text-align: center;
}

.home-hero-wrap .hero-title-box .line1 {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--rr-kingdom-cream);
  line-height: 1.1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.home-hero-wrap .hero-title-box .line2 {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--rr-kingdom-gold-bright);
  line-height: 1.1;
  margin-top: 0.0625rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.home-body {
  padding: 0 1.25rem 0;
}

.home-screen .section-heading {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 0.375rem;
  letter-spacing: -0.01em;
  color: var(--rr-kingdom-cream);
  text-align: center;
}

.home-screen .section-sub {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--rr-kingdom-text-muted);
  margin: 0 0 1.25rem;
  line-height: 1.45;
  text-align: center;
}

.home-screen .btn-play {
  width: 100%;
  margin-bottom: 1rem;
  border-radius: 999px;
  min-height: 3.25rem;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, var(--rr-kingdom-gold-bright) 0%, var(--rr-accent-gold-dark) 100%);
  color: #3d1828;
  box-shadow: 0 4px 0 #a67c1a, 0 8px 20px rgba(0, 0, 0, 0.35);
}

.home-screen .btn-play:hover {
  background: linear-gradient(180deg, #ffc94d 0%, var(--rr-kingdom-gold-bright) 100%);
  transform: translateY(-1px);
}

.home-screen .action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.home-screen .action-card {
  border-radius: 1.25rem;
  padding: 1.25rem 0.75rem 1.125rem;
  text-align: center;
  transition: transform 150ms ease-out, box-shadow 150ms ease-out;
}

.home-screen .action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--rr-kingdom-card-shadow), 0 12px 28px rgba(0, 0, 0, 0.25);
}

.home-screen .action-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--rr-kingdom-gold-bright);
  border: 1px solid rgba(212, 168, 67, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.625rem;
}

.home-screen .action-label {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--rr-kingdom-cream);
}

.home-screen .stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.home-screen .stat-card {
  border-radius: 1rem;
  padding: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.home-screen .stat-icon {
  width: 2.375rem;
  height: 2.375rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.home-screen .stat-icon-gold {
  background: rgba(0, 0, 0, 0.22);
  color: var(--rr-kingdom-gold-bright);
  border: 1px solid rgba(212, 168, 67, 0.45);
}

.home-screen .stat-icon-purple {
  background: rgba(0, 0, 0, 0.22);
  color: var(--rr-kingdom-gold-bright);
  border: 1px solid rgba(212, 168, 67, 0.45);
}

.home-screen .stat-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rr-kingdom-text-muted);
  line-height: 1.2;
}

.home-screen .stat-value {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--rr-kingdom-cream);
  margin-top: 0.125rem;
  line-height: 1.25;
}

.avatar-photo {
  padding: 0;
  overflow: hidden;
  background: #fff;
}

.avatar-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Theme art — Raja / Rani / Police / Thief splash */
.theme-banner {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.theme-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  display: block;
}

.theme-banner-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(36, 20, 24, 0.05) 0%, rgba(36, 20, 24, 0.28) 55%, rgba(36, 20, 24, 0.72) 100%);
  pointer-events: none;
}

.theme-banner-compact {
  height: 9rem;
  margin: -1rem -1.25rem 0.875rem;
  border-radius: 0 0 1rem 1rem;
}

.theme-banner-lobby {
  margin: 0 0 0.5rem;
  border-radius: 0;
}

.themed-page {
  background: var(--rr-kingdom-bg);
  color: var(--rr-kingdom-cream);
}

.card-heading {
  margin: 0 0 1rem;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--rr-kingdom-cream);
}

.form-code {
  letter-spacing: 0.35em;
  font-size: 1.375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.placeholder-page .page-top {
  padding-top: 0.25rem;
}

.nav-item.active { color: var(--rr-kingdom-gold-bright); }
.nav-item { color: var(--rr-kingdom-text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 150ms ease-out, box-shadow 150ms ease-out, transform 150ms ease-out;
  min-height: 3rem;
  padding: 0 1.5rem;
}
.btn:focus-visible {
  outline: 2px solid var(--rr-kingdom-gold);
  outline-offset: 2px;
}
.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, var(--rr-kingdom-gold-bright) 0%, var(--rr-accent-gold-dark) 100%);
  color: #3d1828;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 0 #a67c1a, 0 8px 20px rgba(0, 0, 0, 0.35);
  margin-bottom: 1rem;
}
.btn-primary:hover {
  background: linear-gradient(180deg, #ffc94d 0%, var(--rr-kingdom-gold-bright) 100%);
  transform: translateY(-1px);
}
.btn-secondary {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  color: var(--rr-kingdom-cream);
  border: 1.5px solid rgba(212, 168, 67, 0.55);
}
.btn-secondary:hover { background: rgba(0, 0, 0, 0.32); }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
  margin-bottom: 1.25rem;
}
.action-card {
  background: var(--white);
  border: 1px solid #f1f5f9;
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 150ms ease-out, box-shadow 150ms ease-out;
}
.action-card:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(91,33,182,0.12); }
.action-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-600);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.625rem;
}
.action-label {
  font-weight: 600;
  font-size: 0.9375rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
}
.stat-card {
  background: var(--purple-50);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.stat-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon.gold { background: #fef3c7; color: var(--gold-500); }
.stat-icon.purple { background: var(--purple-100); color: var(--purple-600); }
.stat-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate-500);
}
.stat-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--slate-900);
  margin-top: 0.125rem;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 390px;
  background: linear-gradient(180deg, var(--rr-kingdom-card-mid) 0%, var(--rr-kingdom-bg-deep) 100%);
  border-top: 2px solid rgba(212, 168, 67, 0.45);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--rr-kingdom-text-muted);
  transition: color 150ms ease-out;
}
.nav-item svg { width: 1.375rem; height: 1.375rem; }
.nav-item.active { color: var(--rr-kingdom-gold-bright); }

/* Page header (inner pages) */
.page-header {
  text-align: center;
  margin-bottom: 1rem;
}

.page-header .page-title {
  margin: 0;
  padding-right: 0;
}

.page-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  min-height: 2.5rem;
}

.page-title {
  flex: 1;
  text-align: center;
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  color: var(--rr-kingdom-cream);
}

.page-exit-wrap {
  margin-top: 1rem;
  padding: 0 0 1.25rem;
}

.lobby-page .page-exit-wrap,
.game-page .page-exit-wrap {
  margin-top: 0.75rem;
  padding: 0 1.25rem 1.25rem;
}

.btn-exit {
  width: 100%;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--rr-kingdom-text-muted);
  background: transparent;
  border: 1.5px solid rgba(212, 168, 67, 0.35);
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.btn-exit:hover {
  background: rgba(212, 168, 67, 0.12);
  color: var(--rr-kingdom-cream);
}

.app-page-fill {
  min-height: min(820px, calc(100dvh - 1rem));
  display: flex;
  flex-direction: column;
}

.app-page-fill .page-exit-wrap {
  margin-top: auto;
}

.card-compact {
  padding: 0.875rem 1rem;
  margin-bottom: 0.875rem;
}

.card-compact .card-heading {
  margin-bottom: 0.375rem;
  font-size: 0.9375rem;
}

.card-compact .slider-row {
  margin-bottom: 0.25rem;
}

.card-compact input[type="range"] {
  margin: 0.125rem 0 0.25rem;
}

.card-compact .slider-labels {
  font-size: 0.75rem;
}

.code-display {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.28);
  border: 2px dashed rgba(212, 168, 67, 0.55);
  border-radius: 0.875rem;
  padding: 0.75rem 0.625rem;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  color: var(--rr-kingdom-cream);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.lobby-top-spacer {
  width: 2.5rem;
  height: 2.5rem;
}

.waiting-circle svg {
  color: var(--rr-kingdom-gold-bright);
  margin-bottom: 0.25rem;
}

.chat-empty {
  margin: 0;
  padding: 0.75rem 0.5rem 1rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--rr-kingdom-text-muted);
  font-style: italic;
}

.create-hero {
  text-align: center;
  margin-bottom: 1.25rem;
}
.crown-icon {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-700);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  overflow: hidden;
}

.crown-icon-king {
  width: 5.5rem;
  height: 5.5rem;
  border: 3px solid var(--rr-accent-gold);
  box-shadow: var(--rr-shadow-sm);
  background: #fff;
}

.crown-icon-king img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.create-hero h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: var(--rr-kingdom-cream);
}

.create-hero p {
  color: var(--rr-kingdom-text-muted);
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.card {
  border-radius: var(--rr-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rr-kingdom-gold-bright);
  margin-bottom: 0.75rem;
}
.copy-btn {
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 0.875rem;
  background: rgba(0, 0, 0, 0.28);
  color: var(--rr-kingdom-gold-bright);
  border: 1px solid rgba(212, 168, 67, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease-out;
}
.copy-btn:hover { background: rgba(212, 168, 67, 0.2); }

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  color: var(--rr-kingdom-cream);
}
.slider-row span:last-child {
  font-weight: 700;
  color: var(--rr-kingdom-gold-bright);
  font-size: 1.125rem;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--rr-kingdom-gold-bright);
  margin: 0.5rem 0;
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--rr-kingdom-text-muted);
}

.code-row {
  display: flex;
  gap: 0.625rem;
  align-items: center;
}

.form-input {
  width: 100%;
  min-height: 3rem;
  border: 1.5px solid rgba(212, 168, 67, 0.5);
  border-radius: 0.875rem;
  padding: 0 1rem;
  font-size: 1rem;
  font-family: inherit;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  background: rgba(0, 0, 0, 0.28);
  color: var(--rr-kingdom-cream);
}
.form-input::placeholder {
  color: rgba(245, 230, 184, 0.42);
}
.form-input:focus {
  outline: none;
  border-color: var(--rr-kingdom-gold-bright);
  box-shadow: 0 0 0 3px rgba(245, 187, 65, 0.22);
}

/* Lobby */
.lobby-page {
  display: flex;
  flex-direction: column;
  background: var(--rr-kingdom-bg);
  color: var(--rr-kingdom-cream);
}
.lobby-top {
  display: grid;
  grid-template-columns: 2.5rem 1fr 2.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
}
.lobby-top-center { text-align: center; }
.lobby-top-center .room-label {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0;
  color: var(--rr-kingdom-cream);
}
.lobby-top-center .game-title {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--rr-kingdom-gold-bright);
  margin: 0.2rem 0 0;
}
.settings-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--rr-kingdom-gold-bright);
}
.lobby-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem 0;
}
.btn-start-game {
  background: linear-gradient(180deg, var(--rr-kingdom-gold-bright) 0%, var(--rr-accent-gold-dark) 100%);
  color: #3d1828;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 2rem;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #a67c1a, 0 8px 20px rgba(0, 0, 0, 0.35);
}
.game-page .lobby-main { display: none; }
.game-role-card {
  margin: 0 1.25rem 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--rr-radius);
  text-align: center;
}
.game-role-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rr-kingdom-gold-bright);
  margin: 0 0 0.25rem;
}
.game-role-title {
  margin: 0;
  font-size: 1.375rem;
  color: var(--rr-kingdom-cream);
}
.game-role-hint {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--rr-kingdom-text-muted);
}
.game-timer-wrap {
  text-align: center;
  padding: 0 1.25rem 0.75rem;
}
.game-timer-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rr-kingdom-text-muted);
  margin: 0 0 0.25rem;
}
.game-timer {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--rr-kingdom-gold-bright);
  font-variant-numeric: tabular-nums;
}
.game-timer-sub {
  font-size: 0.8125rem;
  color: var(--rr-kingdom-text-muted);
  margin: 0.25rem 0 0;
  line-height: 1.4;
}

/* Lobby */
.lobby-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.lobby-header .room-label {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.lobby-header .game-title {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--purple-600);
  margin: 0.25rem 0 0;
}

.waiting-circle {
  width: 10rem;
  height: 10rem;
  border-radius: 999px;
  border: 3px solid var(--rr-kingdom-gold);
  background: var(--rr-kingdom-card-bg);
  box-shadow: var(--rr-kingdom-card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
  position: relative;
}
.waiting-circle .count {
  font-size: 2rem;
  font-weight: 800;
  color: var(--rr-kingdom-cream);
  line-height: 1;
}
.waiting-circle .status {
  font-size: 0.875rem;
  color: var(--rr-kingdom-text-muted);
  margin-top: 0.25rem;
}
.waiting-banner {
  background: rgba(0, 0, 0, 0.28);
  border: 1.5px solid rgba(212, 168, 67, 0.45);
  border-radius: 999px;
  padding: 0.875rem 1.25rem;
  text-align: center;
  font-weight: 600;
  color: var(--rr-kingdom-cream);
  margin-bottom: 1.5rem;
  font-size: 0.9375rem;
}

.chat-panel {
  background: var(--rr-kingdom-card-bg);
  border: 2px solid var(--rr-kingdom-gold);
  border-bottom: none;
  border-radius: 1.5rem 1.5rem 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
  margin-top: auto;
  padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
  width: 100%;
  position: relative;
}
.chat-panel::before {
  content: "";
  position: absolute;
  inset: 3px 3px auto;
  height: calc(100% - 6px);
  border-radius: 1.25rem 1.25rem 0 0;
  border: 1px solid rgba(212, 168, 67, 0.2);
  border-bottom: none;
  pointer-events: none;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--rr-kingdom-cream);
}
.chat-chevron {
  margin-left: auto;
  color: var(--rr-kingdom-text-muted);
  font-size: 0.875rem;
}
.chat-messages {
  max-height: 11rem;
  overflow-y: auto;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.msg-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.msg-row.mine { flex-direction: row-reverse; }
.msg-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--purple-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--purple-700);
  flex-shrink: 0;
}
.msg-bubble {
  max-width: 75%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.4;
}
.msg-bubble.in {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(212, 168, 67, 0.25);
  border-bottom-left-radius: 0.25rem;
  color: var(--rr-kingdom-cream);
}
.msg-bubble.out {
  background: rgba(107, 40, 64, 0.65);
  border: 1px solid rgba(212, 168, 67, 0.35);
  border-bottom-right-radius: 0.25rem;
  color: var(--rr-kingdom-cream);
}
.msg-name {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--rr-kingdom-gold-bright);
  margin-bottom: 0.125rem;
}
.msg-bubble.out .msg-name { color: var(--rr-kingdom-text-muted); text-align: right; }

.chat-form {
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  border: 1.5px solid rgba(212, 168, 67, 0.45);
  background: rgba(0, 0, 0, 0.28);
  color: var(--rr-kingdom-cream);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 0.9375rem;
}
.chat-input::placeholder { color: rgba(245, 230, 184, 0.42); }
.chat-input:focus { outline: 2px solid rgba(245, 187, 65, 0.35); }
.send-btn {
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--rr-kingdom-gold-bright) 0%, var(--rr-accent-gold-dark) 100%);
  color: #3d1828;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 150ms ease-out;
}
.send-btn:hover { transform: translateY(-1px); }

/* Login — splash (2s) then themed email popup */
.login-page {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  display: block;
  overflow: hidden;
  background: var(--rr-kingdom-bg);
  line-height: 0;
}

.login-stage {
  width: 100%;
}

.login-bg {
  width: 100%;
  height: auto;
  display: block;
  vertical-align: top;
}

.login-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(36, 20, 24, 0.15) 0%,
    rgba(36, 20, 24, 0.45) 55%,
    rgba(20, 10, 16, 0.62) 100%
  );
  opacity: 0;
  transition: opacity 450ms ease;
  pointer-events: none;
  z-index: 1;
}

.login-popup {
  position: absolute;
  left: 50%;
  top: 52%;
  z-index: 2;
  width: min(calc(100% - 2rem), 18rem);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -48%) scale(0.94);
  transition: opacity 450ms ease, transform 450ms ease;
  line-height: normal;
}

.login-popup-frame {
  position: relative;
  padding: 1.375rem 1.25rem 1.25rem;
  border-radius: 1rem;
  text-align: center;
  background: var(--rr-kingdom-card-bg);
  border: 2.5px solid var(--rr-kingdom-gold);
  box-shadow: var(--rr-kingdom-card-shadow);
}

.login-popup-frame::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 0.75rem;
  border: 1px solid rgba(212, 168, 67, 0.22);
  pointer-events: none;
}

.login-popup-crest {
  width: 2.75rem;
  height: 2.75rem;
  margin: -2.5rem auto 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(180deg, #f5bb41 0%, #c9922a 100%);
  color: #4a1c30;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  border: 2px solid #f5e6b8;
}

.login-page.login-ready .login-scrim {
  opacity: 1;
}

.login-page.login-ready .login-popup {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.login-popup-title {
  margin: 0 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
}

.login-popup-title .line1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #f5e6b8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.login-popup-title .line2 {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--rr-accent-gold);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.login-popup-sub {
  margin: 0 0 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(245, 230, 184, 0.78);
}

.login-form .login-input {
  margin-bottom: 0.75rem;
  min-height: 2.75rem;
  font-size: 0.9375rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1.5px solid rgba(212, 168, 67, 0.5);
  color: #fff;
  border-radius: 0.75rem;
}

.login-form .login-input::placeholder {
  color: rgba(255, 255, 255, 0.42);
}

.login-form .login-input:focus {
  border-color: var(--rr-accent-gold);
  box-shadow: 0 0 0 3px rgba(245, 187, 65, 0.22);
}

.btn-login-gold {
  width: 100%;
  min-height: 2.875rem;
  margin: 0;
  border: none;
  border-radius: 0.75rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  color: #3d1828;
  background: linear-gradient(180deg, #f5bb41 0%, #e5a82e 100%);
  box-shadow:
    0 4px 0 #a67c1a,
    0 8px 20px rgba(0, 0, 0, 0.35);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.btn-login-gold:hover {
  transform: translateY(-1px);
  box-shadow:
    0 5px 0 #a67c1a,
    0 10px 24px rgba(0, 0, 0, 0.4);
}

.btn-login-gold:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 0 #a67c1a,
    0 4px 12px rgba(0, 0, 0, 0.3);
}
.msg-avatar.av-king { background: #fef3c7; padding: 0; overflow: hidden; }
.msg-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  border-radius: 999px;
}
.msg-avatar.av-you { background: #dcfce7; }
.msg-avatar.av-other { background: #e2e8f0; }
.voice-btn {
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--purple-600);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.voice-btn.recording { background: #fecdd3; color: #be123c; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.7; } }
.voice-audio { width: 100%; max-width: 14rem; height: 2rem; margin-top: 0.25rem; }
.login-hint {
  font-size: 0.75rem;
  color: var(--slate-500);
  margin: -0.5rem 0 1rem;
  line-height: 1.4;
}
.form-email { letter-spacing: normal; text-transform: none; text-align: left; }
.create-page { padding: 0 1.25rem; }

.placeholder-body {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--rr-kingdom-text-muted);
}
.placeholder-body h2 {
  color: var(--rr-kingdom-cream);
  margin-bottom: 0.5rem;
}

@media (min-width: 481px) {
  body {
    background: #E8E4F0;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
  }

  .desktop-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: auto;
    width: auto;
  }

  .phone-frame {
    position: relative;
    width: 390px;
    height: auto;
    max-height: min(844px, calc(100dvh - 3rem));
    min-height: 0;
    background: #1a1a1a;
    border-radius: 2.75rem;
    padding: 0.625rem;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 24px 64px rgba(30, 16, 50, 0.28),
      inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  }

  .phone-notch {
    display: block;
    position: absolute;
    top: 0.625rem;
    left: 50%;
    transform: translateX(-50%);
    width: 6.5rem;
    height: 1.375rem;
    background: #1a1a1a;
    border-radius: 0 0 1rem 1rem;
    z-index: 60;
    pointer-events: none;
  }

  .app-shell {
    width: 100%;
    height: auto;
    max-width: none;
    margin: 0;
    border-radius: 2.125rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--rr-kingdom-bg);
    border: none;
    box-shadow: none;
    min-height: 0;
  }

  .app-main {
    flex: 0 0 auto;
    overflow: visible;
  }

  .app-main:has(.home-screen),
  .app-main:has(.placeholder-page) {
    padding-bottom: calc(3.625rem + env(safe-area-inset-bottom, 0px));
  }

  .app-main:has(.lobby-page),
  .app-main:has(.game-page),
  .app-main:has(.create-page),
  .app-main:has(.themed-page) {
    max-height: min(844px, calc(100dvh - 3rem));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .app-main:has(.login-page) {
    overflow: hidden;
  }

  .bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    max-width: none;
    width: 100%;
    border-radius: 0;
  }

  .flash-toast {
    max-width: 350px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-scrim,
  .login-popup,
  .btn-login-gold {
    transition: none;
  }

  .btn, .action-card, .nav-item, .copy-btn, .send-btn, .btn-exit,
  .char-bounce-1, .char-bounce-2, .char-bounce-3, .char-bounce-4 {
    animation: none;
    transition: none;
  }
}
