/* 3·2·1 Futbol iOS Design System Match (Theme.swift & Components.swift)
 * Flat, zero-shadow buttons, uppercase rounded typography, seamless WKWebView integration */

:root {
  --bg-top: #2F4BB0;
  --bg: #1B2D6E;
  --bg-deep: #10194A;
  --purple: #7B3FE4;
  --yellow: #FFD23F;
  --blue: #3B8BFF;
  --green: #35D07F;
  --red: #FF5470;
  --ink: #1D2B64;
  --muted: #B8C4EE;
  --panel-fill: rgba(255, 255, 255, 0.08);
  --panel-border: rgba(255, 255, 255, 0.12);
  --ghost-fill: rgba(255, 255, 255, 0.14);
  --font: 'Nunito', ui-rounded, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Baloo 2', 'Nunito', ui-rounded, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 55%, var(--bg-deep) 100%);
  color: #FFFFFF;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
}

body.in-match {
  background: var(--bg-deep);
}

#app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  background: transparent;
  border-radius: 0;
  border: none;
  overflow: hidden;
}

/* ==================== SCREENS ==================== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(18px + env(safe-area-inset-bottom, 0px));
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.screen > * {
  width: 100%;
  max-width: 480px;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.screen-match {
  padding: 0;
  align-items: stretch;
}

.screen-match > * {
  max-width: none;
}

/* ==================== TOPBAR ==================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.screen-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #FFFFFF;
}

.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  padding: 6px 13px;
  height: 38px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.92rem;
  color: var(--yellow);
}

.coin-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--yellow);
  display: inline-block;
  flex-shrink: 0;
}

.coin-dot-sm {
  width: 9px;
  height: 9px;
  vertical-align: middle;
}

.coin-dot-dark {
  background: var(--ink);
}

/* ==================== iOS BigButtonStyle & PillButtonStyle (FLAT, ZERO SHADOW, UPPERCASE) ==================== */
.btn {
  appearance: none;
  border: none;
  outline: none;
  box-shadow: none;
  font-family: var(--font);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 16px;
  height: 46px;
  padding: 0 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #FFFFFF;
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}

.btn-lg {
  width: 100%;
  height: 56px;
  font-size: 18px;
  border-radius: 16px;
}

.btn:active:not(:disabled) {
  opacity: 0.7;
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-yellow {
  background: var(--yellow);
  color: var(--ink);
}

.btn-blue {
  background: var(--blue);
  color: #FFFFFF;
}

.btn-green {
  background: var(--green);
  color: #FFFFFF;
}

.btn-ghost {
  background: var(--ghost-fill);
  color: #FFFFFF;
}

.btn-danger {
  background: var(--red);
  color: #FFFFFF;
}

/* PillButtonStyle (Components.swift: Capsule, height 34, font 13 heavy rounded, flat) */
.btn-pill {
  appearance: none;
  border: none;
  outline: none;
  box-shadow: none;
  font-family: var(--font);
  font-weight: 900;
  font-size: 12.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 999px;
  height: 34px;
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: #FFFFFF;
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}

.btn-pill:active:not(:disabled) {
  opacity: 0.7;
  transform: scale(0.97);
}

.btn-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-pill-yellow {
  background: var(--yellow);
  color: var(--ink);
}

.btn-pill-blue {
  background: var(--blue);
  color: #FFFFFF;
}

.btn-pill-green {
  background: var(--green);
  color: #FFFFFF;
}

.btn-pill-ghost {
  background: var(--ghost-fill);
  color: #FFFFFF;
}

.btn-link {
  appearance: none;
  border: none;
  box-shadow: none;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}

.btn-link:active {
  opacity: 0.7;
  transform: scale(0.97);
}

/* Circular translucent icon buttons matching Html5GameView.swift */
.icon-btn {
  appearance: none;
  border: none;
  box-shadow: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ghost-fill);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-weight: 900;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:active {
  opacity: 0.7;
  transform: scale(0.95);
}

.icon-btn-sm {
  width: 34px;
  height: 34px;
}

.icon-btn-sm svg {
  width: 16px;
  height: 16px;
}

/* PanelCard surface matching Components.swift */
.panel-card {
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  border-radius: 22px;
  padding: 14px;
}

/* ==================== 1. MAIN MENU & 3·2·1 LOGO ==================== */
.menu-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}

