:root {
  color-scheme: light;
  --ink: #312a23;
  --paper: #fffefe;
  --paper-deep: #fff1c0;
  --mint: #dff6f1;
  --mint-strong: #8d6bff;
  --coral: #f2a5ff;
  --coral-strong: #d957f1;
  --sky: #efe6ff;
  --sky-strong: #8a55f6;
  --leaf: #ffe48a;
  --sun: #ffc226;
  --shadow: rgba(49, 42, 35, 0.18);
  --radius: 8px;
  --font-hand: "Comic Sans MS", "Bradley Hand", "LXGW WenKai", "Kaiti SC", "STKaiti", system-ui, sans-serif;
  --font-ui: "Comic Sans MS", "Bradley Hand", "LXGW WenKai", "Kaiti SC", "STKaiti", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--font-ui);
  letter-spacing: 0;
  background:
    radial-gradient(circle at 14% 15%, rgba(138, 85, 246, 0.16), transparent 25rem),
    radial-gradient(circle at 90% 8%, rgba(240, 92, 232, 0.16), transparent 24rem),
    radial-gradient(circle at 86% 92%, rgba(255, 194, 38, 0.18), transparent 26rem),
    linear-gradient(135deg, #ffffff 0%, #fffaff 46%, #fffdf5 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  content: "";
  opacity: 0.4;
  background-image:
    linear-gradient(rgba(49, 42, 35, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(49, 42, 35, 0.04) 1px, transparent 1px);
  background-size: 38px 38px;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.paint-wash {
  position: fixed;
  z-index: -2;
  width: 18rem;
  height: 18rem;
  border-radius: 47% 53% 43% 57%;
  filter: blur(16px);
  opacity: 0.42;
  transform: rotate(-6deg);
}

.wash-one {
  top: 7rem;
  left: -4rem;
  background: var(--leaf);
}

.wash-two {
  right: -5rem;
  bottom: 8rem;
  background: var(--coral);
  transform: rotate(10deg);
}

.wash-three {
  top: 52%;
  left: 42%;
  background: var(--sky);
  transform: translate(-50%, -50%) rotate(18deg);
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 80px;
  padding: 0 12px;
}

.brand-button,
.icon-button,
.primary-button,
.secondary-button,
.role-card,
.difficulty-button,
.mode-button,
.answer-button,
.small-button {
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 4px 12px var(--shadow);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.brand-button:hover,
.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.role-card:hover,
.difficulty-button:hover,
.mode-button:hover,
.answer-button:hover,
.small-button:hover {
  transform: translate(-1px, -2px) rotate(-0.4deg);
  box-shadow: 0 4px 12px var(--shadow);
}

.brand-button:active,
.icon-button:active,
.primary-button:active,
.secondary-button:active,
.role-card:active,
.difficulty-button:active,
.mode-button:active,
.answer-button:active,
.small-button:active {
  transform: translate(1px, 1px);
  box-shadow: 0 2px 4px var(--shadow);
}

.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  font-family: var(--font-ui);
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 800;
}

.brand-mark {
  width: 44px;
  height: 40px;
  object-fit: contain;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
  background: var(--paper-deep);
}

.leaderboard-trigger {
  background: var(--sun);
}

.screen {
  padding-top: 28px;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 900px) {
  .home-grid {
    grid-template-columns: 1fr 1fr;
  }
  .home-grid-span-all {
    grid-column: 1 / -1;
  }
}

.home-section-title {
  font-family: var(--font-ui);
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 16px;
  color: var(--ink);
}

/* ---- Home loading skeleton (shown until app.js runs its first render) ---- */
.home-skeleton {
  padding-top: 20px;
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 4px 12px rgba(49, 42, 35, 0.05);
}

.skeleton-banner {
  min-height: 120px;
}

.skeleton-panel {
  min-height: 300px;
}

.skeleton-collection {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

/* Shimmer placeholder primitive */
.sk {
  position: relative;
  overflow: hidden;
  background: var(--paper-deep);
  border-radius: 8px;
}

.sk::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.65) 50%, transparent 100%);
  animation: skeleton-sweep 1.5s infinite;
}

@keyframes skeleton-sweep {
  100% { transform: translateX(100%); }
}

.sk-line { height: 16px; border-radius: 999px; }
.sk-w-30 { width: 30%; }
.sk-w-40 { width: 40%; }
.sk-w-50 { width: 50%; }
.sk-w-70 { width: 70%; }
.sk-w-90 { width: 90%; }
.sk-pill { width: 160px; height: 44px; border-radius: 999px; margin-top: auto; }
.sk-block { flex: 1; min-height: 120px; border-radius: 16px; }
.sk-btn { height: 48px; border-radius: 14px; margin-top: auto; }
.sk-tile { min-height: 180px; border-radius: 16px; }

