/* ========== PHASE 6C POLISH: MOTION, BRAND, AND MICRODETAILS ========== */

:root {
  --cv-polish-white: rgba(255, 255, 255, 0.44);
  --cv-polish-ink-glow: rgba(23, 19, 31, 0.38);
  --cv-polish-scanline: rgba(255, 241, 194, 0.08);
  --cv-polish-green: #8bf18e;
  --cv-polish-cyan: #7ed7ef;
  --cv-polish-rose: #ef7d7d;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 7px, var(--cv-polish-scanline) 7px 8px),
    linear-gradient(180deg, rgba(255, 241, 194, 0.08), transparent 28%, rgba(23, 19, 31, 0.2));
  opacity: 0.62;
}

body::after {
  z-index: 0;
  background:
    linear-gradient(90deg, rgba(23, 19, 31, 0.34), transparent 17%, transparent 83%, rgba(23, 19, 31, 0.34)),
    linear-gradient(180deg, rgba(23, 19, 31, 0.22), transparent 18%, transparent 78%, rgba(23, 19, 31, 0.3));
}

.screen {
  isolation: isolate;
}

.screen.active .shell-nav,
.screen.active .shell-header,
.screen.active .menu-header,
.screen.active .shell-page-head,
.screen.active .game-header,
.screen.active .status-bar,
.screen.active .game-badge-strip,
.screen.active .game-controls {
  animation: cv-panel-in 220ms steps(4, end) both;
}

.screen.active .shell-panel,
.screen.active .menu-group,
.screen.active .mode-card,
.screen.active .leaderboard-entry,
.screen.active .leader-row,
.screen.active .quest-row,
.screen.active .unlock-item,
.screen.active .practice-match-row {
  animation: cv-card-in 260ms steps(5, end) both;
}

.screen.active .shell-panel:nth-of-type(2),
.screen.active .mode-card:nth-child(2),
.screen.active .quest-row:nth-child(2),
.screen.active .unlock-item:nth-child(2),
.screen.active .leaderboard-entry:nth-child(2) {
  animation-delay: 30ms;
}

.screen.active .shell-panel:nth-of-type(3),
.screen.active .mode-card:nth-child(3),
.screen.active .quest-row:nth-child(3),
.screen.active .unlock-item:nth-child(3),
.screen.active .leaderboard-entry:nth-child(3) {
  animation-delay: 60ms;
}

.screen.active .shell-panel:nth-of-type(4),
.screen.active .quest-row:nth-child(4),
.screen.active .unlock-item:nth-child(4),
.screen.active .leaderboard-entry:nth-child(4) {
  animation-delay: 90ms;
}

.loading-logo,
.shell-logo,
.menu-logo {
  image-rendering: pixelated;
  filter: drop-shadow(4px 4px 0 var(--cv-ink)) drop-shadow(0 8px 0 rgba(23, 19, 31, 0.18));
  transform-origin: 50% 78%;
}

.loading-logo {
  animation: cv-logo-idle 1450ms steps(2, end) infinite;
}

.shell-brand:hover .shell-logo,
.menu-header:hover .menu-logo {
  transform: translateY(-2px) rotate(-2deg);
}

.shell-panel,
#menu-screen .menu-panel,
.mode-card,
.quest-row,
.leaderboard-entry,
.unlock-item,
.practice-match-row,
.modal {
  position: relative;
  isolation: isolate;
}

.shell-panel::before,
#menu-screen .menu-panel::before,
.mode-card::before,
.quest-row::before,
.leaderboard-entry::before,
.practice-match-row::before,
.modal::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 241, 194, 0.32);
  pointer-events: none;
  z-index: 2;
}

.lobby-hero-panel {
  overflow: hidden;
}

.lobby-hero-panel > * {
  position: relative;
  z-index: 1;
}

