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

:root {
  --blue: #2563EB;
  --blue-light: #3B82F6;
  --blue-bg: #EFF6FF;
  --blue-bg2: #F0F7FF;
  --orange: #F97316;
  --orange-dark: #EA580C;
  --bg: #F5F6FA;
  --white: #FFFFFF;
  --text: #1A1A1A;
  --text-sec: #666666;
  --text-muted: #AAAAAA;
  --border: #E8EAF0;
  --border-light: #F0F1F5;
  --green: #22C55E;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-icon {
  font-size: 22px;
  line-height: 1;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* Desktop: header categories - right side, underline style */
.header-cats {
  display: none;
  align-items: center;
  gap: 0;
}

.header-cat {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font);
  transition: all .2s;
}

.header-cat:hover {
  color: var(--text-sec);
}

.header-cat.active {
  color: var(--blue);
  font-weight: 600;
  border-bottom-color: var(--blue);
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--blue-bg);
  padding: 3px 10px;
  border-radius: 12px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.live-text {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue);
}

/* ===== Mobile Tabs ===== */
.mobile-tabs {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}

.mobile-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all .2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font);
}

.cat-tab:hover {
  color: var(--text-sec);
}

.cat-tab.active {
  color: var(--blue);
  font-weight: 600;
  border-bottom-color: var(--blue);
}

/* ===== Chip Bar ===== */
.chip-bar {
  background: var(--white);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chip-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sec);
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  border: none;
  font-family: var(--font);
}

.chip:hover {
  background: #E8EAF0;
}

.chip.active {
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px;
}

.hidden {
  display: none !important;
}

/* ===== Section Headers ===== */
.section-header {
  display: none;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.realtime-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-bg);
  padding: 4px 12px;
  border-radius: 12px;
}

.history-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-lottery-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-bg);
  padding: 4px 12px;
  border-radius: var(--radius-xs);
}

/* ===== Cards Grid ===== */
.cards-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.lottery-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 16px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow .2s, transform .15s;
}

.lottery-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.lottery-card.card-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.card-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-bg2);
  padding: 3px 8px;
  border-radius: 4px;
}

.card-draw {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.card-draw-no {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font);
}

.card-countdown {
  display: flex;
  align-items: center;
  gap: 3px;
}

.cd-box {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--blue);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cd-sep {
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
  font-family: var(--mono);
}

.card-balls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 4px;
}

.ball {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--white);
  font-family: var(--font);
  font-size: 16px;
  flex-shrink: 0;
}

.ball-num {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
}

.ball-sum {
  background: linear-gradient(180deg, var(--orange), var(--orange-dark));
}

.ball-op {
  font-size: 16px;
  color: #CCC;
  font-weight: normal;
  flex-shrink: 0;
}

/* Card: next draw row */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.card-next {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.next-no {
  font-weight: 600;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.featured-cd .cd-box {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  font-size: 13px;
}

.featured-cd .cd-sep {
  font-size: 13px;
}

/* ===== Featured Card (Detail) ===== */
.featured-card .lottery-card {
  cursor: default;
}

.featured-card .lottery-card:hover {
  box-shadow: none;
  transform: none;
}

.featured-card .card-name {
  font-size: 16px;
}

.featured-card .ball {
  width: 46px;
  height: 46px;
  font-size: 20px;
}

.featured-card .ball-op {
  font-size: 18px;
}

/* ===== Date Filter ===== */
.date-filter {
  display: flex;
  gap: 0;
  margin: 12px 0;
}

.df-btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sec);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all .2s;
}

.df-btn:hover {
  background: var(--border-light);
}

.df-btn.active {
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
}

/* ===== Drawing state ===== */
.card-countdown {
  min-height: 22px;
}

.card-countdown.is-drawing {
  gap: 0;
}

.drawing-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
  line-height: 22px;
  animation: drawingPulse 1.2s ease-in-out infinite;
}

.featured-cd.is-drawing .drawing-text {
  line-height: 28px;
}