@media (prefers-reduced-motion: reduce) {
  .sk::after { animation: none; }
}

.home-panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.home-header {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 0px;
}

.home-title-area {
  display: grid;
  gap: 8px;
}

.home-visual {
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.home-visual img {
  width: min(84vw, 200px);
  height: auto;
  filter: drop-shadow(0 18px 20px rgba(49, 42, 35, 0.16));
  animation: floaty 4s ease-in-out infinite;
}

.home-board {
  display: grid;
  gap: 22px;
}

.home-copy {
  max-width: 620px;
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(1.1rem, 2.8vw, 1.45rem);
  font-weight: 800;
  line-height: 1.35;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-button {
  min-height: 48px;
  padding: 10px 14px;
  font-weight: 900;
  background: #fff;
}

.mode-button.is-selected {
  background: var(--sky);
  box-shadow: 4px 5px 0 rgba(138, 85, 246, 0.24);
}

.status-pill,
.loading-line {
  width: fit-content;
  max-width: 100%;
  padding: 8px 11px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  font-weight: 900;
  background: var(--paper-deep);
  box-shadow: 0 2px 8px rgba(49, 42, 35, 0.05);
}

.status-pill.is-ready {
  background: var(--mint);
}

.status-pill.is-warn {
  background: var(--coral);
}

.app-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(3rem, 9vw, 6.7rem);
  line-height: 1;
  letter-spacing: 0;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.role-card {
  min-height: 138px;
  padding: 18px;
  text-align: left;
  background: rgba(255, 253, 244, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.role-mascot {
  height: 50px;
  width: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.role-mascot svg {
  height: 100%;
  width: auto;
}

.role-card:first-child {
  transform: rotate(-0.7deg);
}

.role-card:last-child {
  transform: rotate(0.8deg);
}

.role-card.is-selected {
  background: var(--mint);
  box-shadow: 4px 5px 0 rgba(120, 191, 174, 0.45);
}

.role-card.is-selected:last-child {
  background: var(--sky);
  box-shadow: 4px 5px 0 rgba(95, 143, 220, 0.35);
}

.role-name {
  display: block;
  font-family: var(--font-ui);
  font-size: clamp(1.45rem, 4vw, 2.4rem);
  font-weight: 800;
}

.role-label {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 9px;
  border: 2px solid currentColor;
  border-radius: 12px;
  color: rgba(49, 42, 35, 0.76);
  font-size: 0.86rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.5);
}

.difficulty-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 2px dashed rgba(49, 42, 35, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.54);
}

.difficulty-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.difficulty-head strong {
  font-family: var(--font-ui);
  font-size: 1.3rem;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.difficulty-button {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 10px;
  text-align: left;
}

.difficulty-button.is-selected {
  background: var(--sun);
}

.difficulty-button span {
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 900;
}

.difficulty-button small {
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
}

.world-cup-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(223, 246, 241, 0.94), rgba(255, 228, 138, 0.88));
  box-shadow: 0 4px 12px var(--shadow);
}

.world-cup-entry span,
.share-link-box span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.world-cup-entry strong {
  display: block;
  font-family: var(--font-ui);
  font-size: 1.35rem;
  font-weight: 900;
}

.world-cup-entry p {
  margin: 4px 0 0;
  font-weight: 800;
  line-height: 1.35;
}

.challenge-create {
  display: grid;
  gap: 12px;
}

.challenge-create-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.join-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr) auto;
  gap: 8px;
}

.home-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.primary-button,
.secondary-button,
.small-button,
.answer-button {
  min-height: 46px;
  padding: 11px 18px;
  font-weight: 900;
}

.primary-button {
  background: var(--sky-strong);
  color: #fff;
}

.secondary-button {
  background: var(--paper);
}

.full-button {
  width: 100%;
}

.game-screen {
  display: grid;
  gap: 18px;
}

.game-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: rgba(255, 253, 244, 0.88);
  box-shadow: 0 4px 12px var(--shadow);
}

.game-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1;
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  color: rgba(49, 42, 35, 0.68);
}

.progress-box {
  display: grid;
  gap: 8px;
  min-width: min(260px, 34vw);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.92rem;
  font-weight: 900;
}

.progress-rail {
  position: relative;
  height: 15px;
  overflow: hidden;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 999px;
  background: #fff;
}

.progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-right: 2px solid rgba(49, 42, 35, 0.55);
  background: linear-gradient(90deg, var(--mint-strong), var(--sun), var(--coral));
  transition: width 260ms ease;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (min-width: 900px) {
  .game-layout {
    flex-direction: row;
    align-items: flex-start;
  }
  .game-main-col {
    flex: 1;
    min-width: 0;
  }
  .game-sidebar-col {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
}

.panel {
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: rgba(255, 253, 244, 0.92);
  box-shadow: 0 4px 12px var(--shadow);
}

.history-panel {
  position: relative;
  min-height: 520px;
  overflow: hidden;
}

.chat-result-backdrop {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
}

.chat-result-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(420px, 100%);
  max-height: 100%;
  padding: 18px;
  overflow: auto;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 12px;
  text-align: center;
  background: #fff;
  box-shadow: 0 16px 48px rgba(49, 42, 35, 0.15);
  animation: popIn 180ms ease both;
}

.chat-result-card h2 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 2rem;
  line-height: 1;
}

.chat-result-card p {
  margin: 0;
  font-weight: 900;
}

.result-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.result-mini-lines {
  display: grid;
  gap: 4px;
  font-size: 0.92rem;
  font-weight: 900;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 2px solid rgba(49, 42, 35, 0.18);
}

.panel-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 1.55rem;
  line-height: 1;
}

.object-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  overflow-wrap: anywhere;
  font-weight: 900;
  background: var(--leaf);
}

.history-list {
  display: grid;
  gap: 12px;
  max-height: 460px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  list-style: none;
}

.empty-history {
  display: grid;
  min-height: 280px;
  place-items: center;
  padding: 28px;
  color: rgba(49, 42, 35, 0.52);
  font-family: var(--font-ui);
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
}

.history-item {
  display: grid;
  gap: 7px;
  animation: popIn 240ms ease both;
}

.bubble {
  width: fit-content;
  max-width: min(100%, 680px);
  padding: 11px 13px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(49, 42, 35, 0.05);
  overflow-wrap: anywhere;
  background: white;
}

.bubble.question {
  background: var(--sky);
}

.bubble.answer {
  margin-left: 22px;
  background: var(--mint);
}

.bubble-emoji {
  display: inline-grid;
  width: 1.6rem;
  height: 1.6rem;
  place-items: center;
  margin-right: 4px;
  border: 2px solid rgba(49, 42, 35, 0.32);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  vertical-align: middle;
}

.bubble-quip {
  display: block;
  margin-top: 5px;
  color: rgba(49, 42, 35, 0.7);
  font-family: var(--font-ui);
  font-weight: 900;
}

.bubble.guess {
  background: var(--paper-deep);
}

.bubble.system {
  background: #fff;
  border-style: dashed;
}

.bubble strong {
  font-family: var(--font-ui);
  font-size: 1.08rem;
}

.action-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.side-art {
  display: grid;
  place-items: center;
  padding: 8px 0 2px;
}

.side-art img {
  width: min(180px, 54vw);
  transform: rotate(2deg);
}

.mini-note {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 2px dashed rgba(49, 42, 35, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
}

.mini-note span {
  color: rgba(49, 42, 35, 0.66);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.mini-note strong {
  font-family: var(--font-ui);
  font-size: 1.75rem;
  line-height: 1;
}

.mini-note p {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.35;
}

.input-form {
  display: grid;
  gap: 8px;
}

.input-form label,
.answer-area-label {
  font-size: 0.9rem;
  font-weight: 900;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.text-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  outline: none;
  background: white;
  box-shadow: inset 2px 2px 0 rgba(49, 42, 35, 0.07);
}

.text-input:focus {
  background: #fffef6;
  box-shadow:
    0 0 0 4px rgba(247, 202, 89, 0.32),
    inset 2px 2px 0 rgba(49, 42, 35, 0.07);
}

.current-question {
  display: grid;
  gap: 12px;
}

.ai-question-card {
  min-height: 110px;
  padding: 14px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: var(--sky);
}

.ai-question-card p {
  margin: 7px 0 0;
  font-family: var(--font-ui);
  font-size: clamp(1.28rem, 3vw, 1.8rem);
  font-weight: 900;
  line-height: 1.22;
}

.ai-question-card small {
  display: block;
  margin-top: 8px;
  font-weight: 900;
}

.mascot-mini {
  width: 68px;
  height: auto;
  color: var(--ink);
  flex: 0 0 auto;
  filter: drop-shadow(0 5px 5px rgba(49, 42, 35, 0.16));
}

.bubble.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-style: dashed;
}

.bubble.thinking span {
  display: block;
  color: rgba(49, 42, 35, 0.68);
  font-family: var(--font-ui);
  font-weight: 900;
}

.ai-pending {
  background: var(--sky);
}

.chat-answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: 20px;
}

.chat-answer-row .answer-button {
  min-width: 112px;
}

.clue-sketch {
  width: min(260px, 100%);
  margin: 3px 0 0 24px;
  padding: 9px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 2px 8px rgba(49, 42, 35, 0.05);
}

