/* === Stats Panel === */
.stats-panel {
  position: fixed;
  left: 12px;
  top: 56px;
  bottom: 80px;
  width: 280px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 30;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.stats-panel.visible { display: flex; }

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

.stats-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.stats-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.stats-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.stats-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 8px 6px;
}

.stat-label {
  font-size: 0.55em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
}

.stat-value {
  font-size: 0.9em;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Tilt Meter */
.tilt-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
}

.tilt-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.tilt-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background 0.5s ease;
}

.tilt-value {
  font-size: 0.6em;
  font-weight: 700;
  color: var(--text2);
  min-width: 36px;
  text-align: right;
}

/* P&L Chart */
.pnl-chart {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pnl-svg {
  width: 100%;
  height: 60px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
}

/* === Tilt Overlay (urgent warning) === */
.tilt-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(233, 69, 96, 0.08);
  z-index: 50;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  backdrop-filter: blur(4px);
}

.tilt-overlay.visible { display: flex; }

.tilt-card {
  background: rgba(10, 10, 15, 0.95);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 28px 36px;
  max-width: 420px;
  text-align: center;
}

.tilt-card h2 {
  color: var(--accent);
  font-size: 1.3em;
  margin-bottom: 12px;
}

.tilt-card p {
  color: var(--text2);
  font-size: 0.85em;
  line-height: 1.6;
  margin-bottom: 16px;
}

.tilt-tips {
  list-style: none;
  padding: 0;
  text-align: left;
}

.tilt-tips li {
  font-size: 0.75em;
  color: var(--text);
  padding: 4px 0 4px 16px;
  position: relative;
}

.tilt-tips li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.tilt-dismiss {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 0.85em;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}

.tilt-dismiss:hover {
  background: var(--accent-hover);
}

/* === Ranges Panel === */
.ranges-panel {
  position: fixed;
  left: 12px;
  top: 56px;
  bottom: 80px;
  width: 340px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 32;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.ranges-panel.visible { display: flex; }

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

.ranges-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.ranges-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.ranges-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.ranges-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* === Bankroll Panel === */
.bankroll-panel {
  position: fixed;
  left: 12px;
  top: 56px;
  bottom: 80px;
  width: 280px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 31;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.bankroll-panel.visible { display: flex; }

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

.bankroll-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.bankroll-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.bankroll-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.bankroll-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* === Leak Finder Panel === */
.leaks-panel {
  position: fixed;
  right: 12px;
  top: 56px;
  bottom: 80px;
  width: 320px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 31;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.leaks-panel.visible { display: flex; }

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

.leaks-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.leaks-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.leaks-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.leaks-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* === Quiz Panel === */
.quiz-panel {
  position: fixed;
  right: 12px;
  top: 56px;
  bottom: 80px;
  width: 340px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 33;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.quiz-panel.visible { display: flex; }

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

.quiz-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.quiz-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.quiz-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* === Analysis Panel === */
.analysis-panel {
  position: fixed;
  right: 12px;
  top: 56px;
  bottom: 80px;
  width: 360px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 32;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.analysis-panel.visible { display: flex; }

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

.analysis-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.analysis-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.analysis-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.analysis-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}


/* ============================================
   SMALL VIEWPORTS — Panels become bottom sheets
   JS-controlled via .is-mobile on #app
   ============================================ */

.is-mobile .stats-panel,
.is-mobile .ranges-panel,
.is-mobile .bankroll-panel,
.is-mobile .leaks-panel,
.is-mobile .quiz-panel,
.is-mobile .analysis-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: auto;
  bottom: 0;
  width: 100%;
  max-height: 75vh;
  border-radius: 16px 16px 0 0;
  z-index: 40;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  padding-bottom: env(safe-area-inset-bottom);
}

.is-mobile .stats-header::before,
.is-mobile .ranges-header::before,
.is-mobile .bankroll-header::before,
.is-mobile .leaks-header::before,
.is-mobile .quiz-header::before,
.is-mobile .analysis-header::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.is-mobile .stats-header,
.is-mobile .ranges-header,
.is-mobile .bankroll-header,
.is-mobile .leaks-header,
.is-mobile .quiz-header,
.is-mobile .analysis-header {
  position: relative;
  padding: 18px 16px 10px;
}

.is-mobile .stats-close,
.is-mobile .ranges-close,
.is-mobile .bankroll-close,
.is-mobile .leaks-close,
.is-mobile .quiz-close,
.is-mobile .analysis-close {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
}

.is-mobile .stats-body,
.is-mobile .ranges-body,
.is-mobile .bankroll-body,
.is-mobile .leaks-body,
.is-mobile .quiz-body,
.is-mobile .analysis-body {
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
}

.is-mobile .tilt-card {
  margin: 0 16px;
  padding: 24px 20px;
}

.is-mobile .tilt-card h2 { font-size: 1.1em; }
.is-mobile .tilt-card p { font-size: 0.8em; }

.is-mobile .tilt-dismiss {
  width: 100%;
  padding: 14px 24px;
  min-height: 48px;
}

/* === Panel backdrop for mobile === */
.panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 39;
}

.panel-backdrop.visible { display: block; }

/* === Coach Bubble — inline by default, sidebar when container is wide === */
.coach-bubble {
  display: flex;
  align-items: flex-start;
  gap: clamp(4px, 0.6vmin, 12px);
  max-width: 600px;
  margin: 0 clamp(4px, 1vmin, 12px);
  padding: clamp(4px, 0.6vmin, 10px) clamp(8px, 1vmin, 16px);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: clamp(6px, 0.8vmin, 12px);
  animation: coachSlideIn 0.35s ease-out;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  min-height: 28px;
  overflow-y: auto;
}

/* Subtle scrollbar for coach bubble */
.coach-bubble::-webkit-scrollbar { width: 4px; }
.coach-bubble::-webkit-scrollbar-track { background: transparent; }
.coach-bubble::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }
.coach-bubble::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.25); }