.lobby-hero-panel::after {
  content: "";
  position: absolute;
  right: clamp(8px, 1.6vw, 18px);
  bottom: clamp(8px, 1.6vw, 18px);
  width: clamp(84px, 15dvh, 142px);
  aspect-ratio: 1;
  border: 3px solid rgba(23, 19, 31, 0.42);
  background:
    repeating-conic-gradient(from 45deg, rgba(255, 241, 194, 0.42) 0 25%, rgba(23, 19, 31, 0.18) 0 50%) 50% / 25% 25%,
    linear-gradient(180deg, rgba(255, 241, 194, 0.22), rgba(47, 138, 134, 0.22));
  box-shadow: inset 0 0 0 4px rgba(255, 241, 194, 0.12);
  opacity: 0.38;
  transform: rotate(4deg);
}

.btn-play,
.btn-primary,
.btn-secondary,
.btn-compact,
.link-btn,
.shell-nav-btn,
.leaderboard-tab,
.mode-card-action,
#game-screen .ctrl-btn,
#game-screen .btn-settings,
.modal-icon-btn {
  position: relative;
  overflow: hidden;
}

.btn-play::after,
.btn-primary::after,
.mode-card-action::after,
.shell-nav-btn.active::after,
.leaderboard-tab.active::after {
  content: "";
  position: absolute;
  top: -30%;
  bottom: -30%;
  left: -45%;
  width: 28%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.58), transparent);
  transform: skewX(-18deg) translateX(-140%);
  pointer-events: none;
}

.btn-play:hover::after,
.btn-primary:hover::after,
.mode-card:hover .mode-card-action::after,
.shell-nav-btn.active:hover::after,
.leaderboard-tab.active:hover::after {
  animation: cv-shine 620ms steps(7, end);
}

.btn-play {
  animation: cv-cta-pulse 1800ms steps(4, end) infinite;
}

.pixel-chip,
.quest-category,
.wallet-safety-strip span,
.seed-warning,
.game-mode-pill {
  position: relative;
  overflow: hidden;
}

.pixel-chip::after,
.quest-category::after,
.wallet-safety-strip span::after,
.game-mode-pill::after {
  content: "";
  position: absolute;
  inset: 2px 2px auto 2px;
  height: 2px;
  background: rgba(255, 255, 255, 0.38);
  pointer-events: none;
}

.shell-nav-btn.active,
.leaderboard-tab.active,
.quest-category.active,
.diff-card.selected,
.time-card.selected {
  animation: cv-selected-glow 1500ms steps(3, end) infinite;
}

#menu-screen .mode-card {
  overflow: hidden;
  transition: transform 90ms steps(1, end), filter 90ms steps(1, end);
}

#menu-screen .mode-card:hover {
  transform: translateY(-2px);
  filter: saturate(1.08) brightness(1.03);
}

#menu-screen .mode-card.selected {
  animation: cv-mode-selected 1600ms steps(4, end) infinite;
}

#menu-screen .mode-card.selected::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px dashed rgba(23, 19, 31, 0.58);
  pointer-events: none;
}

#menu-screen .mode-card.selected .pixel-chip,
#menu-screen .mode-card.selected .mode-card-action {
  color: var(--cv-ink) !important;
  text-shadow: none !important;
}

#menu-screen .mode-card.selected .mode-card-copy strong,
#menu-screen .mode-card.selected .mode-card-copy > span {
  color: #fff1c2 !important;
  text-shadow: 2px 2px 0 var(--cv-ink);
}

.mode-card[data-mode-kind="server"] .mode-card-preview {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.24) 25%, transparent 25%) 0 0 / 12px 12px,
    linear-gradient(180deg, #69c66d, #2f8546) !important;
}

.mode-card[data-mode-kind="pvp"] .mode-card-preview {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.24) 25%, transparent 25%) 0 0 / 12px 12px,
    linear-gradient(180deg, #7ed7ef, #4e9bd1) !important;
}

.mode-card[data-mode-kind="local"] .mode-card-preview {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.24) 25%, transparent 25%) 0 0 / 12px 12px,
    linear-gradient(180deg, #d59eea, #7256ad) !important;
}

.mode-card-preview {
  position: relative;
  overflow: hidden;
}

.mode-card-preview::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255, 241, 194, 0.34);
  pointer-events: none;
}

