:root {
  --bg-grad: linear-gradient(135deg, #fff1f5 0%, #fef3c7 50%, #e0f2fe 100%);
  --card-bg: rgba(255, 255, 255, 0.9);
  --card-border: rgba(255, 255, 255, 0.95);
  --text: #3b2314;
  --muted: #7c5c46;
  --accent: #ec4899;
  --accent-2: #f59e0b;
  --shadow: 0 18px 50px rgba(120, 60, 40, 0.14);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'M PLUS Rounded 1c', system-ui, -apple-system, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 10px;
  gap: 6px;
}

.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  flex-shrink: 0;
}

.hud-players {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.hud-player-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 13px;
  background: var(--card-bg);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 16px rgba(120, 60, 40, 0.08);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.hud-player-card.is-ghost {
  opacity: 0.68;
}

.hud-player-card.is-mochi {
  transform: scale(1.04);
  background: #fff1f2;
}

.hud-player-card.is-rush {
  background: #fef9c3;
}

.hud-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.hud-p-info {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.hud-p-name {
  font-size: 13px;
  font-weight: 700;
}

.hud-p-status {
  font-size: 11px;
  color: var(--muted);
}

.hud-p-crowns {
  font-size: 13px;
  font-weight: 700;
  margin-left: 2px;
}

.hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(120, 60, 40, 0.1);
}

.round-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fde68a;
  color: #92400e;
}

.timer-pill {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timer-pill.urgent {
  color: #e11d48;
  animation: pulseUrgent 0.7s ease-in-out infinite alternate;
}

@keyframes pulseUrgent {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.hud-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.hud-btn,
.pill-btn,
.choice-btn,
.secondary-btn {
  appearance: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 12px;
  border: 2px solid rgba(120, 60, 40, 0.12);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(120, 60, 40, 0.08);
  transition: transform 0.12s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.hud-btn:hover,
.pill-btn:hover,
.choice-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.arena-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
}

.arena-frame {
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 118px);
  max-width: calc(100vw - 32px);
  aspect-ratio: 728 / 616;
  background: #eadbc8;
  padding: 7px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  border-radius: 16px;
  display: block;
}

.coach-bar {
  width: min(1040px, 100%);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(120, 60, 40, 0.1);
  box-shadow: 0 6px 18px rgba(120, 60, 40, 0.08);
  font-size: 12.5px;
}

.coach-keys {
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.coach-hint {
  font-weight: 700;
  color: #9a3412;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid var(--accent);
  color: var(--text);
  padding: 7px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 10px 26px rgba(236, 72, 153, 0.22);
  pointer-events: none;
  animation: bannerPop 0.25s ease-out;
}

@keyframes bannerPop {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.95); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(59, 35, 20, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.overlay[hidden],
[hidden] {
  display: none !important;
}

.modal {
  background: rgba(255, 251, 246, 0.97);
  border: 3px solid #ffffff;
  border-radius: 26px;
  box-shadow: 0 28px 80px rgba(59, 35, 20, 0.28);
  padding: 18px 22px;
  max-height: 95vh;
  overflow-y: auto;
}

.lobby-modal {
  width: min(940px, 100%);
}

.small-modal {
  width: min(400px, 100%);
  text-align: center;
}

.result-modal {
  width: min(560px, 100%);
  text-align: center;
}

.modal-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, #fbcfe8, #fde68a);
  display: grid;
  place-items: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: 0 8px 20px rgba(236, 72, 153, 0.22);
}

.modal-top h1 {
  margin: 0;
  font-size: clamp(20px, 2.8vw, 26px);
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.lang-pill {
  margin-left: auto;
  flex-shrink: 0;
}

.howto-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.howto-step {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(236, 72, 153, 0.16);
  border-radius: 16px;
  padding: 8px 11px;
}

.howto-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.howto-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.howto-desc {
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

.slots-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.slot-card {
  background: #ffffff;
  border: 2px solid rgba(120, 60, 40, 0.12);
  border-radius: 18px;
  padding: 10px 10px 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 5px;
  transition: transform 0.15s ease, opacity 0.15s ease, border-color 0.2s ease;
}

.slot-card.is-off {
  opacity: 0.52;
}

.slot-portrait-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.slot-portrait-canvas {
  display: block;
  border-radius: 50%;
}

.char-swap-btn {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(120, 60, 40, 0.18);
  background: #fff7ed;
  color: var(--text);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.char-swap-btn:hover {
  transform: scale(1.1);
  border-color: var(--accent);
}

.slot-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.1;
}

.slot-role-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  color: #ffffff;
}

.slot-animal {
  font-size: 11.5px;
  color: var(--muted);
}

.pattern-mini-grid {
  display: grid;
  grid-template-columns: repeat(5, 9px);
  grid-template-rows: repeat(5, 9px);
  gap: 2px;
  padding: 5px;
  border-radius: 10px;
  background: #fff9f2;
  border: 1px solid rgba(120, 60, 40, 0.1);
}

.pattern-cell {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: rgba(120, 60, 40, 0.08);
}

.pattern-cell.is-origin {
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px #ffffff;
}

.slot-ability {
  font-size: 11px;
  line-height: 1.28;
  padding: 4px 7px;
  border-radius: 9px;
  background: #fff7ed;
  color: #9a3412;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot-keys {
  font-size: 9.8px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
}

.slot-mode-btn {
  margin-top: auto;
  width: 100%;
  appearance: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 11px;
  border: 0;
  cursor: pointer;
  color: #ffffff;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.slot-mode-btn:hover {
  transform: translateY(-1px);
}

.lobby-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.best-of-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.best-of-label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
}

.choice-btn.active {
  background: #fdf2f8;
  border-color: var(--accent);
  color: #be185d;
}

.primary-btn {
  appearance: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 11px 26px;
  border-radius: 15px;
  border: 0;
  background: linear-gradient(135deg, #ec4899, #f59e0b);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(236, 72, 153, 0.3);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(236, 72, 153, 0.38);
}

.error-note {
  margin-top: 8px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: #e11d48;
}

.result-badge {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 6px;
}

.result-modal h2 {
  margin: 0;
  font-size: 28px;
}

.result-sub {
  margin: 6px 0 16px;
  color: var(--muted);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.score-pill {
  background: #ffffff;
  border-radius: 14px;
  padding: 10px 8px;
  border: 2px solid rgba(120, 60, 40, 0.1);
}

.score-pill.is-winner {
  border-color: #f59e0b;
  background: #fffbeb;
}

.awards-section {
  margin: 14px 0 18px;
}

.awards-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
}

.awards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.award-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 12.5px;
  border: 1px solid rgba(120, 60, 40, 0.1);
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

@media (max-width: 820px) {
  .howto-strip {
    grid-template-columns: 1fr;
  }
  .slots-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .coach-bar {
    flex-direction: column;
    border-radius: 14px;
    text-align: center;
  }
  .coach-hint {
    white-space: normal;
    text-align: center;
  }
  .hud-players {
    display: none;
  }
}