.coach-bubble.visible {
  opacity: 1;
  pointer-events: auto;
}

.coach-icon {
  font-size: clamp(0.8em, 1vmin, 1.2em);
  flex-shrink: 0;
  margin-top: 1px;
}

.coach-text {
  font-size: clamp(0.6em, 0.8vmin, 0.88em);
  line-height: 1.5;
  color: var(--text2);
}

/* Wide viewport: coach bubble in sidebar — JS fitLayout() caps max-height dynamically */
.is-wide .coach-bubble {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  max-width: none;
  margin: clamp(8px, 1vw, 14px) 0 0;
  padding: clamp(6px, 0.8vw, 12px) clamp(10px, 1.2vw, 18px);
}

.is-wide .coach-icon { font-size: clamp(0.9em, 1vw, 1.2em); }
.is-wide .coach-text { font-size: clamp(0.68em, 0.78vw, 0.88em); }

/* Coach feedback button */
.coach-feedback-btn {
  flex-shrink: 0;
  width: clamp(20px, 2.5vmin, 30px);
  height: clamp(20px, 2.5vmin, 30px);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text2);
  font-size: clamp(0.6em, 0.9vmin, 0.85em);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  margin-top: 2px;
  pointer-events: auto;
}

.coach-feedback-btn:hover {
  background: rgba(255, 215, 0, 0.15);
  border-color: var(--gold);
  color: var(--gold);
}

.coach-bubble.positive { border-left: 3px solid var(--green); }
.coach-bubble.positive .coach-text { color: var(--green); }

.coach-bubble.negative { border-left: 3px solid var(--accent); }
.coach-bubble.negative .coach-text { color: var(--accent); }

.coach-bubble.neutral { border-left: 3px solid var(--gold); }
.coach-bubble.neutral .coach-text { color: var(--gold); }