.clue-sketch svg {
  width: 100%;
  height: auto;
}

.clue-sketch figcaption {
  color: rgba(49, 42, 35, 0.75);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.25;
}

.sketch-card {
  fill: var(--paper-deep);
  stroke: var(--ink);
  stroke-width: 4;
}

.palette-mint .sketch-card {
  fill: var(--mint);
}

.palette-coral .sketch-card {
  fill: var(--coral);
}

.palette-sky .sketch-card {
  fill: var(--sky);
}

.palette-leaf .sketch-card {
  fill: var(--leaf);
}

.sketch-emoji {
  font-size: 24px;
}

.sketch-line {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-width: 3;
}

.sketch-line.two {
  opacity: 0.5;
}

.doodle-fill,
.doodle-ball,
.portrait-accessory-fill {
  fill: rgba(255, 255, 255, 0.78);
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doodle-ball {
  fill: #fff;
}

.doodle-sun {
  fill: var(--sun);
  stroke: var(--ink);
  stroke-width: 3;
}

.doodle-ink,
.doodle-ink.thin,
.portrait-accessory-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doodle-ink.thin,
.portrait-accessory-line {
  stroke-width: 3;
}

.doodle-ink.fillless {
  fill: none;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 253, 244, 0.62);
  backdrop-filter: blur(3px);
}

.busy-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 12px;
  text-align: center;
  background: linear-gradient(135deg, #fffdf4, #f8fff8);
  box-shadow: 9px 12px 0 rgba(49, 42, 35, 0.22);
  animation: popIn 180ms ease both;
}

.busy-card strong {
  font-family: var(--font-ui);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  line-height: 1.05;
}

.busy-card p {
  margin: 0;
  font-weight: 900;
}

.busy-doodle {
  position: relative;
  display: grid;
  width: 104px;
  height: 104px;
  place-items: center;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 46% 54% 48% 52%;
  background: var(--sky);
  animation: wiggle 950ms ease-in-out infinite;
}

.busy-doodle span {
  font-family: var(--font-ui);
  font-size: 4rem;
  font-weight: 900;
}

.busy-doodle i,
.busy-doodle b {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  transform: rotate(14deg);
  background: var(--sun);
}

.busy-doodle i {
  top: 8px;
  right: -8px;
}

.busy-doodle b {
  bottom: 10px;
  left: -8px;
  background: var(--coral);
}

.busy-meter {
  width: min(260px, 100%);
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 999px;
  background: #fff;
}

.busy-meter span {
  display: block;
  width: 42%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint-strong), var(--sun), var(--coral));
  animation: loadingSwipe 1.1s ease-in-out infinite;
}

.answer-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.answer-button.yes {
  background: var(--mint);
}

.answer-button.no {
  background: var(--coral);
}

.result-screen {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(280px, 1.2fr);
  align-items: center;
  gap: clamp(24px, 5vw, 64px);
  min-height: calc(100vh - 148px);
}

.result-card {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: rgba(255, 253, 244, 0.92);
  box-shadow: 0 16px 48px rgba(49, 42, 35, 0.15);
}

.result-card h1 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(2.5rem, 7vw, 5rem);
  line-height: 0.95;
}

.result-line {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.result-line span {
  font-weight: 900;
  color: rgba(49, 42, 35, 0.64);
}

.result-visual {
  display: grid;
  place-items: center;
}

.result-visual img {
  width: min(86vw, 360px);
  filter: drop-shadow(0 18px 20px rgba(49, 42, 35, 0.16));
}

.portrait-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(88vw, 390px);
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 8px 10px 0 var(--shadow);
  transform: rotate(-0.6deg);
}

.portrait-card.is-compact {
  width: min(380px, calc(100% - 24px));
  margin: 8px 0 0 24px;
  transform: rotate(0.3deg);
  height: auto;
}

.portrait-card svg {
  width: 100%;
  height: auto;
  flex-shrink: 0;
}

.portrait-card figcaption {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-grow: 1;
  gap: 5px;
  text-align: center;
}

.portrait-card figcaption strong {
  font-family: var(--font-ui);
  font-size: 1.55rem;
  line-height: 1;
}

.portrait-card figcaption span {
  color: rgba(49, 42, 35, 0.72);
  font-weight: 900;
  line-height: 1.35;
}

