:root {
  --bg: #060911;
  --surface: #0e1424;
  --surface-hover: #151f38;
  --border: #1a2642;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.25);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.15);
  --orange: #f97316;
  --red: #ef4444;
  --yellow: #facc15;
  --text: #f8fafc;
  --muted: #64748b;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0.75rem 0.5rem 2.5rem 0.5rem;
}

.viewport {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  padding-left: max(0.4rem, env(safe-area-inset-left));
  padding-right: max(0.4rem, env(safe-area-inset-right));
}

/* Nav */
.app-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem 0;
  flex-wrap: wrap;
  gap: 5px;
}


.brand-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-title span {
  color: var(--accent);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-icon-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  transition: all 0.15s;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-nav:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.relative-rank-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--yellow);
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.1);
  cursor: pointer;
  min-height: 44px;
}

/* Modos */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}

.mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.65rem 0.3rem;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 44px;
}

.mode-card .m-icon {
  font-size: 1.25rem;
}

.mode-card .m-title {
  font-size: 0.75rem;
  font-weight: 700;
}

.mode-card.active {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
}

/* Sub-Controles */
.sub-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
}

.sub-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.chip-group {
  display: flex;
  gap: 0.3rem;
}

.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  min-width: 38px;
}

.chip.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* HUD Deck */
.hud-deck {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: 0.4rem;
}

.hud-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hud-tag {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

.hud-data {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.scale-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0.25rem;
  width: 75px;
}

.scale-beam {
  width: 100%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: rotate(0deg);
}

.scale-fulcrum {
  font-size: 0.6rem;
  line-height: 0.6rem;
  color: var(--muted);
}

/* Guias Verticais */
.axis-guide {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 0.2rem;
  border-radius: 6px;
}

.axis-guide.lighter {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.05);
}

.axis-guide.heavier {
  color: var(--orange);
  background: rgba(249, 115, 22, 0.05);
}

/* Mesa de Ordenação Fixa */
.order-board {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, background-color 0.2s ease;
  min-height: 62px;
}

.card:hover {
  background: var(--surface-hover);
}

/* Destaque quando selecionado para troca */
.card.selected-for-swap {
  border-color: var(--yellow) !important;
  background: rgba(250, 204, 21, 0.12) !important;
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.25) !important;
  transform: scale(1.02);
}

.c-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
}

.c-pos {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  background: var(--bg);
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  min-width: 2rem;
  text-align: center;
}

.card.selected-for-swap .c-pos {
  background: var(--yellow);
  color: #000;
}

.c-icon {
  font-size: 1.45rem;
  flex-shrink: 0;
}

.c-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.25;
}

.c-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.volume-preview {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--yellow);
}

.scale-box-render {
  background: rgba(250, 204, 21, 0.3);
  border: 1px solid var(--yellow);
  border-radius: 2px;
}

.c-weight-val {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--green);
  background: var(--green-glow);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.c-status {
  font-size: 0.8rem;
  font-weight: 800;
}

.c-status.correct { color: var(--green); }
.c-status.heavier { color: var(--orange); }
.c-status.lighter { color: var(--accent); }

/* Botões de Ação Direcional (Área de toque de 48px para mobile) */
.btn-arrow-grp {
  display: flex;
  gap: 4px;
}

.btn-arr {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, transform 0.1s;
}

.btn-arr:active {
  background: var(--accent);
  color: #000;
  transform: scale(0.95);
}

.feedback-alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.feedback-alert.success {
  border-color: var(--green);
  background: var(--green-glow);
  color: #86efac;
}

.feedback-alert.game-over {
  border-color: var(--red);
  color: #fca5a5;
}

/* Botões de Ação Inferiores */
.dock-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.btn {
  flex: 1;
  border-radius: var(--radius);
  border: none;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
}

.btn-action {
  min-height: 74px;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 40%, #0c4a6e 100%);
  color: #f8fafc;
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 
    0 10px 24px -4px rgba(2, 132, 199, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 1px 1px rgba(255, 255, 255, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.btn-action-main {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-action-sub {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(224, 242, 254, 0.85);
}

.btn-action:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.btn-action:active:not(:disabled) {
  transform: translateY(2px) scale(0.985);
}

.btn-action:disabled {
  background: #131b2e;
  border-color: #1e293b;
  color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-next {
  background: var(--yellow);
  color: #000;
  min-height: 74px;
}

.btn-share {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
  min-height: 74px;
}

.btn-share-modal {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: #031525;
  font-weight: 800;
  width: 100%;
  padding: 0.8rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.25);
}

/* Painel de Estatísticas Resumidas */
.stats-panel {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.1rem;
}

.stat-l {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
}

.stat-v {
  font-size: 0.85rem;
  font-weight: 800;
  color: #fff;
}

/* Modais */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

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

.modal-header h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.quick-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  text-align: center;
}

.kpi-box {
  background: var(--bg);
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.kpi-val {
  font-size: 1.25rem;
  font-weight: 800;
  display: block;
}

.kpi-lbl {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
}

.histogram-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hist-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.hist-bars-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.hist-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.hist-num {
  width: 1.2rem;
  color: var(--muted);
}

.hist-track {
  flex: 1;
  background: var(--bg);
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
  display: flex;
}

.hist-fill {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.hist-fill.has-val {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.hist-fill.loss-fill {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.unplayed-info {
  background: var(--bg);
  border: 1px dashed var(--border);
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.unplayed-info strong {
  color: var(--yellow);
}

/* Modal de Ranking */
.rank-modal-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.3rem;
  background: var(--bg);
  padding: 0.25rem;
  border-radius: 8px;
}

.rank-tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.4rem;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.rank-tab-btn.active {
  background: var(--surface);
  color: #fff;
  border: 1px solid var(--border);
}

.grank-total {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.podium-list, .neighborhood-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.8rem;
}

.rank-row.is-user {
  border-color: var(--accent);
  background: var(--surface-hover);
  box-shadow: 0 0 10px var(--accent-glow);
}

.rank-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rank-tag {
  font-weight: 900;
  min-width: 1.5rem;
}

.rank-tag.gold { color: #facc15; }
.rank-tag.silver { color: #e2e8f0; }
.rank-tag.bronze { color: #f97316; }
.rank-tag.regular { color: var(--muted); }

.rank-pos-name {
  font-weight: 700;
}

.rank-row.is-user .rank-pos-name {
  color: var(--accent);
  font-weight: 800;
}

.rank-score {
  font-weight: 800;
  color: var(--yellow);
}

.separator-line {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0.4rem 0;
}

.separator-line::before, .separator-line::after {
  content: '';
  flex: 1;
  border-bottom: 1px dashed var(--border);
}

.separator-line span {
  padding: 0 0.5rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--accent);
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 10000;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  animation: toastFade 0.25s ease;
}

@keyframes toastFade {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.hidden {
  display: none !important;
}