.coach-bubble.warning { border-left: 3px solid #ff8c00; }
.coach-bubble.warning .coach-text { color: #ff8c00; }

@keyframes coachSlideIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* === Score Popup (flashes over table after each decision) === */
.score-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: clamp(1.2em, 2.5vmin, 2em);
  font-weight: 800;
  padding: clamp(8px, 1.5vmin, 16px) clamp(16px, 3vmin, 40px);
  border-radius: 16px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: none;
  white-space: nowrap;
  text-align: center;
  backdrop-filter: blur(12px);
  letter-spacing: 0.5px;
}

.score-popup.visible {
  animation: scoreFlash 1.6s ease-out forwards;
}

@keyframes scoreFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  25% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(0.95); }
}

.score-popup.score-best {
  background: rgba(34, 197, 94, 0.2);
  border: 2px solid rgba(34, 197, 94, 0.4);
  color: var(--green);
  text-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}
.score-popup.score-correct {
  background: rgba(59, 130, 246, 0.2);
  border: 2px solid rgba(59, 130, 246, 0.4);
  color: #60a5fa;
  text-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}
.score-popup.score-inaccuracy {
  background: rgba(255, 215, 0, 0.15);
  border: 2px solid rgba(255, 215, 0, 0.3);
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}
.score-popup.score-mistake {
  background: rgba(249, 115, 22, 0.2);
  border: 2px solid rgba(249, 115, 22, 0.4);
  color: #f97316;
  text-shadow: 0 0 20px rgba(249, 115, 22, 0.3);
}
.score-popup.score-blunder {
  background: rgba(233, 69, 96, 0.2);
  border: 2px solid rgba(233, 69, 96, 0.4);
  color: var(--accent);
  text-shadow: 0 0 20px rgba(233, 69, 96, 0.3);
}

/* === Range Matrix Panel === */
.matrix-panel {
  position: fixed;
  right: 12px;
  top: 56px;
  bottom: 80px;
  width: 380px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 33;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.matrix-panel.visible { display: flex; }

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

.matrix-header h3 {
  margin: 0;
  font-size: 0.85em;
  color: var(--text);
}

.matrix-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.4em;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.matrix-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.matrix-legend {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6em;
  color: var(--text2);
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 1px;
  margin: 0 auto;
  max-width: 350px;
}

.matrix-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.4em, 0.55vw, 0.6em);
  font-weight: 600;
  border-radius: 2px;
  cursor: default;
  transition: transform 0.1s;
  position: relative;
  line-height: 1;
}

.matrix-cell:hover {
  transform: scale(1.3);
  z-index: 2;
  box-shadow: 0 0 8px rgba(255,255,255,.2);
}

.matrix-cell.is-hero {
  outline: 2px solid #fff;
  outline-offset: -1px;
  z-index: 1;
}

.matrix-info {
  text-align: center;
  color: var(--text2);
  font-size: 0.65em;
  padding: 8px 0;
  line-height: 1.5;
}

/* Mobile bottom sheet for matrix */
.is-mobile .matrix-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: auto;
  bottom: 0;
  width: 100%;
  max-height: 75vh;
  border-radius: 16px 16px 0 0;
  z-index: 40;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  padding-bottom: env(safe-area-inset-bottom);
}

.is-mobile .matrix-header::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

/* === Leaderboard Panel === */
.leaderboard-panel {
  position: fixed;
  right: 12px;
  top: 56px;
  bottom: 80px;
  width: 320px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0;
  z-index: 31;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.leaderboard-panel.visible { display: flex; }

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

.leaderboard-header h3 {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
}

.leaderboard-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 6px;
  border-radius: 4px;
}

.leaderboard-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.leaderboard-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* Mobile bottom sheet for leaderboard */
.is-mobile .leaderboard-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: auto;
  bottom: 0;
  width: 100%;
  max-height: 75vh;
  border-radius: 16px 16px 0 0;
  z-index: 40;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  padding-bottom: env(safe-area-inset-bottom);
}

.is-mobile .leaderboard-header::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.is-mobile .leaderboard-header {
  position: relative;
  padding: 18px 16px 10px;
}

.is-mobile .leaderboard-close {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
}

.is-mobile .leaderboard-body {
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
}