@keyframes drawingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Row insert animation ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== History List (Mobile) ===== */
.history-list {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
}

.history-row:last-child {
  border-bottom: none;
}

.hist-no {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
  min-width: 72px;
}

.hist-balls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.hist-balls .ball {
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.hist-balls .ball-op {
  font-size: 11px;
}

.hist-time {
  font-size: 11px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text-muted);
  min-width: 64px;
  text-align: right;
}

.history-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Desktop History Table ===== */
.desktop-history {
  display: none;
}

.history-table {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
}

.th-no {
  width: 120px;
  flex-shrink: 0;
}

.th-nums {
  flex: 1;
  text-align: center;
}

.th-result {
  width: 80px;
  text-align: center;
  flex-shrink: 0;
}

.th-time {
  width: 180px;
  text-align: right;
  flex-shrink: 0;
}

.table-row {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}

.table-row:last-child {
  border-bottom: none;
}

.table-row:hover {
  background: #FAFBFD;
}

.tr-no {
  width: 120px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
}

.tr-balls {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tr-balls .ball {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

.tr-balls .ball-op {
  font-size: 13px;
}

.tr-sum {
  width: 80px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.tr-sum .ball {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

.tr-time {
  width: 180px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text-muted);
  text-align: right;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
}

.pg-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all .2s;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-sec);
}

.pg-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.pg-btn.active {
  background: var(--blue);
  color: var(--white);
  border-color: var(--blue);
  font-weight: 600;
}

.pg-btn.disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.pg-btn.disabled:hover {
  border-color: var(--border);
  color: var(--text-muted);
}

.pg-dots {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Footer ===== */
.footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  text-align: center;
}

.footer-copy {
  font-size: 12px;
  color: var(--text-sec);
  margin-bottom: 4px;
}

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

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

/* ==========================================================
   Desktop (>=768px)
   ========================================================== */
@media (min-width: 768px) {
  /* Header: show categories inline, hide mobile tabs */
  .header-inner {
    padding: 14px 32px;
  }

  .header-cats {
    display: flex;
  }

  .header .live-badge {
    display: none;
  }

  .mobile-tabs {
    display: none;
  }

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

  .logo-text {
    font-size: 18px;
  }

  /* Chip bar: hidden on desktop, chips show in content area */
  .chip-bar {
    display: none;
  }

  .chip {
    padding: 7px 18px;
    font-size: 13px;
  }

  /* Main content */
  .main-content {
    padding: 20px 32px;
  }

  /* Section headers visible */
  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }

  /* Cards: auto-fit, min 240px per card */
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }

  .lottery-card {
    padding: 16px 14px;
  }

  .card-name {
    font-size: 14px;
  }

  .card-badge {
    font-size: 9px;
    padding: 2px 6px;
  }

  .card-draw-no {
    font-size: 11px;
  }

  .cd-box {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .cd-sep {
    font-size: 10px;
  }

  .ball {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .ball-op {
    font-size: 14px;
  }

  .card-balls {
    gap: 5px;
    padding: 8px 0 4px;
  }

  .card-next {
    font-size: 11px;
  }

  .next-label {
    font-size: 11px;
  }

  .next-no {
    font-size: 11px;
  }

  .featured-cd .cd-box {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  /* Desktop history section */
  .desktop-history {
    display: block;
    margin-top: 32px;
  }

  .desktop-history .section-header {
    margin-bottom: 12px;
  }

  .desktop-history .date-filter {
    margin: 0;
  }

  /* Hide mobile-only detail view on desktop */
  .view-detail {
    display: none !important;
  }

  /* Featured card adjustments on desktop */
  .featured-card .lottery-card {
    max-width: 100%;
  }

  .featured-card .ball {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }

  /* Footer */
  .footer-inner {
    padding: 20px 32px;
  }
}

/* Large desktop (>=1200px) */
@media (min-width: 1200px) {
  .cards-grid {
    gap: 20px;
  }

  .lottery-card {
    padding: 18px 16px;
  }

  .card-name {
    font-size: 15px;
  }

  .ball {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }
}