.progress-fill,
.loading-bar,
.quest-progress-fill {
  animation: cv-progress-flow 900ms steps(8, end) infinite;
  background-size: 32px 100% !important;
}

.quest-row.completed {
  box-shadow: var(--cv-shadow-small), inset 6px 0 0 var(--cv-polish-green) !important;
}

.quest-row:hover,
.leaderboard-entry:hover,
.leader-row:hover,
.unlock-item:hover,
.practice-match-row:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.profile-avatar-frame {
  overflow: hidden;
}

.profile-avatar-frame::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(255, 241, 194, 0.42);
  pointer-events: none;
}

.cosmetic-preview,
.public-board,
#game-screen .chess-board {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game-screen .game-container {
  animation: cv-battle-in 300ms steps(5, end) both;
}

#game-screen .player-card.active-turn {
  animation: cv-turn-ready 1150ms steps(3, end) infinite;
}

#game-screen .status-bar {
  position: relative;
  overflow: hidden;
}

#game-screen .status-bar::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--cv-gold) 0 12px, var(--cv-green) 12px 24px);
  animation: cv-status-run 900ms steps(8, end) infinite;
}

#game-screen .board-wrapper {
  position: relative;
}

#game-screen .board-wrapper::before {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(255, 241, 194, 0.22);
  pointer-events: none;
}

#game-screen .chess-board {
  position: relative;
}

#game-screen .chess-board::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px) 0 0 / 12.5% 12.5%,
    linear-gradient(0deg, rgba(23, 19, 31, 0.08) 1px, transparent 1px) 0 0 / 12.5% 12.5%;
  pointer-events: none;
  z-index: 2;
}

#game-screen .piece {
  transition: transform 90ms steps(2, end), filter 90ms steps(2, end);
}

#game-screen .square:hover .piece {
  transform: translateY(-2px);
  filter: drop-shadow(0 3px 0 rgba(23, 19, 31, 0.45));
}

.backend-status {
  animation: cv-toast-in 180ms steps(4, end) both;
  border-radius: 0 !important;
  border-width: 3px !important;
}

.modal-overlay.active .modal {
  animation: cv-modal-in 180ms steps(4, end) both;
}

.wallet-option,
.wallet-provider-row {
  transition: transform 90ms steps(1, end), filter 90ms steps(1, end);
}

.wallet-option:hover,
.wallet-provider-row:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.matchmaking-bars span {
  animation: cv-queue-bars 760ms steps(4, end) infinite !important;
}

body[data-active-screen="game"] .backend-status {
  top: auto;
  bottom: max(10px, env(safe-area-inset-bottom));
}

body[data-game-authority="pvp"] #game-connection-label {
  background: var(--cv-polish-cyan);
}

body[data-game-authority="server"] #game-authority-label {
  background: var(--cv-polish-green);
}

body[data-game-authority="local"] #game-authority-label {
  background: #d7b9ef;
}

@keyframes cv-panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cv-card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cv-logo-idle {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes cv-shine {
  from {
    transform: skewX(-18deg) translateX(-140%);
  }
  to {
    transform: skewX(-18deg) translateX(540%);
  }
}

@keyframes cv-cta-pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.08);
  }
}

@keyframes cv-selected-glow {
  0%,
  100% {
    box-shadow: var(--cv-shadow-small) !important;
  }
  50% {
    box-shadow: 0 3px 0 var(--cv-ink), 0 0 0 3px rgba(255, 241, 194, 0.28) !important;
  }
}

@keyframes cv-mode-selected {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.05) saturate(1.1);
  }
}

@keyframes cv-progress-flow {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 32px 0;
  }
}

@keyframes cv-battle-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes cv-turn-ready {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.1);
  }
}

@keyframes cv-status-run {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 24px 0;
  }
}

@keyframes cv-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes cv-modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cv-queue-bars {
  0%,
  100% {
    transform: translateY(0);
    filter: brightness(1);
  }
  50% {
    transform: translateY(-5px);
    filter: brightness(1.18);
  }
}

