:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-elevated: #21262d;
  --border: #30363d;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.15);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.15);
  --yellow: #d29922;
  --yellow-bg: rgba(210, 153, 34, 0.15);
  --purple: #bc8cff;
  --purple-bg: rgba(188, 140, 255, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --nav-height: 64px;
  --header-height: 108px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 100;
  background: var(--bg-primary);
  padding: var(--safe-top) 16px 0;
  border-bottom: 1px solid var(--border);
  transition: transform 0.3s ease;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

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

.logo-icon {
  font-size: 24px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-bar {
  position: relative;
  padding-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(calc(-50% - 6px));
  color: var(--text-muted);
  font-size: 20px;
}

.search-bar input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px 10px 40px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

/* Main Content */
.main-content {
  padding-top: var(--header-height);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  min-height: 100vh;
}

.page {
  display: none;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

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

/* Category Chips */
.category-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 12px 16px;
}

.category-scroll::-webkit-scrollbar {
  display: none;
}

.category-chips {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  flex-shrink: 0;
}

.chip:active {
  transform: scale(0.95);
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Sort Bar */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 12px;
}

.sort-label {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

.sort-options {
  display: flex;
  gap: 4px;
}

.sort-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.sort-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Market Cards */
.markets-list {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.market-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.market-card:active {
  transform: scale(0.98);
  background: var(--bg-elevated);
}

.market-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.market-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.market-info {
  flex: 1;
  min-width: 0;
}

.market-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.market-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.market-category-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--purple-bg);
  color: var(--purple);
  font-weight: 500;
}

.market-volume {
  font-size: 11px;
  color: var(--text-muted);
}

.market-end {
  font-size: 11px;
  color: var(--text-muted);
}

.market-badges {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-hot {
  background: var(--red-bg);
  color: var(--red);
}

.badge-trending {
  background: var(--green-bg);
  color: var(--green);
}

.market-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.market-option {
  display: flex;
  align-items: center;
  gap: 10px;
}

.option-label {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 80px;
  flex-shrink: 0;
}

.option-bar-container {
  flex: 1;
  height: 28px;
  background: var(--bg-elevated);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.option-bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 4px;
}

.option-bar.green {
  background: linear-gradient(90deg, rgba(63, 185, 80, 0.4), rgba(63, 185, 80, 0.7));
}

.option-bar.red {
  background: linear-gradient(90deg, rgba(248, 81, 73, 0.4), rgba(248, 81, 73, 0.7));
}

.option-percentage {
  font-size: 14px;
  font-weight: 700;
  min-width: 42px;
  text-align: right;
}

.option-percentage.green {
  color: var(--green);
}

.option-percentage.red {
  color: var(--red);
}

.market-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.market-votes {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.market-votes .material-icons-round {
  font-size: 14px;
}

.btn-predict {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-predict:active {
  transform: scale(0.95);
  background: var(--accent-hover);
}

.btn-predict:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-predict.voted {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

/* AI Insights Page */
.page-header {
  padding: 20px 16px 8px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.ai-section {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.ai-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ai-card-header .material-icons-round {
  color: var(--accent);
  font-size: 24px;
}

.ai-card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.ai-card-desc {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 16px;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary .material-icons-round {
  font-size: 20px;
}

.market-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='%238b949e'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.ai-result {
  margin-top: 16px;
}

.ai-result-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.ai-suggestion {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-suggestion-prob {
  min-width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.ai-suggestion-prob.high {
  background: var(--green-bg);
  color: var(--green);
}

.ai-suggestion-prob.medium {
  background: var(--yellow-bg);
  color: var(--yellow);
}

.ai-suggestion-prob.low {
  background: var(--red-bg);
  color: var(--red);
}

.ai-suggestion-info h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.ai-suggestion-info span {
  font-size: 11px;
  color: var(--text-muted);
}

.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
}

.ai-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.ai-loading-text {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Leaderboard */
.leaderboard-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: all 0.2s;
}

.leaderboard-rank {
  font-size: 18px;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
}

.leaderboard-rank.gold { color: #ffd700; }
.leaderboard-rank.silver { color: #c0c0c0; }
.leaderboard-rank.bronze { color: #cd7f32; }

.leaderboard-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.leaderboard-info {
  flex: 1;
}

.leaderboard-name {
  font-size: 14px;
  font-weight: 600;
}

.leaderboard-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.leaderboard-accuracy {
  text-align: right;
}

.leaderboard-accuracy-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
}

.leaderboard-accuracy-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* My Votes Page */
.myvotes-content {
  padding: 16px;
}

.myvotes-stats-card {
  background: linear-gradient(135deg, #1a3a5c, #2d1b4e);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid rgba(88, 166, 255, 0.2);
}

.myvotes-stats-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
}

.myvotes-stat {
  text-align: center;
}

.myvotes-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.myvotes-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.myvotes-stat-divider {
  width: 1px;
  height: 40px;
  background: var(--border);
}

.myvotes-section {
  margin-bottom: 16px;
}

.myvotes-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.vote-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vote-history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.vote-history-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.vote-history-body {
  flex: 1;
  min-width: 0;
}

.vote-history-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  line-height: 1.4;
}

.vote-history-detail {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vote-history-option {
  font-size: 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
}

.vote-history-time {
  font-size: 11px;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

.empty-state .material-icons-round {
  font-size: 48px;
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
}

.empty-state-sub {
  font-size: 12px !important;
  margin-top: 4px;
  color: var(--text-muted);
}

.myvotes-disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-top: 16px;
}

.myvotes-disclaimer .material-icons-round {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.myvotes-disclaimer p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.modal-body {
  padding: 20px;
}

.modal-market-info p {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.modal-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.modal-option:active {
  transform: scale(0.98);
}

.modal-option.selected {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
}

.modal-option-label {
  font-size: 15px;
  font-weight: 500;
}

.modal-option-pct {
  font-size: 15px;
  font-weight: 700;
}

.btn-vote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius);
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-vote:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-vote:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-vote .material-icons-round {
  font-size: 22px;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  max-width: 360px;
  width: calc(100% - 32px);
  padding: 14px 20px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

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

.toast.success {
  border-color: var(--green);
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
}

.toast.error {
  border-color: var(--red);
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  position: relative;
}

.nav-item .material-icons-round {
  font-size: 24px;
  transition: all 0.2s;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item.active .material-icons-round {
  transform: scale(1.1);
}

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-card {
  height: 160px;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}

/* Responsive: Tablet/Desktop */
@media (min-width: 481px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Pulse animation for hot badge */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.badge-hot {
  animation: pulse 2s ease-in-out infinite;
}

/* Splash Screen */
.splash-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash-content {
  text-align: center;
}

.splash-logo {
  font-size: 64px;
  margin-bottom: 16px;
  animation: splashBounce 1.5s ease-in-out infinite;
}

@keyframes splashBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.splash-title {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 32px;
}

.splash-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.splash-text {
  font-size: 14px;
  color: var(--text-muted);
}