.portrait-bg,
.portrait-hair,
.portrait-neck,
.portrait-outfit,
.portrait-face,
.portrait-eye,
.portrait-nose,
.portrait-mouth,
.portrait-shine,
.portrait-flower {
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.portrait-bg {
  stroke-width: 5;
}

.portrait-hair {
  stroke-width: 5;
}

.portrait-neck,
.portrait-face {
  fill: #ffe5d7;
  stroke-width: 4;
}

.portrait-outfit {
  stroke-width: 5;
}

.portrait-eye,
.portrait-nose,
.portrait-mouth {
  fill: none;
  stroke-width: 4;
}

.portrait-cheek {
  fill: #ffb1a3;
  opacity: 0.85;
}

.portrait-shine {
  fill: var(--sun);
  stroke-width: 4;
}

.portrait-shine.two {
  fill: var(--coral);
}

.portrait-flower {
  fill: #f2a5ff;
  stroke-width: 4;
}

.portrait-accessory {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 4;
}

.portrait-accessory-fill {
  fill: rgba(255, 255, 255, 0.82);
}

.portrait-emoji {
  font-size: 30px;
}

.portrait-name {
  fill: var(--ink);
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: 900;
}

.character-doodle {
  display: grid;
  gap: 12px;
  width: min(88vw, 380px);
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 12px;
  background: rgba(255, 253, 244, 0.92);
  box-shadow: 8px 10px 0 var(--shadow);
  transform: rotate(-1deg);
}

.character-doodle svg {
  width: 100%;
  height: auto;
}

.character-doodle figcaption {
  display: grid;
  gap: 6px;
  text-align: center;
}

.character-doodle figcaption strong {
  font-family: var(--font-ui);
  font-size: 1.7rem;
  line-height: 1;
}

.character-doodle figcaption span {
  font-weight: 900;
  line-height: 1.35;
}

.doodle-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.doodle-tags em {
  padding: 4px 8px;
  border: 2px solid rgba(49, 42, 35, 0.5);
  border-radius: 999px;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.62);
}

.doodle-blob {
  fill: var(--sky);
  stroke: var(--ink);
  stroke-width: 5;
}

.palette-mint .doodle-blob {
  fill: var(--mint);
}

.palette-coral .doodle-blob {
  fill: var(--coral);
}

.palette-sky .doodle-blob {
  fill: var(--sky);
}

.palette-sun .doodle-blob {
  fill: var(--paper-deep);
}

.palette-leaf .doodle-blob {
  fill: var(--leaf);
}

.doodle-shadow,
.doodle-body,
.doodle-arm,
.doodle-foot,
.doodle-belly,
.doodle-head,
.doodle-hair,
.doodle-face,
.doodle-smile,
.doodle-spark {
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doodle-shadow,
.doodle-belly,
.doodle-face,
.doodle-smile {
  fill: none;
}

.doodle-shadow {
  stroke-width: 5;
  opacity: 0.35;
}

.doodle-body {
  fill: #fff;
  stroke-width: 5;
}

.doodle-arm,
.doodle-foot {
  fill: #fff;
  stroke-width: 5;
}

.doodle-belly {
  stroke-width: 4;
}

.doodle-head {
  fill: #fff;
  stroke-width: 5;
}

.doodle-hair {
  fill: #6d5949;
  stroke-width: 5;
}

.doodle-face {
  stroke-width: 9;
}

.doodle-smile {
  stroke-width: 5;
}

.doodle-spark {
  fill: var(--sun);
  stroke-width: 4;
}

.doodle-spark.two {
  fill: var(--coral);
}

.doodle-cheek {
  fill: #ffb1a3;
}

.doodle-emoji {
  font-size: 44px;
}

.doodle-name {
  fill: var(--ink);
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: 900;
}

.challenge-screen {
  display: grid;
  gap: 18px;
}

.challenge-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.challenge-code {
  display: grid;
  gap: 5px;
  min-width: 180px;
  padding: 12px;
  border: 2px dashed var(--ink);
  border-radius: 12px;
  background: var(--paper-deep);
}

.challenge-code span {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.challenge-code strong {
  font-family: var(--font-ui);
  font-size: 1.7rem;
}

.challenge-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(320px, 1.25fr);
  gap: 18px;
}

.challenge-card {
  padding-bottom: 16px;
}

.challenge-card > .secondary-button {
  margin: 0 16px;
}

.challenge-share {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px;
}

.challenge-share p {
  margin: 0;
  font-weight: 900;
  line-height: 1.45;
}

.share-link-box {
  display: grid;
  gap: 9px;
  margin: 0 16px 14px;
  padding: 12px;
  border: 2px dashed rgba(49, 42, 35, 0.52);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.share-link-box a {
  overflow-wrap: anywhere;
  color: var(--sky-strong);
  font-weight: 900;
  text-decoration: none;
}

.challenge-feed {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.empty-challenge {
  padding: 18px;
  border: 1px dashed rgba(49, 42, 35, 0.2);
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 900;
  text-align: center;
  background: rgba(255, 255, 255, 0.64);
}

.challenge-player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 2px solid rgba(49, 42, 35, 0.72);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.76);
}

.challenge-player.is-solved {
  background: var(--mint);
}

.challenge-player strong,
.challenge-player span {
  display: block;
}

.challenge-player strong {
  font-family: var(--font-ui);
  font-size: 1.25rem;
}

.challenge-player span {
  font-weight: 900;
  line-height: 1.35;
}

.challenge-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.challenge-stats span {
  padding: 5px 8px;
  border: 2px solid rgba(49, 42, 35, 0.48);
  border-radius: 999px;
  background: #fff;
  font-size: 0.82rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(49, 42, 35, 0.36);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  gap: 16px;
  width: min(460px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  padding: 18px;
  overflow: auto;
  border: 1px solid rgba(49, 42, 35, 0.15);
  border-radius: 12px;
  background:
    linear-gradient(120deg, rgba(255, 253, 244, 0.97), rgba(248, 255, 248, 0.97)),
    var(--paper);
  box-shadow: 9px 12px 0 rgba(49, 42, 35, 0.22);
  animation: popIn 180ms ease both;
}

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

.modal-head h2 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 2.1rem;
  line-height: 1;
}

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

.leaderboard-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid rgba(49, 42, 35, 0.72);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.76);
}