.logo-321 {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.logo-tiles {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo-tile {
  width: 48px;
  height: 54px;
  border-radius: 12px;
  background: #FFFFFF;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 32px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.logo-tile.t1 { transform: rotate(-8deg) translateY(4px); }
.logo-tile.t2 { transform: rotate(3deg) translateY(-3px); }
.logo-tile.t3 { transform: rotate(9deg) translateY(4px); }

.logo-wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 34px;
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--yellow);
  text-transform: uppercase;
}

.logo-sub {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-canvas {
  width: 100%;
  max-width: 320px;
  height: 175px;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.menu-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.menu-row-2 .btn {
  padding: 0 10px;
  font-size: clamp(12px, 3.5vw, 15px);
  white-space: nowrap;
}

/* ==================== 2. SHOP ==================== */
.shop-grid {
  flex: 1;
  margin-top: 14px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-right: 2px;
  align-content: start;
}

.shop-grid::-webkit-scrollbar {
  width: 4px;
}

.shop-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.puck-card {
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  border-radius: 18px;
  padding: 11px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.puck-card.selected {
  border-color: var(--yellow);
  background: rgba(255, 210, 63, 0.12);
}

.puck-card-name {
  font-size: 12px;
  font-weight: 800;
  color: #FFFFFF;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.puck-card-btn {
  width: 100%;
  height: 30px;
  font-size: 11.5px;
  padding: 0 8px;
}

/* ==================== 3. STADIUM SELECT ==================== */
.stadium-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

.stadium-title-wrap {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stadium-tier-pill {
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--yellow);
  padding: 4px 12px;
  border-radius: 999px;
}

.stadium-name {
  font-family: var(--font-display);
  font-size: 1.65rem;
  line-height: 1.05;
  letter-spacing: 0.03em;
  font-weight: 800;
  color: #FFFFFF;
  text-align: center;
  text-transform: uppercase;
}

.stadium-carousel {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.carousel-arrow {
  appearance: none;
  border: none;
  box-shadow: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ghost-fill);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}

.carousel-arrow svg {
  width: 20px;
  height: 20px;
}

.carousel-arrow:active {
  opacity: 0.7;
  transform: scale(0.94);
}

.stadium-canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stadium-preview-canvas {
  width: 100%;
  max-width: 280px;
  height: 205px;
}

.lock-badge {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(16, 25, 74, 0.88);
  border: 2px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.lock-badge svg {
  width: 24px;
  height: 24px;
}

.dots-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.24);
  transition: transform 0.15s ease, background 0.15s ease;
}

.dot.active {
  background: var(--yellow);
  transform: scale(1.3);
}

.info-card {
  width: 100%;
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  border-radius: 22px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.92rem;
  font-weight: 700;
}

.info-row span:first-child {
  color: var(--muted);
}

.info-val {
  font-weight: 900;
  color: #FFFFFF;
}

.info-val.gold {
  color: var(--yellow);
}

.info-flavor {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--yellow);
  border-radius: 999px;
}

.screen-footer {
  flex-shrink: 0;
  padding-top: 12px;
}

/* ==================== 4. TACTICS ==================== */
.tactics-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: 12px;
  min-height: 0;
  margin-top: 8px;
}

.team-badge-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  border-radius: 22px;
  padding: 10px 14px;
}

