/* ==========================================================================
   MATERIAL 3 EXPRESSIVE CHESS — STYLESHEET
   Font: Roboto Condensed everywhere
   Themes: White, Black (Dark Slate), AMOLED Black (#000000)
   ========================================================================== */

:root {
  --font-main: 'Roboto Condensed', -apple-system, BlinkMacSystemFont, sans-serif;
  --spring-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
  --smooth-easing: cubic-bezier(0.2, 0, 0, 1);
}

/* 1. WHITE THEME (Material 3 Expressive Light) */
html[data-theme="white"] {
  --bg-canvas: #FBF8FF;
  --surface-1: #F2EFF9;
  --surface-2: #E6E1F2;
  --surface-3: #DCD5EC;
  --text-primary: #1B1B21;
  --text-secondary: #47464F;
  --primary: #5850EC;
  --on-primary: #FFFFFF;
  --primary-container: #E1DFFF;
  --on-primary-container: #130463;
  --secondary-container: #E3E0F9;
  --outline: #C8C5D0;
  --board-light: #EFECE6;
  --board-dark: #7D945D;
  --board-frame: #E2DDF0;
  --last-move: rgba(255, 213, 0, 0.45);
  --selected-sq: rgba(88, 80, 236, 0.42);
  --eval-bg: #2A2931;
  --eval-fill: #FFFFFF;
}

/* 2. BLACK THEME (Material 3 Expressive Dark) */
html[data-theme="black"] {
  --bg-canvas: #121318;
  --surface-1: #1E1F26;
  --surface-2: #282933;
  --surface-3: #333440;
  --text-primary: #E4E1E9;
  --text-secondary: #C8C5D0;
  --primary: #C1C1FF;
  --on-primary: #272177;
  --primary-container: #3E3990;
  --on-primary-container: #E1DFFF;
  --secondary-container: #454559;
  --outline: #47464F;
  --board-light: #DEE3E6;
  --board-dark: #6C8799;
  --board-frame: #23242D;
  --last-move: rgba(246, 246, 105, 0.42);
  --selected-sq: rgba(193, 193, 255, 0.45);
  --eval-bg: #2C2D38;
  --eval-fill: #C1C1FF;
}

/* 3. AMOLED BLACK THEME (True #000000 Pitch Black) */
html[data-theme="amoled"] {
  --bg-canvas: #000000;
  --surface-1: #0A0A0E;
  --surface-2: #13131A;
  --surface-3: #1E1E28;
  --text-primary: #F5F4FA;
  --text-secondary: #A5A3B3;
  --primary: #D0BCFF;
  --on-primary: #381E72;
  --primary-container: #4F378B;
  --on-primary-container: #EADDFF;
  --secondary-container: #262335;
  --outline: #252533;
  --board-light: #D8D4E6;
  --board-dark: #54457F;
  --board-frame: #0D0D14;
  --last-move: rgba(208, 188, 255, 0.42);
  --selected-sq: rgba(124, 77, 255, 0.52);
  --eval-bg: #171721;
  --eval-fill: #D0BCFF;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  transition: background-color 0.25s var(--smooth-easing), color 0.25s var(--smooth-easing);
}

/* App Shell — Phone-first Vertical Flex Layout */
.app-shell {
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 6px) 10px env(safe-area-inset-bottom, 8px);
  gap: 6px;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 24px;
  padding: 6px 10px;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 14px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  display: grid;
  place-items: center;
}

.brand-titles h1 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.05;
}

.subtitle-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.03em;
}

/* Theme Segmented Button */
.theme-segmented {
  display: flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--outline);
  gap: 2px;
}

.theme-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.25s var(--spring-easing);
}

.theme-btn .material-symbols-rounded {
  font-size: 15px;
}

.theme-btn.active {
  background: var(--primary);
  color: var(--on-primary);
  transform: scale(1.03);
}

/* Workspace */
.game-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-height: 0;
}

/* Player Cards */
.player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 20px;
  padding: 6px 12px;
  transition: border-color 0.2s, transform 0.2s;
}

.player-card.active-turn {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 14px;
  background: var(--surface-3);
  color: var(--primary);
  display: grid;
  place-items: center;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.rating-chip {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--secondary-container);
  color: var(--text-primary);
}

.captured-strip {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-height: 15px;
  letter-spacing: -1px;
}

.clock-pill {
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  min-width: 68px;
  text-align: center;
}

.player-card.active-turn .clock-pill {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

/* Evaluation Bar */
.eval-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 14px;
  padding: 4px 10px;
}

.eval-bar-track {
  flex: 1;
  height: 8px;
  background: var(--eval-bg);
  border-radius: 999px;
  overflow: hidden;
}

.eval-bar-fill {
  height: 100%;
  background: var(--eval-fill);
  transition: width 0.35s var(--smooth-easing);
}

.eval-readout {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
}

.eval-score {
  font-weight: 800;
  color: var(--primary);
}