@media (max-width: 560px) {
  .shell-nav {
    width: 100%;
    max-width: 100%;
    gap: 4px;
    padding: 5px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .shell-nav::-webkit-scrollbar {
    display: none;
  }

  .shell-nav-btn {
    min-width: 60px;
    padding: 6px 4px;
    font-size: 0.46rem;
  }

  .shell-content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-left: max(7px, env(safe-area-inset-left));
    padding-right: max(7px, env(safe-area-inset-right));
  }

  .shell-header {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .shell-brand {
    max-width: 100%;
  }

  .shell-brand h1 {
    font-size: 1.05rem;
  }

  .shell-actions {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
    gap: 8px;
    overflow: hidden;
  }

  .shell-actions .btn-compact {
    width: 100%;
    min-width: 0;
    padding: 9px 6px;
    font-size: 0.76rem;
    white-space: nowrap;
  }

  .panel-label,
  .menu-label {
    font-family: var(--font-pixel-ui);
    font-size: 0.62rem;
    font-weight: 900;
    line-height: 1.1;
    text-shadow: none;
  }

  .dashboard-grid,
  .pixel-grid-dashboard {
    grid-template-rows: 1.18fr 0.82fr 0.95fr 0.95fr 0.95fr;
    gap: 7px;
  }

  .lobby-hero-panel {
    padding: 10px;
  }

  .lobby-hero-panel::after {
    width: 86px;
    opacity: 0.22;
  }

  .lobby-hero-panel h2 {
    font-size: clamp(1.65rem, 5.8dvh, 2.2rem);
    margin-bottom: 3px;
  }

  .lobby-hero-actions {
    grid-template-columns: 1fr;
    gap: 6px;
    margin: 4px 0 5px;
  }

  .lobby-wallet-cta,
  .lobby-safety-row,
  .lobby-hero-panel .trust-note,
  #dashboard-cosmetics,
  .rank-card .trust-note,
  .leaderboard-preview .trust-note,
  .recent-practice-panel .trust-note,
  .next-unlock-panel .unlock-meta,
  .next-unlock-panel .trust-note {
    display: none !important;
  }

  .profile-summary,
  .rank-card,
  .next-unlock-panel,
  .quests-preview,
  .leaderboard-preview,
  .recent-practice-panel {
    padding: 9px;
  }

  .profile-summary .summary-row {
    gap: 7px;
    align-items: center;
  }

  .profile-summary .profile-avatar {
    width: 46px;
    height: 46px;
  }

  .profile-summary h2,
  .rank-card h2,
  .lobby-status-card h2 {
    font-size: 0.74rem;
    line-height: 1.25;
    margin-bottom: 3px;
  }

  .level-line,
  .progress-track {
    margin-top: 4px;
  }

  .profile-summary .level-line span:last-child,
  .profile-summary .progress-track,
  .recent-practice-panel .practice-match-actions .mini-action-btn {
    display: none !important;
  }

  .profile-summary .level-line {
    justify-content: flex-start;
  }

  .recent-practice-panel .practice-match-actions {
    justify-content: flex-start;
  }

  .quest-row,
  .leaderboard-entry,
  .practice-match-row,
  .unlock-preview {
    padding: 7px;
    gap: 6px;
  }

  .quests-preview .quest-row:nth-child(n+2),
  .leaderboard-preview .leaderboard-entry:nth-child(n+2),
  .recent-practice-panel .practice-match-row:nth-child(n+2) {
    display: none;
  }

  .quest-marker {
    width: 32px;
    height: 32px;
  }

  .quest-reward {
    padding: 5px 6px;
    font-size: 0.58rem;
  }

  .screen.active .shell-panel,
  .screen.active .menu-group,
  .screen.active .mode-card {
    animation-duration: 180ms;
  }

  body[data-active-screen="game"] .backend-status {
    bottom: max(6px, env(safe-area-inset-bottom));
  }
}

@media (max-height: 780px) and (min-width: 901px) {
  #menu-screen .menu-header {
    margin-bottom: 8px;
  }

  #menu-screen .menu-panel {
    gap: 8px;
  }

  #menu-screen .btn-play {
    margin-top: 10px !important;
    margin-bottom: 14px !important;
    padding: 13px 16px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