.team-badge-meta {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.team-badge-name {
  font-size: 1.05rem;
  font-weight: 900;
}

.formation-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.formation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.formation-label {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.formation-row {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.formation-row::-webkit-scrollbar {
  height: 4px;
}

.formation-row::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.formation-item {
  flex-shrink: 0;
  background: var(--panel-fill);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.12s ease, opacity 0.08s ease;
}

.formation-item:active {
  opacity: 0.75;
}

.formation-item.selected {
  border-color: var(--yellow);
  background: rgba(255, 210, 63, 0.14);
}

.formation-item canvas {
  border-radius: 8px;
  display: block;
}

.formation-item-tag {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--muted);
}

.formation-item.selected .formation-item-tag {
  color: var(--yellow);
}

/* ==================== 5. CUSTOM EDITOR ==================== */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.editor-hint {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.editor-pitch-frame {
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid var(--panel-border);
}

#editor-canvas {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  cursor: grab;
}

#editor-canvas:active {
  cursor: grabbing;
}

/* ==================== 6. VS SPLASH ==================== */
.vs-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.vs-matchup {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 10px;
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  border-radius: 22px;
  padding: 20px 12px;
}

.vs-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.vs-label {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
}

.vs-blue .vs-label {
  background: var(--blue);
  color: #FFFFFF;
}

.vs-red .vs-label {
  background: var(--red);
  color: #FFFFFF;
}

.vs-badge {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--yellow);
  letter-spacing: 0.05em;
}

/* ==================== 7. ACTIVE MATCH & HUD ==================== */
#match-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.match-hud {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 520px);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.scoreboard {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 25, 74, 0.88);
  border: 1.5px solid var(--panel-border);
  border-radius: 16px;
  padding: 6px 10px;
  gap: 8px;
}

.sb-side {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-score {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  min-width: 22px;
  text-align: center;
}

.sb-p1 .sb-score {
  color: #7dd3fc;
}

.sb-p2 .sb-score {
  color: #fda4af;
}

.sb-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.turn-pill {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #FFFFFF;
  white-space: nowrap;
}

.timer-track {
  width: 100%;
  max-width: 120px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--yellow);
  transition: width 0.08s linear;
}

.timer-fill.warn {
  background: var(--red);
}

.pause-btn {
  pointer-events: auto;
  background: rgba(16, 25, 74, 0.88);
  border: 1.5px solid var(--panel-border);
  flex-shrink: 0;
}

.reaction-bubble {
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--bg-deep);
  border: 1.5px solid var(--panel-border);
  border-radius: 14px;
  padding: 4px 9px;
  font-size: 1.15rem;
  animation: popIn 0.2s ease;
}

.match-hint {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 460px);
  background: var(--purple);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 800;
  color: #FFFFFF;
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 48, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
  animation: fadeIn 0.15s ease;
}

.modal-card {
  width: 100%;
  max-width: 356px;
  background: var(--bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 22px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.16s ease;
}

.modal-sm {
  max-width: 320px;
}

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

.modal-head h3 {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--yellow);
}

.modal-center-title {
  font-family: var(--font-display);
  text-align: center;
  font-size: 1.25rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--yellow);
}

.modal-text {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
}

.modal-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tut-canvas-wrap {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 1.5px solid var(--panel-border);
}

#tut-canvas {
  width: 100%;
  height: auto;
  display: block;
}

.tut-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Result Modal */
.result-badge {
  font-size: 2.5rem;
  text-align: center;
}

.result-title {
  font-family: var(--font-display);
  text-align: center;
  font-size: 1.7rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--yellow);
}

.result-score {
  font-family: var(--font-display);
  text-align: center;
  font-size: 1.9rem;
  font-weight: 800;
  color: #FFFFFF;
}

.result-reward {
  text-align: center;
  background: var(--panel-fill);
  border: 1.5px solid var(--panel-border);
  color: var(--yellow);
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 900;
  font-size: 0.95rem;
}

.result-unlock {
  text-align: center;
  background: var(--green);
  color: #FFFFFF;
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 900;
  font-size: 0.88rem;
}

/* Toast (matches ArcadeToast in ArcadeComponents.swift) */
.toast {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 440px);
  background: var(--red);
  color: #FFFFFF;
  padding: 11px 16px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 60;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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