.leaderboard-rank {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 50%;
  font-family: var(--font-ui);
  font-weight: 900;
  background: var(--sun);
}

.leaderboard-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 900;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  background: var(--paper-deep);
  box-shadow: 0 12px 32px rgba(49, 42, 35, 0.12);
  font-weight: 900;
  animation: popIn 180ms ease both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-10px) rotate(1deg);
  }
}

@keyframes wiggle {
  0%,
  100% {
    transform: rotate(-3deg) translateY(0);
  }
  50% {
    transform: rotate(3deg) translateY(-5px);
  }
}

@keyframes loadingSwipe {
  0% {
    transform: translateX(-105%);
  }
  100% {
    transform: translateX(245%);
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 22px, 720px);
    padding-top: 12px;
  }

  .topbar {
    min-height: 56px;
  }

  .brand-button {
    max-width: calc(100vw - 86px);
    overflow: hidden;
  }

  .brand-button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .home-header {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }

  .home-visual {
    order: -1;
  }

  .home-visual img {
    width: min(62vw, 150px);
  }

  .result-screen,
  .challenge-layout {
    grid-template-columns: 1fr;
  }

  .result-screen {
    align-content: start;
    min-height: 0;
    padding-bottom: 24px;
  }

  .result-visual img {
    width: min(62vw, 250px);
  }

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

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

  .challenge-create-grid,
  .join-grid {
    grid-template-columns: 1fr;
  }

  .challenge-hero,
  .challenge-player {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .challenge-stats {
    justify-content: flex-start;
  }

  .game-top {
    grid-template-columns: 1fr;
  }

  .progress-box {
    min-width: 100%;
  }

  .history-panel {
    min-height: 360px;
  }

  .history-list {
    max-height: 360px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .small-button {
    width: 100%;
  }
}

@media (max-width: 440px) {
  .screen {
    padding-top: 18px;
  }

  .app-title {
    font-size: 3.15rem;
  }

  .game-top,
  .panel-head,
  .action-panel,
  .result-card {
    padding: 14px;
  }

  .result-line {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .leaderboard-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .leaderboard-score {
    grid-column: 2;
  }
}


.single-player-col,
.multiplayer-col {
  display: grid;
  gap: 22px;
}
.home-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 820px) {
  .home-split {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .home-copy {
    font-size: 0.9rem;
  }
  .role-name {
    font-size: 1.2rem;
  }
  .role-card {
    min-height: auto;
    padding: 10px;
  }
  .world-cup-entry strong {
    font-size: 1rem;
  }
  .mini-note strong {
    font-size: 1.2rem;
  }
  .challenge-create-grid {
    grid-template-columns: 1fr;
  }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-select {
  padding: 8px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 12px;
  font-weight: 900;
  background: var(--paper);
  cursor: pointer;
  box-shadow: 0 4px 12px var(--shadow);
}


/* TCG Card Styles */
.collection-screen {
  display: grid;
  gap: 24px;
}
.tcg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  align-items: start;
}
.collection-card-item,
.tcg-card-panel {
  display: grid;
  gap: 12px;
}
.tcg-card {
  position: relative;
  border-radius: 12px;
  padding: 4px;
  background: var(--rarity-color);
  box-shadow: 0 10px 20px rgba(0,0,0,0.15), 0 0 0 1px rgba(255,255,255,0.4) inset;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.tcg-card.rarity-mythic {
  background: linear-gradient(135deg, #FFD700, #FF69B4, #00FFFF);
  animation: shimmer 3s infinite linear;
  background-size: 200% 200%;
}
@keyframes shimmer {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.tcg-card:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 15px 30px rgba(0,0,0,0.25);
}
.tcg-card-inner {
  background: var(--paper);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  overflow: hidden;
}
.tcg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 0.9rem;
}
.tcg-universe {
  color: var(--ink);
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tcg-rarity-chip,
.tcg-rarity-badge {
  background: var(--ink);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-ui);
}
.tcg-rarity-chip {
  flex: 0 0 auto;
  background: var(--rarity-accent, var(--ink));
  color: #1f1710;
  border: 2px solid rgba(49, 42, 35, 0.55);
  box-shadow: 0 2px 0 rgba(49, 42, 35, 0.18);
}
.tcg-rarity-badge {
  flex: 0 0 auto;
  background: var(--rarity-accent, var(--ink));
  color: #1f1710;
  border: 1px solid rgba(49, 42, 35, 0.28);
}
.tcg-art {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--sky);
  border-radius: 12px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  overflow: hidden;
  min-height: 220px;
  aspect-ratio: 4 / 3;
}
.tcg-generated-img {
  width: auto;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  display: block;
}
.tcg-count-medal {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 8px;
  text-align: center;
  color: #fff;
  background: rgba(26, 20, 14, 0.82);
  border: 3px solid var(--rarity-accent, #ffc226);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
}
.tcg-count-medal strong {
  display: block;
  font-size: 1.75rem;
  line-height: 1;
}
.tcg-count-medal span {
  display: block;
  max-width: 58px;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
}
.tcg-generating-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 200px;
  color: var(--ink-light);
  font-size: 0.9rem;
  background: rgba(255,255,255,0.5);
}
.tcg-generating-placeholder svg {
  width: 60px;
  height: 60px;
  margin-bottom: 12px;
  animation: float 2s ease-in-out infinite;
}
.tcg-api-error {
  background: #ffe5e5;
  color: #d32f2f;
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 4px;
  margin-top: 8px;
  word-break: break-word;
  text-align: left;
  border: 1px solid #ffcccc;
}
.tcg-body {
  text-align: center;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tcg-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
}
.tcg-name {
  min-width: 0;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 1.8rem;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.tcg-fact {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}
.rarity-guide {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 2px solid rgba(49, 42, 35, 0.18);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  height: 100%;
}
.rarity-guide-head {
  display: grid;
  gap: 2px;
}
.rarity-guide-head strong {
  font-family: var(--font-ui);
  font-size: 1.05rem;
}
.rarity-guide-head span {
  color: rgba(49, 42, 35, 0.68);
  font-size: 0.86rem;
  line-height: 1.35;
}
.rarity-guide-list {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-grow: 1;
  gap: 6px;
  margin: 6px 0;
}
.rarity-guide-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 4px 6px;
  border-radius: 7px;
  color: rgba(49, 42, 35, 0.76);
}
.rarity-guide-row.is-active {
  background: rgba(255, 194, 38, 0.18);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(49, 42, 35, 0.12);
}
.rarity-guide-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rarity-guide-row em {
  font-style: normal;
  font-size: 0.82rem;
  white-space: nowrap;
}
.rarity-dot {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(49, 42, 35, 0.35);
  border-radius: 50%;
  background: #aeb4bd;
  box-shadow: 0 2px 8px rgba(49, 42, 35, 0.16);
}
.rarity-dot.rarity-uncommon {
  background: #68c96f;
}
.rarity-dot.rarity-rare {
  background: #299bff;
}
.rarity-dot.rarity-epic {
  background: #a75af7;
}
.rarity-dot.rarity-legendary {
  background: #f59b35;
}
.rarity-dot.rarity-mythic {
  background: linear-gradient(135deg, #ffd45a, #ff76b8, #75f6ff);
}
.card-history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.card-history-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid rgba(49, 42, 35, 0.1);
  border-radius: 7px;
  background: #faf9f7;
}
.card-history-item strong {
  font-size: 0.82rem;
}
.card-history-item span {
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.card-history-item em {
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(49, 42, 35, 0.08);
  font-style: normal;
  font-weight: 900;
  font-size: 0.78rem;
}
.tcg-generating {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: var(--font-ui);
  font-size: 1.2rem;
  font-weight: bold;
}


.floating-decorations {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.deco-star {
  position: absolute;
  animation: floaty 4s ease-in-out infinite alternate;
}

.deco-star path {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.deco-sparkle {
  position: absolute;
  animation: pulse 2s ease-in-out infinite alternate;
}

.deco-sparkle path {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.1); opacity: 1; }
}

.app-shell {
  position: relative;
}

/* ==========================================================================
   MOBILE ENGINE ADAPTATION (iOS WebKit & Android Blink) - CSS3 & HTML5 STYLES
   ========================================================================== */

/* Universal Mobile Fixes & Tap Highlight Overrides */
@supports (touch-action: manipulation) {
  button, 
  .role-card, 
  .difficulty-button, 
  .mode-button, 
  .answer-button,
  .brand-button,
  .icon-button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent; /* Disable iOS Safari grey flash */
  }
}

/* Base Body Containment and Overscroll Control */
body {
  overscroll-behavior-y: none; /* Block Android pull-to-refresh on page background */
}

/* Responsive Viewports using Modern CSS3 Dynamic Viewport Units (dvh) */
@supports (height: 100dvh) {
  body, .app-shell {
    min-height: 100dvh;
  }
}

@media (max-width: 480px) {
  .game-rules-box {
    display: none !important;
  }

  /* App Shell Padding using CSS Logical Properties */
  .app-shell {
    width: calc(100% - 16px);
    padding-block: 8px 16px;
    padding-inline: 0;
  }

  /* Compact Topbar for Mobile */
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    min-height: auto;
    padding-inline: 8px;
    gap: 8px;
  }

  .brand-button {
    font-size: 1.15rem !important;
    padding-block: 6px;
    padding-inline: 10px 8px;
  }

  .brand-button img {
    height: 32px !important;
  }

  #rulesSubtitle {
    font-size: 0.78rem !important;
    line-height: 1.25 !important;
    margin-block-start: 4px;
    padding-inline: 4px;
  }

  .topbar-right {
    gap: 6px !important;
  }

  /* Custom Native Overrides for Language Select */
  .lang-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23312a23' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
    padding-inline: 8px 24px; /* Space for customized arrow */
    height: 38px;
    font-size: 0.82rem;
    border-radius: 8px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
    border-radius: 8px;
  }

  /* Compact Main Game Screen grid */
  .game-screen {
    gap: 12px !important;
  }

  .game-top {
    grid-template-columns: 1fr;
    padding-block: 10px !important;
    padding-inline: 12px !important;
    gap: 8px !important;
    background: rgba(255, 253, 244, 0.94);
  }

  .game-title {
    font-size: 1.5rem !important;
  }

  .progress-box {
    width: 100% !important;
    min-width: 100% !important;
  }

  /* Compact Panel & Chat Bubbles adjustments */
  .history-panel {
    min-height: 320px !important;
  }

  .history-list {
    max-height: 260px !important;
    padding-block: 8px !important;
    padding-inline: 10px !important;
    -webkit-overflow-scrolling: touch; /* Enable iOS momentum scrolling */
    overscroll-behavior-y: contain; /* Stop body scrolling when container ends on Android */
  }

  .bubble {
    font-size: 0.92rem;
    padding-block: 8px !important;
    padding-inline: 10px !important;
    max-width: 90% !important;
  }

  .bubble.answer {
    margin-inline-start: 10px !important; /* CSS Logical property margin */
  }

  /* Prevent paint wash blobs from covering the screen */
  .paint-wash {
    width: 10rem;
    height: 10rem;
    filter: blur(28px);
    opacity: 0.25;
  }

  /* Interactive Form and Buttons adaptation */
  .action-panel {
    padding-block: 10px !important;
    padding-inline: 12px !important;
    gap: 8px !important;
  }

  /* CRITICAL: Force minimum font-size of 16px to prevent WebKit input auto-zoom shift */
  .text-input {
    font-size: 16px !important;
    min-height: 44px !important;
    border-radius: 10px;
  }

  .answer-button {
    min-height: 44px !important;
    font-size: 0.92rem !important;
    border-radius: 10px;
  }

  /* Modal transformed into slick Bottom Sheets for iOS/Android */
  .modal-backdrop {
    display: flex;
    align-items: flex-end !important;
    padding-inline: 0 !important;
    padding-block: 0 !important;
  }

  .modal-panel {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important; /* Top roundings only */
    padding-block: 18px env(safe-area-inset-bottom, 32px) !important; /* WebKit Safe Areas notch support */
    padding-inline: 16px !important;
    margin-block-end: 0 !important;
    box-shadow: 0 -8px 24px var(--shadow) !important;
    
    /* Hardware acceleration to prevent drops */
    will-change: transform;
    transform: translate3d(0, 100%, 0);
    animation: slideUpMobile 250ms cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
  }
}

/* Animations using GPU translation */
@keyframes slideUpMobile {
  from {
    transform: translate3d(0, 100%, 0);
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

/* Landscape View adjustments for WebKit notch displays */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding-inline-start: env(safe-area-inset-left);
    padding-inline-end: env(safe-area-inset-right);
  }
}
