/* ==========================================================================
   Chinese Chess Web (CCW) Design System & Layout
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-main: #0f172a;
  --bg-board: #eab308;
  --felt-wood: #b45309;
  --board-grid: #451a03;
  --gold-accent: #f59e0b;
  --gold-light: #fef08a;
  --red-piece: #dc2626;
  --black-piece: #1e293b;
  --text-light: #f8fafc;
  --text-muted: #94a3b8;
  --surface-glass: rgba(30, 41, 59, 0.85);
  --border-glass: rgba(255, 255, 255, 0.12);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

body {
  font-family: "Ubuntu Sans", "Noto Sans TC", -apple-system, sans-serif;
  background-color: var(--bg-main);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(180, 83, 9, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(15, 23, 42, 0.9) 0%, transparent 80%);
  color: var(--text-light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.app-header {
  width: 100%;
  max-width: 600px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glass);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon {
  font-size: 22px;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(90deg, #ffffff, var(--gold-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-name span {
  font-size: 11px;
  background: var(--gold-accent);
  -webkit-text-fill-color: #0f172a;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 900;
  vertical-align: middle;
}

.header-controls {
  display: flex;
  gap: 6px;
}

.btn-subtle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-subtle:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: var(--gold-accent);
}

/* Status Banner */
.status-banner {
  width: 100%;
  max-width: 600px;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.status-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-light);
}

.status-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
}

.pill-turn {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.pill-check {
  background: #dc2626;
  color: #ffffff;
  animation: pulseCheck 1s infinite alternate;
}

.pill-mode {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.pill-eval {
  background: rgba(148, 163, 184, 0.14);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.pill-eval[data-advantage="red"] {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.38);
}

.pill-eval[data-advantage="black"] {
  background: rgba(59, 130, 246, 0.16);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.38);
}

@keyframes pulseCheck {
  0% { transform: scale(1); box-shadow: 0 0 4px #dc2626; }
  100% { transform: scale(1.08); box-shadow: 0 0 12px #dc2626; }
}

/* Main Container */
.game-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 12px 24px;
}

/* Player Profiles */
.player-profile {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.profile-bottom {
  margin-top: 8px;
  margin-bottom: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.avatar-red {
  background: radial-gradient(circle at 35% 35%, #ef4444, #991b1b);
  color: #ffffff;
  border: 2px solid var(--gold-accent);
}

.avatar-black {
  background: radial-gradient(circle at 35% 35%, #334155, #0f172a);
  color: #f8fafc;
  border: 2px solid #cbd5e1;
}

.player-name {
  font-size: 14px;
  font-weight: 700;
}

.captured-pieces {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Board Wrapper & SVG Canvas */
.board-wrapper {
  width: 100%;
  aspect-ratio: 9 / 10;
  max-width: 480px;
  position: relative;
  background: #d97706;
  background-image:
    radial-gradient(circle at 50% 50%, #f59e0b 0%, #b45309 100%);
  border: 8px solid #78350f;
  border-radius: 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  padding: 4px;
  touch-action: manipulation;
}

.chess-board {
  width: 100%;
  height: 100%;
  position: relative;
}

.chess-board svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Action Toolbar */
.action-toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.hint-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.btn-pair {
  display: flex;
  gap: 3px;
  width: 100%;
}

.btn-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 700;
  padding: 10px 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-hint, .btn-automove {
  flex: 1;
  font-size: 11px;
  padding: 8px 0;
}

.btn-hint {
  background: linear-gradient(135deg, #0e7490, #0891b2);
  border-color: #06b6d4;
  color: #cffafe;
}

.btn-hint:hover:not(:disabled) {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
}

.btn-automove {
  background: linear-gradient(135deg, #7c3aed, #9333ea);
  border-color: #a855f7;
  color: #f3e8ff;
}

.btn-automove:hover:not(:disabled) {
  background: linear-gradient(135deg, #9333ea, #a855f7);
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
}

.select-hint-diff {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(6, 182, 212, 0.5);
  color: #cffafe;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 3px 2px;
  text-align: center;
  cursor: pointer;
  outline: none;
}

.select-hint-diff:hover {
  border-color: #06b6d4;
}

.btn-action:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
  border-color: var(--gold-accent);
  transform: translateY(-2px);
}

.btn-danger {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.3);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.3);
  border-color: #ef4444;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: #1e293b;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
}

.modal-header h3 {
  font-size: 18px;
  color: var(--gold-light);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.modal-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-light);
  max-height: 60vh;
  overflow-y: auto;
}

.modal-body h4 {
  color: var(--gold-accent);
  margin-top: 12px;
  margin-bottom: 4px;
}

.setting-label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.setting-label select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-glass);
  color: var(--text-light);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold-accent), #d97706);
  color: #ffffff;
  border: none;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.6);
}

.trophy-icon {
  font-size: 48px;
  text-align: center;
  margin-bottom: 12px;
}

.modal-over {
  text-align: center;
}

.over-msg {
  color: var(--gold-light);
  font-size: 16px;
  margin-bottom: 20px;
}

/* Notation Drawer */
.notation-drawer {
  width: 100%;
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  margin-top: 12px;
  padding: 12px;
  display: none;
}

.notation-drawer.active {
  display: block;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-light);
  margin-bottom: 8px;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.notation-list {
  max-height: 120px;
  overflow-y: auto;
  font-size: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
}

.notation-item {
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.notation-empty {
  grid-column: span 2;
  text-align: center;
  color: var(--text-muted);
  padding: 12px 0;
}