.eval-best-line {
  color: var(--text-secondary);
  max-width: 145px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 2D Chessboard Container */
.board-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.board-outer-frame {
  width: min(100%, 46vh);
  aspect-ratio: 1 / 1;
  background: var(--board-frame);
  padding: 6px;
  border-radius: 26px;
  border: 1px solid var(--outline);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

@media (min-height: 740px) {
  .board-outer-frame {
    width: min(100%, 50vh);
  }
}

.chessboard {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 20px;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.square {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.square.light {
  background-color: var(--board-light);
}

.square.dark {
  background-color: var(--board-dark);
}

.square.last-move {
  background-image: linear-gradient(var(--last-move), var(--last-move));
}

.square.selected {
  background-image: linear-gradient(var(--selected-sq), var(--selected-sq));
}

.square.in-check {
  background-image: radial-gradient(circle, rgba(255, 59, 48, 0.85) 0%, rgba(255, 59, 48, 0) 72%);
}

/* Coordinates on Board Edges */
.coord-rank,
.coord-file {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  opacity: 0.82;
}

.coord-rank {
  top: 3px;
  left: 4px;
}

.coord-file {
  bottom: 2px;
  right: 4px;
}

.square.light .coord-rank,
.square.light .coord-file {
  color: var(--board-dark);
}

.square.dark .coord-rank,
.square.dark .coord-file {
  color: var(--board-light);
}

/* Legal Move Indicators */
.legal-dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(20, 20, 28, 0.32);
  pointer-events: none;
}

.legal-capture-ring {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  border: 4px solid rgba(20, 20, 28, 0.34);
  position: absolute;
  pointer-events: none;
}

/* 2D Chess Pieces */
.piece-img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
  transition: transform 0.15s var(--spring-easing);
}

.square.selected .piece-img {
  transform: scale(1.1);
}

/* Move Ribbon Scrubber */
.move-ribbon-card {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 18px;
  padding: 5px 6px;
}

.icon-tonal-btn {
  width: 32px;
  height: 32px;
  border-radius: 12px;
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-tonal-btn:active {
  transform: scale(0.92);
}

.move-chips-scroll {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 4px;
}

.move-chips-scroll::-webkit-scrollbar {
  display: none;
}

.empty-moves-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.move-pair {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.move-num {
  color: var(--text-secondary);
  font-weight: 600;
}

.ply-chip {
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.ply-chip.active {
  background: var(--primary);
  color: var(--on-primary);
}

/* Bottom Navigation Dock */
.bottom-dock {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 26px;
  padding: 6px 8px;
  gap: 4px;
}

.dock-item {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.dock-pill {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  transition: all 0.25s var(--spring-easing);
}

.dock-item.active {
  color: var(--text-primary);
}

.dock-item.active .dock-pill {
  background: var(--primary-container);
  color: var(--on-primary-container);
  width: 56px;
}

/* Modals & Dialogs (M3 Expressive Sheets) */
.m3-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 12px;
}

.m3-dialog-backdrop.hidden {
  display: none;
}

.m3-dialog {
  width: 100%;
  max-width: 480px;
  background: var(--surface-1);
  border: 1px solid var(--outline);
  border-radius: 32px;
  padding: 20px;
  animation: sheetUp 0.3s var(--spring-easing);
}

@keyframes sheetUp {
  from { transform: translateY(40px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.dialog-header h2 {
  font-size: 1.25rem;
  font-weight: 800;
}

.close-dialog-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.section-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 12px 0 6px;
}

.expressive-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-card {
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 22px;
  padding: 12px;
  text-align: left;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  transition: all 0.2s var(--spring-easing);
}

.mode-card.selected {
  border-color: var(--primary);
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.pill-selector-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.choice-pill {
  flex: 1;
  border: 1px solid var(--outline);
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 9px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s var(--spring-easing);
}

.choice-pill.active {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

.m3-btn-filled-expressive {
  border: none;
  background: var(--primary);
  color: var(--on-primary);
  padding: 13px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s var(--spring-easing);
}

.m3-btn-filled-expressive:active {
  transform: scale(0.96);
}

.full-width {
  width: 100%;
  margin-top: 16px;
}

.m3-btn-tonal {
  border: none;
  background: var(--secondary-container);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

/* Multiplayer Room Styles */
.dialog-desc {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 12px;
}

.room-box {
  background: var(--surface-2);
  border-radius: 22px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #F59E0B;
}

.status-dot.connected {
  background: #10B981;
}

.share-url-row,
.join-code-row {
  display: flex;
  gap: 6px;
}

input[type="text"],
textarea {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--outline);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.85rem;
}

.divider-text {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-secondary);
  margin: 14px 0 8px;
}

/* Analysis Studio Toggle */
.analysis-toggle-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 20px;
}

.analysis-toggle-card strong {
  display: block;
  font-size: 0.92rem;
}

.analysis-toggle-card small {
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.m3-switch {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 2px solid var(--outline);
  position: relative;
  cursor: pointer;
}

.m3-switch.active {
  background: var(--primary);
  border-color: var(--primary);
}

.switch-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--on-primary);
  position: absolute;
  top: 2px;
  left: 3px;
  transition: transform 0.2s var(--spring-easing);
}

.m3-switch.active .switch-thumb {
  transform: translateX(21px);
}

/* Promotion Picker */
.promo-dialog h3 {
  text-align: center;
  margin-bottom: 12px;
}

.promo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promo-grid button {
  background: var(--surface-2);
  border: 1px solid var(--outline);
  border-radius: 20px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-primary);
  font-weight: 700;
  cursor: pointer;
}

.promo-grid img {
  width: 48px;
  height: 48px;
}

/* Toast */
.m3-toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s var(--spring-easing);
  z-index: 200;
}

.m3-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
