:root {
  /* Default Theme: Classic Red vs. Blue */
  --p1-grad: linear-gradient(155deg, #ef4444 0%, #b91c1c 65%, #7f1d1d 100%);
  --p1-border: #fca5a5;
  --p1-ghost-bg: rgba(185, 28, 28, 0.18);
  --p1-ghost-border: rgba(239, 68, 68, 0.35);
  --p1-ghost-text: rgba(254, 202, 202, 0.42);
  --p1-arrow: #fca5a5;
  --p1-arrow-stroke: #dc2626;
  --p1-cell-tint: rgba(239, 68, 68, 0.16);

  --p2-grad: linear-gradient(155deg, #3b82f6 0%, #1d4ed8 65%, #1e3a8a 100%);
  --p2-border: #93c5fd;
  --p2-ghost-bg: rgba(29, 78, 216, 0.18);
  --p2-ghost-border: rgba(59, 130, 246, 0.35);
  --p2-ghost-text: rgba(191, 219, 254, 0.42);
  --p2-arrow: #93c5fd;
  --p2-arrow-stroke: #2563eb;
  --p2-cell-tint: rgba(59, 130, 246, 0.16);

  --cell-size: 70px;
  --piece-size: 60px;
}

* { touch-action: manipulation; box-sizing: border-box; }
body { font-family: system-ui, -apple-system, sans-serif; background: #1e293b; color: #f8fafc; display: flex; flex-direction: column; align-items: center; padding: 10px 12px 32px; margin: 0; overflow-x: hidden; min-height: 100vh; }

input, button, select { padding: 7px 11px; border-radius: 6px; border: none; font-size: 13px; font-family: inherit; }
select { background: #334155; color: #f8fafc; border: 1px solid #475569; font-weight: bold; cursor: pointer; }
button { background: #3b82f6; color: white; cursor: pointer; font-weight: bold; transition: transform 0.08s, background 0.15s; }
button:hover { background: #2563eb; }
button:active { transform: scale(0.97); }
button.create { background: #10b981; }
button.create:hover { background: #059669; }
button.ranked { background: linear-gradient(135deg, #f59e0b, #d97706); color: #0f172a; }
button.ranked:hover { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
button.shuffle { background: #f59e0b; color: #0f172a; }
button.shuffle:hover { background: #d97706; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }
button.util { background: #334155; border: 1px solid #475569; color: #f8fafc; }
button.util:hover { background: #475569; }
button:disabled { background: #475569; opacity: 0.55; cursor: not-allowed; }

/* Clean, Minimalist Centered Landing Page */
#home-screen { width: 100%; max-width: 580px; display: flex; flex-direction: column; align-items: center; gap: 13px; margin-top: 6px; }
.hero-logo { width: 290px; max-width: 82vw; height: auto; object-fit: contain; display: block; filter: drop-shadow(0 6px 16px rgba(0,0,0,0.55)); }

.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #0f172a;
  border: 1px solid #334155;
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #cbd5e1;
}
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 8px #4ade80; display: inline-block; }

.nav-stack { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 9px; }
.nav-item {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.28);
}
.nav-item:hover { background: #162238; border-color: #38bdf8; transform: translateY(-1px); }
.nav-item:active { transform: scale(0.98); }
.nav-icon { width: 22px; height: 22px; fill: #38bdf8; flex-shrink: 0; display: block; }
.nav-item.primary-play { border-color: #10b981; }
.nav-item.primary-play .nav-icon { fill: #10b981; }
.nav-item.primary-play:hover { border-color: #34d399; background: #0d2622; }

/* Sub-Views */
.sub-panel { width: 100%; max-width: 580px; background: #0f172a; border: 1px solid #334155; border-radius: 12px; padding: 18px; display: none; flex-direction: column; gap: 13px; box-shadow: 0 10px 25px rgba(0,0,0,0.4); }
.sub-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #1e293b; padding-bottom: 10px; }
.sub-header h3 { margin: 0; font-size: 18px; color: #38bdf8; display: flex; align-items: center; gap: 8px; }
.sub-btn-stack { display: flex; flex-direction: column; gap: 10px; }
.sub-btn-stack button { padding: 13px 16px; font-size: 16px; }
.diff-sub { display: block; font-size: 11px; font-weight: 500; opacity: 0.88; margin-top: 2px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; background: #1e293b; color: #f8fafc; border: 1px solid #475569; padding: 11px 12px; font-size: 15px; }
.join-row button { padding: 11px 18px; font-size: 15px; }

/* Setup Builder Lab (Home Screen "Setups" Tab) */
.builder-slots-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.builder-slot-btn { flex: 1; min-width: 110px; padding: 8px 10px; font-size: 12px; background: #1e293b; border: 1px solid #475569; color: #cbd5e1; }
.builder-slot-btn.active-slot { border-color: #facc15; background: rgba(250, 204, 21, 0.14); color: #fef08a; }
.builder-tray-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; background: #1e293b; padding: 8px; border-radius: 8px; border: 1px solid #334155; }
.tray-slot { height: 48px; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; user-select: none; transition: transform 0.1s, outline 0.1s; }
.tray-slot.available { background: var(--p1-grad); border: 1px solid var(--p1-border); color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.4); }
.tray-slot.available:hover { transform: translateY(-2px); }
.tray-slot.placed { background: var(--p1-ghost-bg); border: 1px dashed var(--p1-ghost-border); color: var(--p1-ghost-text); cursor: default; }
.tray-slot.selected-tray { outline: 3px solid #facc15; transform: scale(1.06); z-index: 2; }
.builder-board-grid { display: grid; grid-template-columns: repeat(6, 52px); grid-template-rows: repeat(3, 52px); gap: 4px; background: #1e293b; padding: 8px; border-radius: 8px; border: 1px solid #334155; justify-content: center; margin: 0 auto; }
.builder-cell { width: 52px; height: 52px; background: #334155; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.builder-cell:hover { background: #3f516b; }
.builder-cell.selected-bcell { outline: 3px solid #facc15; z-index: 2; }
.builder-piece { width: 46px; height: 46px; border-radius: 6px; background: var(--p1-grad); border: 1px solid var(--p1-border); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 3px; }
.builder-piece .rank-badge { font-size: 11px; }
.builder-piece .piece-icon svg { width: 17px; height: 17px; }
.builder-piece .piece-name { font-size: 6.5px; }

/* Settings Form Layout */
.setting-row { display: flex; justify-content: space-between; align-items: center; background: #1e293b; padding: 12px 14px; border-radius: 8px; border: 1px solid #334155; gap: 12px; flex-wrap: wrap; }
.setting-label { font-weight: 700; font-size: 14px; color: #f8fafc; }
.setting-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }

/* Searching Box & Background Queue Banner */
#matchmaking-box { display: none; width: 100%; background: #1e293b; border: 2px solid #38bdf8; border-radius: 10px; padding: 16px; text-align: center; }
#bg-queue-banner {
  display: none;
  width: 100%;
  max-width: 760px;
  background: rgba(14, 116, 144, 0.28);
  border: 1px solid #38bdf8;
  border-radius: 8px;
  padding: 6px 12px;
  margin-bottom: 6px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #bae6fd;
}
.spinner { display: inline-block; width: 15px; height: 15px; border: 3px solid rgba(56, 189, 248, 0.3); border-top-color: #38bdf8; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Rankings & Profile Stats */
.tier-badge { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.tier-bronze { background: #78350f; color: #fde68a; }
.tier-silver { background: #475569; color: #f1f5f9; }
.tier-gold { background: #ca8a04; color: #fef9c3; }
.tier-platinum { background: #0891b2; color: #cffafe; }
.tier-marshal { background: #dc2626; color: #fef2f2; }

.rank-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rank-table th { text-align: left; color: #94a3b8; font-size: 11px; text-transform: uppercase; padding: 6px 8px; border-bottom: 1px solid #334155; }
.rank-table td { padding: 8px; border-bottom: 1px solid #1e293b; }
.rank-table tr:last-child td { border-bottom: none; }

.stat-group { background: #1e293b; padding: 12px; border-radius: 8px; border: 1px solid #334155; }
.stat-group-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; color: #94a3b8; margin-bottom: 8px; text-align: left; }
.stat-row { display: flex; justify-content: space-around; }

/* Revamped About Section */
.about-block { background: #1e293b; padding: 12px 14px; border-radius: 8px; border: 1px solid #334155; font-size: 13px; color: #cbd5e1; line-height: 1.5; }
.about-block h4 { margin: 0 0 8px 0; font-size: 14px; color: #facc15; text-transform: uppercase; letter-spacing: 0.4px; }
.piece-guide-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.piece-guide-card { display: flex; align-items: center; gap: 10px; background: #0f172a; border: 1px solid #334155; border-radius: 7px; padding: 7px 9px; }
.pg-badge { width: 34px; height: 34px; border-radius: 6px; background: var(--p1-grad); border: 1px solid var(--p1-border); display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; }
.pg-badge svg { width: 14px; height: 14px; fill: #fff; }
.pg-badge span { font-size: 10px; font-weight: 900; line-height: 1; margin-top: 1px; }
.pg-info { text-align: left; font-size: 12px; line-height: 1.3; }
.pg-info strong { color: #f8fafc; display: block; }
.pg-info span { color: #94a3b8; font-size: 11px; }
.about-bullets { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }

/* Streamlined Top Gameplay Utility Strip & Unified Setup Bar */
#room-banner { display: none; margin-bottom: 6px; width: 100%; max-width: 760px; }
.utility-strip { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 2px 4px; }
.utility-left, .utility-right { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

/* Single Unified Setup Bar (Actions + Saved Presets in one compact row) */
#unified-setup-bar {
  display: none;
  width: 100%;
  max-width: 760px;
  background: #0f172a;
  border: 1px solid #334155;
  padding: 7px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* Sleek Single-Line Status Pill */
#status-panel {
  display: none;
  width: 100%;
  max-width: 760px;
  min-height: 40px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 6px 14px;
  margin-bottom: 8px;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
#status { font-size: 14px; font-weight: 800; color: #38bdf8; text-align: center; }
#battle-banner { display: none; font-size: 13px; font-weight: 700; color: #facc15; text-align: center; }

#arena { display: none; gap: 18px; align-items: flex-start; justify-content: center; width: 100%; max-width: 820px; }
#sidebar { width: 318px; display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.panel { background: #0f172a; padding: 11px 12px; border-radius: 8px; border: 1px solid #334155; }
.clock-box { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px; background: #1e293b; margin-bottom: 6px; transition: outline 0.15s, background 0.15s; }
.clock-box:last-child { margin-bottom: 0; }
.clock-box.active-clock { outline: 2px solid #facc15; }
.clock-box.ready-clock { outline: 2px solid #10b981; background: rgba(16, 185, 129, 0.12); }
.clock-player-info { display: flex; align-items: center; gap: 6px; }
.ready-pill { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.4px; }
.ready-pill.is-ready { background: #10b981; color: #052e16; }
.ready-pill.not-ready { background: #334155; color: #94a3b8; }
.clock-time { font-family: ui-monospace, monospace; font-size: 19px; font-weight: bold; }
.clock-low { color: #f87171; }
.grave-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #94a3b8; margin-bottom: 8px; font-weight: bold; }

.grave-grid { display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(3, 46px); gap: 4px; }
.grave-slot { height: 46px; border-radius: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; transition: all 0.2s; }
.grave-slot.ghost-red { background: var(--p1-ghost-bg); border: 1px dashed var(--p1-ghost-border); color: var(--p1-ghost-text); }
.grave-slot.ghost-blue { background: var(--p2-ghost-bg); border: 1px dashed var(--p2-ghost-border); color: var(--p2-ghost-text); }
.grave-slot.filled-red { background: var(--p1-grad); border: 1px solid var(--p1-border); color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.grave-slot.filled-blue { background: var(--p2-grad); border: 1px solid var(--p2-border); color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.grave-slot.just-captured { outline: 2px solid #facc15; box-shadow: 0 0 12px #facc15; z-index: 2; transform: scale(1.06); }
.mini-icon svg { width: 17px; height: 17px; fill: currentColor; display: block; }
.mini-rank { font-size: 11px; font-weight: 800; line-height: 1; margin-top: 2px; }

#capture-callout { min-height: 36px; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; font-weight: 700; color: #64748b; background: #0f172a; border: 1px solid #334155; border-radius: 8px; padding: 8px 10px; transition: all 0.2s; }
#capture-callout.active-capture { color: #fef08a; border-color: #facc15; background: rgba(250, 204, 21, 0.1); box-shadow: 0 0 10px rgba(250, 204, 21, 0.15); }

.match-actions { display: flex; gap: 8px; }
.match-actions button { flex: 1; }
.alert-box { background: #1e293b; border: 1px solid #facc15; border-radius: 6px; padding: 8px; margin-bottom: 8px; text-align: center; font-size: 12px; }
.alert-box-btns { display: flex; gap: 6px; margin-top: 6px; }
.alert-box-btns button { flex: 1; padding: 6px 8px; font-size: 12px; }

#board { display: grid; grid-template-columns: repeat(6, var(--cell-size)); grid-template-rows: repeat(8, var(--cell-size)); gap: 3px; background: #0f172a; padding: 8px; border-radius: 10px; box-shadow: 0 10px 25px rgba(0,0,0,0.5); position: relative; }
.cell { width: var(--cell-size); height: var(--cell-size); background: #334155; display: flex; align-items: center; justify-content: center; border-radius: 5px; cursor: pointer; user-select: none; position: relative; }
.cell:hover:not(.lake) { background: #3f516b; }
.cell.lake { background: linear-gradient(135deg, #0284c7, #0369a1); cursor: not-allowed; box-shadow: inset 0 0 8px rgba(0,0,0,0.4); }
.cell.selected { outline: 3px solid #facc15; z-index: 2; }
.cell.last-from-red { background: var(--p1-cell-tint); box-shadow: inset 0 0 0 2px var(--p1-ghost-border); }
.cell.last-from-blue { background: var(--p2-cell-tint); box-shadow: inset 0 0 0 2px var(--p2-ghost-border); }
.cell.attack-target-gold {
  outline: 3px solid #facc15;
  background: rgba(250, 204, 21, 0.24) !important;
  box-shadow: inset 0 0 14px rgba(250, 204, 21, 0.55), 0 0 14px rgba(250, 204, 21, 0.45);
  z-index: 4;
}

.move-arrow { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.move-arrow svg { width: calc(var(--cell-size) * 0.62); height: calc(var(--cell-size) * 0.62); display: block; overflow: visible; }
.arrow-red svg { fill: var(--p1-arrow); stroke: var(--p1-arrow-stroke); stroke-width: 1.5px; filter: drop-shadow(0 0 6px var(--p1-arrow-stroke)) drop-shadow(0 2px 3px rgba(0,0,0,0.8)); }
.arrow-blue svg { fill: var(--p2-arrow); stroke: var(--p2-arrow-stroke); stroke-width: 1.5px; filter: drop-shadow(0 0 6px var(--p2-arrow-stroke)) drop-shadow(0 2px 3px rgba(0,0,0,0.8)); }

.piece { width: var(--piece-size); height: var(--piece-size); border-radius: 7px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px; position: relative; box-shadow: 0 3px 6px rgba(0,0,0,0.45), inset 0 1px 1px rgba(255,255,255,0.35); z-index: 3; }
.piece-red { background: var(--p1-grad); border: 1px solid var(--p1-border); color: #fff; }
.piece-blue { background: var(--p2-grad); border: 1px solid var(--p2-border); color: #fff; }
.piece-clash-glow { box-shadow: 0 0 14px #facc15, 0 4px 10px rgba(0,0,0,0.65); outline: 2px solid #fef08a; }

@keyframes pieceEliminated {
  0%   { transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1) rotate(0deg); opacity: 1; filter: brightness(1); }
  28%  { transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1.14) rotate(-4deg); opacity: 1; filter: brightness(2.1) drop-shadow(0 0 12px #facc15); }
  100% { transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(0.18) rotate(12deg); opacity: 0; filter: brightness(0.6); }
}
.piece-eliminating {
  pointer-events: none;
  z-index: 25;
  animation: pieceEliminated 0.42s cubic-bezier(0.36, 0, 0.66, -0.56) forwards;
}

.piece-top { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.rank-badge { font-size: 13px; font-weight: 900; line-height: 1; text-shadow: 0 1px 2px rgba(0,0,0,0.7); }
.piece-icon svg { width: calc(var(--piece-size) * 0.4); height: calc(var(--piece-size) * 0.4); fill: #f8fafc; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }
.piece-name { font-size: 8px; text-transform: uppercase; letter-spacing: 0.3px; font-weight: 700; opacity: 0.92; line-height: 1; }

.hidden-emblem { font-size: calc(var(--piece-size) * 0.44); font-weight: 900; color: rgba(255, 255, 255, 0.35); margin: auto; line-height: 1; transition: all 0.2s; }
.hidden-emblem.star-lit { color: #facc15; text-shadow: 0 0 10px #facc15, 0 0 18px #f59e0b; transform: scale(1.15); }

/* Modals */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.82); z-index: 50; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #1e293b; border: 1px solid #475569; border-radius: 12px; padding: 22px 24px; width: 100%; max-width: 370px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.65); }
.modal-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; color: #f8fafc; }
.modal-desc { font-size: 14px; color: #cbd5e1; margin-bottom: 16px; line-height: 1.4; }
.modal-btns { display: flex; gap: 10px; justify-content: center; flex-direction: column; }
.modal-btns.row { flex-direction: row; }
.modal-btns button { flex: 1; padding: 10px 14px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; margin-bottom: 12px; }
.auth-form input { width: 100%; background: #0f172a; color: #f8fafc; border: 1px solid #475569; padding: 9px 11px; }

@media (max-width: 780px) {
  :root {
    --cell-size: min(14.5vw, 56px);
    --piece-size: min(12.6vw, 48px);
  }
  body { padding: 8px 8px 24px; }
  .piece-guide-grid { grid-template-columns: 1fr; }
  .builder-board-grid { grid-template-columns: repeat(6, min(13.5vw, 48px)); grid-template-rows: repeat(3, min(13.5vw, 48px)); }
  .builder-cell { width: min(13.5vw, 48px); height: min(13.5vw, 48px); }
  .builder-piece { width: min(12vw, 42px); height: min(12vw, 42px); }
  #status { font-size: 13px; }
  #battle-banner { font-size: 12px; }
  #arena { flex-direction: column-reverse; align-items: center; gap: 12px; }
  #sidebar { width: 100%; max-width: 360px; }
  .piece { padding: 2px 3px; }
  .rank-badge { font-size: 11px; }
  .piece-name { font-size: 7px; }
  .grave-grid { grid-template-rows: repeat(3, 42px); }
  .grave-slot { height: 42px; }
}