:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-sec: #4a4a6a;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --border: #d1d5db;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== HEADER ===== */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1.1rem;
}

.header-stats {
  display: flex; gap: 20px; align-items: center;
}

.stat-pill {
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-pill.score { background: #dcfce7; color: #166534; }
.stat-pill.level { background: #fef3c7; color: #92400e; }

/* ===== MAIN LAYOUT ===== */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 1024px) {
  .main-grid { grid-template-columns: 1fr; }
}

/* ===== CARD ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}

.card-body { padding: 16px; }

.timeframe-label {
  font-size: 0.8rem;
  color: var(--text-sec);
}

/* ===== CHART AREA ===== */
.chart-container {
  position: relative;
  height: 380px;
  background: #0f172a;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

#chartCanvas {
  width: 100%; height: 100%;
  display: block;
}

.chart-overlay {
  position: absolute;
  top: 10px; left: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.chart-badge {
  background: rgba(15,23,42,0.85);
  color: #e2e8f0;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
}

.chart-badge.up { color: #4ade80; }
.chart-badge.down { color: #f87171; }

/* ===== ORDER BOOK ===== */
.orderbook {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.8rem;
}

.ob-col h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding: 0 4px;
}

.ob-col.bids h4 { color: var(--success); }
.ob-col.asks h4 { color: var(--danger); }

.ob-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 6px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  transition: background 0.2s;
}

.ob-row .bar {
  position: absolute;
  top: 0; bottom: 0;
  opacity: 0.12;
  z-index: 0;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.ob-row.bid .bar { right: 0; background: var(--success); }
.ob-row.ask .bar { left: 0; background: var(--danger); }

.ob-row span { position: relative; z-index: 1; font-family: 'SF Mono', monospace; font-size: 0.78rem; }

.ob-row.pulse {
  animation: obPulse 0.5s ease;
}

@keyframes obPulse {
  0% { background: rgba(37,99,235,0.25); }
  100% { background: transparent; }
}

/* ===== NEWS FEED ===== */
#newsFeed {
  max-height: 220px;
  min-height: 120px;
  overflow-y: auto;
}

.news-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: #f8fafc;
  border-left: 3px solid var(--border);
  font-size: 0.85rem;
  transition: all 0.3s;
  animation: newsSlide 0.3s ease;
}

@keyframes newsSlide {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.news-item.urgent {
  border-left-color: var(--danger);
  background: #fef2f2;
  animation: newsFlash 2s infinite, newsSlide 0.3s ease;
}

.news-item.bullish { border-left-color: var(--success); background: #f0fdf4; }
.news-item.bearish { border-left-color: var(--danger); background: #fef2f2; }

@keyframes newsFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.news-time {
  font-size: 0.7rem;
  color: var(--text-sec);
  margin-bottom: 2px;
  font-weight: 600;
}

/* ===== DUAL PANEL ===== */
.dual-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) {
  .dual-panel { grid-template-columns: 1fr; }
}

/* ===== AI COACH PANEL ===== */
.coach-panel {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #e2e8f0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.coach-header {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.coach-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(37,99,235,0.4);
}

.coach-info h3 { font-size: 1rem; color: white; }
.coach-info p { font-size: 0.75rem; color: #94a3b8; }

.coach-body {
  padding: 16px;
  min-height: 200px;
  max-height: 300px;
  overflow-y: auto;
}

.coach-message {
  margin-bottom: 14px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  font-size: 0.88rem;
  line-height: 1.6;
  animation: msgSlide 0.3s ease;
}

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

.coach-subtitle {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #94a3b8;
  margin-bottom: 4px;
  font-weight: 600;
}

.coach-controls {
  padding: 12px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  gap: 8px;
}

.coach-btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: #cbd5e1;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font);
}

.coach-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.coach-btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.coach-btn.primary:hover { background: var(--accent-dark); }
.coach-btn:disabled,
.coach-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.6);
  pointer-events: none;
}

/* ===== ACTION BUTTONS ===== */
.action-prompt {
  font-size: 0.85rem;
  color: var(--text-sec);
  margin-bottom: 12px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.action-btn {
  padding: 14px;
  border: 2px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  font-family: var(--font);
  outline: none;
}

.action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.action-btn:active { transform: translateY(0); }
.action-btn.buy { border-color: var(--success); color: var(--success); }
.action-btn.sell { border-color: var(--danger); color: var(--danger); }
.action-btn.hold { border-color: var(--warning); color: var(--warning); }
.action-btn.flag { border-color: var(--accent); color: var(--accent); }

.action-btn .icon { font-size: 1.3rem; }

/* ===== HINT SYSTEM ===== */
.hint-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  margin-top: 12px;
}

.hint-count {
  background: var(--accent);
  color: white;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  flex-shrink: 0;
}

.hint-text { font-size: 0.8rem; color: var(--accent-dark); flex: 1; }

/* ===== RESULT OVERLAY ===== */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.result-overlay.active { display: flex; }

.result-card {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: resultPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes resultPop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.result-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 auto 16px;
}

.result-icon.success { background: #dcfce7; color: var(--success); }
.result-icon.fail { background: #fee2e2; color: var(--danger); }

.result-title {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.result-desc {
  text-align: center;
  color: var(--text-sec);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.result-lesson {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 20px;
  border-left: 4px solid var(--accent);
}

.result-lesson h4 { font-size: 0.8rem; color: var(--text-sec); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.result-lesson p { font-size: 0.85rem; color: var(--text); line-height: 1.5; }

.result-actions {
  display: flex; gap: 10px;
}

.result-actions button {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: var(--font);
}

.result-actions button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e5e7eb; }

/* ===== START SCREEN ===== */
.start-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.start-card {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: startFade 0.6s ease;
}

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

.start-card .logo-icon {
  width: 64px; height: 64px;
  font-size: 2rem;
  margin: 0 auto 20px;
}

.start-card h1 {
  font-size: 1.6rem;
  margin-bottom: 12px;
  color: var(--text);
}

.start-card p {
  color: var(--text-sec);
  font-size: 0.95rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

.start-features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 28px;
  text-align: left;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.feature-item .emoji { font-size: 1.2rem; }

.start-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  outline: none;
}

.start-btn:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}

.start-btn:hover { background: var(--accent-dark); transform: translateY(-1px); }

/* ===== SUMMARY SCREEN ===== */
.summary-screen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 250;
  padding: 20px;
}

.summary-screen.active { display: flex; }

.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  animation: resultPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-circle {
  width: 120px; height: 120px;
  border-radius: 50%;
  border: 6px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  transition: border-color 0.5s, color 0.5s;
}

.score-circle.high { border-color: var(--success); color: var(--success); }
.score-circle.mid { border-color: var(--warning); color: var(--warning); }
.score-circle.low { border-color: var(--danger); color: var(--danger); }

.lessons-list { margin: 20px 0; }

.lesson-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.lesson-item:last-child { border-bottom: none; }
.lesson-item .check { color: var(--success); font-weight: 700; }
.lesson-item .xmark { color: var(--danger); font-weight: 700; }

/* ===== PROGRESS ===== */
.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.progress-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.progress-stats { margin-top: 12px; font-size: 0.8rem; color: var(--text-sec); }

.progress-stat {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.stat-good { font-weight: 600; color: var(--success); }
.stat-bad { font-weight: 600; color: var(--danger); }

/* ===== GUIDE ===== */
.guide-body { font-size: 0.8rem; color: var(--text-sec); }

.guide-item {
  margin-bottom: 10px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 6px;
}

.guide-item:last-child { margin-bottom: 0; }

.guide-item strong { color: var(--text); display: block; margin-bottom: 4px; }
.guide-item p { font-size: 0.78rem; line-height: 1.4; }

/* ===== TOOLTIP ===== */
.tooltip {
  position: absolute;
  background: rgba(15,23,42,0.95);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  border: 1px solid rgba(255,255,255,0.1);
}

.tooltip.visible { opacity: 1; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .main-grid { padding: 12px; gap: 12px; }
  .app-header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .header-stats { gap: 10px; }
  .start-features { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .chart-container { height: 300px; }
  .start-card { padding: 24px; }
  .result-card { padding: 20px; }
  .summary-card { padding: 20px; }
}

@media (max-width: 400px) {
  .action-grid { grid-template-columns: 1fr; }
  .dual-panel { grid-template-columns: 1fr; }
}
