:root {
  --bg: #ffffff;
  --ink: #18181b;
  --muted: #6b7280;
  --border: #e5e7eb;
  --blue: #2563eb;
  --red: #ef4444;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button, input { font-family: inherit; }

@keyframes popThenTilt {
  0%   { opacity: 0; transform: translate3d(0, 16px, 0) scale(0.4) rotate(0deg); }
  70%  { opacity: 1; transform: translate3d(0, 0, 0) scale(1.48) rotate(0deg); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1.85) rotate(-15deg); }
}

@keyframes winPopThenTilt {
  0%   { opacity: 0; transform: scale(0.35) rotate(0deg); }
  70%  { opacity: 1; transform: scale(1.12) rotate(0deg); }
  100% { opacity: 1; transform: scale(1.24) rotate(-15deg); }
}

.intro-stage {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: background 0.35s ease;
}

.intro-stage.clear-bg { background: rgba(255, 255, 255, 0); }
.intro-stage.done { display: none; }

.intro-title {
  font-size: clamp(30px, 4.8vw, 46px);
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #ffffff;
  -webkit-text-stroke: 2.5px #111111;
  text-shadow: 0 4px 0 #111111;
  white-space: nowrap;
  opacity: 0;
  transform-origin: center center;
  will-change: transform, opacity;
}

.intro-title.zoom-in {
  animation: popThenTilt 0.36s cubic-bezier(0.12, 0.9, 0.2, 1) forwards;
}

.intro-title.to-corner {
  opacity: 1;
  transition: transform 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.14s ease 0.24s;
}

#arena {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  background: #ffffff;
  cursor: crosshair;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.ready #arena { opacity: 1; }

.corner-brand {
  position: fixed;
  top: 16px;
  left: 20px;
  z-index: 30;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #ffffff;
  -webkit-text-stroke: 1.6px #111111;
  text-shadow: 0 2px 0 #111111;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.corner-brand.visible { opacity: 1; }

.paused-pill {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: #18181b;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  padding: 5px 14px;
  border-radius: 999px;
  display: none;
}

.paused-pill.show { display: block; }

/* Top-Center Online 2P Matchmaking & Friends Bar */
.online-bar {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 5px 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.35s ease;
  white-space: nowrap;
}

body.ready .online-bar { opacity: 1; }

.online-pill-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: #18181b;
  cursor: pointer;
  transition: all 0.14s ease;
}

.online-pill-btn:hover {
  background: #f3f4f6;
}

.online-pill-btn.primary {
  background: #18181b;
  color: #ffffff;
}

.online-pill-btn.primary:hover {
  background: #374151;
}

.online-pill-btn.leave {
  color: #ef4444;
}

.online-pill-btn.leave:hover {
  background: #fef2f2;
}

.online-status {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.mine-badge {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
}

.top-tools {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.ready .top-tools { opacity: 1; }

.circle-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #374151;
  transition: all 0.14s ease;
  padding: 0;
}

.circle-btn:hover {
  border-color: #9ca3af;
  transform: translateY(-1px);
}

.circle-btn.active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

.circle-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.team-pill {
  position: fixed;
  top: 72px;
  z-index: 25;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.team-pill.show { display: inline-flex; }
.team-pill.left { left: 25%; transform: translateX(-50%); }
.team-pill.right { left: 75%; transform: translateX(-50%); }

.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }

.start-btn {
  position: fixed;
  bottom: 136px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  background: #ef4444;
  color: #ffffff;
  border: 2.5px solid #111111;
  border-radius: 999px;
  box-shadow: 0 4px 0 #111111;
  padding: 9px 32px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  -webkit-text-stroke: 0.8px #111111;
  cursor: pointer;
  display: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.start-btn.show { display: inline-block; }
.start-btn:hover { transform: translateX(-50%) translateY(-1px); box-shadow: 0 5px 0 #111111; }
.start-btn:active { transform: translateX(-50%) translateY(2px); box-shadow: 0 2px 0 #111111; }
.start-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.field-card {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 25;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  min-width: 156px;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.field-card.show { display: block; }

.field-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 2px 0;
}

.field-row b { font-weight: 700; color: #111111; font-variant-numeric: tabular-nums; }
.field-row span { color: var(--muted); }

.team-toggle-card {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 30;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.ready .team-toggle-card { opacity: 1; }

.ios-switch {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d1d5db;
  position: relative;
  transition: background 0.2s ease;
}

.ios-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.ios-switch.on { background: #60a5fa; }
.ios-switch.on::after { transform: translateX(16px); }

.dock-shell {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: calc(100vw - 24px);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

body.ready .dock-shell { opacity: 1; }

.tab-bar {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 15px 15px 0 0;
  padding: 6px 8px 4px;
  margin-bottom: -1px;
  position: relative;
  z-index: 2;
}

.cat-tab {
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.14s ease;
}

.cat-tab:hover { color: var(--ink); }

.cat-tab.active {
  background: #eef2f9;
  color: #111111;
  font-weight: 600;
}

.unit-tray {
  pointer-events: auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 0 16px 16px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  max-width: 100%;
}

.unit-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 54px;
  height: 54px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  flex-shrink: 0;
  padding: 2px;
}

.unit-btn:hover { background: #f8fafc; }

.unit-btn.active {
  background: #eff6ff;
  border-color: #93c5fd;
}

.unit-btn canvas {
  width: 40px;
  height: 36px;
  display: block;
}

.unit-btn span {
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

.unit-btn.active span { color: #1e3a8a; }

.banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  background: #18181b;
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  display: none;
}
.banner.show { display: block; }

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  z-index: 150;
}

.modal-bg {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-bg.open { display: flex; }

.modal {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
  max-width: 420px;
  width: 100%;
  padding: 28px;
  text-align: center;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  -webkit-text-stroke: 1.5px #111111;
  text-shadow: 0 3px 0 #111111;
}

.modal h2.win-blue { color: #3b82f6; }
.modal h2.win-red  { color: #ef4444; }
.modal h2.win-draw { color: #e5e7eb; }

.modal-bg.open .modal h2.win-anim {
  display: inline-block;
  margin: 12px 0 28px;
  animation: winPopThenTilt 0.42s cubic-bezier(0.12, 0.9, 0.2, 1) forwards;
}

.modal p {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

.stats-box {
  display: none;
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 12.5px;
  max-height: 210px;
  overflow-y: auto;
}

.btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { border-color: #111111; }
.btn.dark { background: #111111; color: #ffffff; border-color: #111111; }

.stack { display: flex; flex-direction: column; gap: 9px; }
.mp-row { display: flex; gap: 8px; margin-top: 4px; }

.code-in {
  flex: 1;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
  outline: none;
}

.room-box {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding: 14px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1.5px dashed #cbd5e1;
  margin: 10px 0 16px;
  cursor: pointer;
}

@media (max-width: 720px) {
  .field-card { display: none !important; }
  .team-toggle-card { bottom: 132px; right: 12px; }
}
