/* Suvarnabhumi: Khwan Isan Wiki Styles - Mobile-First & Desktop Optimized */
:root {
  --bg-primary: #0f1612;
  --bg-surface: #15221b;
  --bg-card: #1c2d24;
  --bg-card-hover: #23392e;
  --border-color: #2e4235;
  --border-gold: #c89d56;
  --border-gold-glow: #e6b86a;
  
  --text-main: #f4e6bc;
  --text-muted: #b7a988;
  --text-dim: #7f7358;
  --gold-accent: #ffe27a;
  --gold-bright: #fff2a3;
  --red-accent: #e76f51;
  --blue-accent: #4ea8de;
  --green-accent: #52b788;
  --purple-accent: #b5838d;

  --rarity-common: #8e9ca6;
  --rarity-uncommon: #48bb78;
  --rarity-rare: #4299e1;
  --rarity-epic: #9f7aea;
  --rarity-legendary: #ecc94b;
  
  --font-family: 'Sarabun', 'Leelawadee UI', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-main: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.55);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(200, 157, 86, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(78, 168, 222, 0.03) 0%, transparent 40%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #263a2f; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-gold); }

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(18, 30, 24, 0.96);
  backdrop-filter: blur(14px);
  border-bottom: 2px solid var(--border-gold);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  flex-shrink: 0;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-gold);
  background: #1f3327;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 8px rgba(200, 157, 86, 0.25);
  flex-shrink: 0;
}

.brand-title h1 {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--gold-accent);
  line-height: 1.2;
}

.brand-title span {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-pill {
  background: #17271e;
  padding: 3px 9px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.stat-pill b {
  color: var(--gold-accent);
}

.search-bar-wrap {
  flex: 1;
  max-width: 320px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: #121d17;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
  transition: all 0.2s;
}

.search-input:focus {
  border-color: var(--border-gold);
  background: #16241c;
  box-shadow: 0 0 10px rgba(200, 157, 86, 0.25);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.85rem;
}

/* Swipeable Navigation Tabs */
.nav-tabs-wrapper {
  background: #111a14;
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
}

.nav-tabs {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 3px solid transparent;
  transition: all 0.18s;
  flex-shrink: 0;
}

.nav-tab:hover {
  color: var(--gold-accent);
}

.nav-tab.active {
  color: var(--gold-accent);
  border-bottom-color: var(--border-gold);
  background: rgba(200, 157, 86, 0.08);
}

/* Main Container */
main {
  max-width: 1440px;
  margin: 18px auto 80px;
  padding: 0 16px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}
.tab-pane.active {
  display: block;
}

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

/* Toolbar Filters (Swipeable Pills on Mobile) */
.filter-toolbar {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}
.filter-group::-webkit-scrollbar { display: none; }

.filter-btn {
  padding: 6px 12px;
  border-radius: 18px;
  border: 1px solid var(--border-color);
  background: #17271e;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-btn:hover {
  color: var(--text-main);
  border-color: var(--border-gold);
}

.filter-btn.active {
  background: #2a3d31;
  color: var(--gold-accent);
  border-color: var(--border-gold);
  font-weight: 600;
  box-shadow: 0 0 8px rgba(200, 157, 86, 0.2);
}

.filter-select {
  padding: 6px 10px;
  background: #17271e;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}
.filter-select:focus {
  border-color: var(--border-gold);
}

.results-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

/* Card Styling */
.wiki-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.wiki-card:active {
  transform: scale(0.99);
}

.wiki-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-gold);
  box-shadow: var(--shadow-hover);
  background: var(--bg-card-hover);
}

.wiki-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border-color);
}

.wiki-card.rarity-common::before { background: var(--rarity-common); }
.wiki-card.rarity-uncommon::before { background: var(--rarity-uncommon); }
.wiki-card.rarity-rare::before { background: var(--rarity-rare); }
.wiki-card.rarity-epic::before { background: var(--rarity-epic); }
.wiki-card.rarity-legendary::before { background: var(--rarity-legendary); box-shadow: 0 0 8px var(--rarity-legendary); }

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

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #121c16;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.card-title-group {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--gold-accent);
  line-height: 1.3;
  word-break: break-word;
}

.card-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.card-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}
.badge-boss { background: rgba(231, 111, 81, 0.2); color: #ff8c70; border: 1px solid #e76f51; }
.badge-level { background: #22342a; color: var(--gold-accent); border: 1px solid var(--border-color); }
.badge-class { background: #192f23; color: #72efdd; border: 1px solid #2d6a4f; }
.badge-chapter { background: #332616; color: #ffe066; border: 1px solid #7a5c2d; }

.card-body {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  flex: 1;
}

.card-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  background: #111a14;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}
.stat-item .stat-label { color: var(--text-dim); }
.stat-item .stat-val { font-weight: 700; color: var(--text-main); }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 8px;
  gap: 8px;
}

.drop-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.drop-tag {
  background: #121c16;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.72rem;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.drop-tag:hover {
  border-color: var(--border-gold);
}
.drop-tag .chance {
  color: var(--gold-accent);
  font-weight: 600;
}

/* Class Hero */
.class-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-main);
}

.class-hero-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.class-avatar {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: #203326;
  border: 2px solid var(--border-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.class-hero-title h2 {
  font-size: 1.35rem;
  color: var(--gold-accent);
  line-height: 1.2;
}

.class-playstyle-box {
  background: #111a14;
  border-left: 3px solid var(--border-gold);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 14px 0;
  color: var(--gold-bright);
  font-size: 0.88rem;
}

.stats-radar-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.stat-pill-box {
  background: #142119;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.stat-pill-box .label { font-size: 0.7rem; color: var(--text-muted); display: block; margin-bottom: 2px; }
.stat-pill-box .val { font-size: 0.95rem; font-weight: 700; color: var(--gold-accent); }

/* System & Patch */
.system-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.system-card h3 {
  color: var(--gold-accent);
  margin-bottom: 10px;
  font-size: 1.1rem;
}
.system-card ul, .system-card ol {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.system-card li { margin-bottom: 6px; }

.patch-block {
  background: var(--bg-surface);
  border-left: 3px solid var(--border-gold);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 16px 18px;
  margin-bottom: 14px;
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}
.patch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}
.patch-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold-accent);
}
.patch-date {
  font-size: 0.78rem;
  color: var(--text-dim);
  background: #121c16;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-surface);
  border: 2px solid var(--border-gold);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  position: relative;
  padding: 22px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: #203326;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 10;
}
.modal-close:hover {
  background: var(--red-accent);
  color: #fff;
}

/* Floating Back to Top Button */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #203428;
  border: 2px solid var(--border-gold);
  color: var(--gold-accent);
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  z-index: 90;
  transition: transform 0.2s, background 0.2s;
}
.back-to-top:hover {
  background: var(--border-gold);
  color: #121c16;
  transform: translateY(-3px);
}
.back-to-top.show {
  display: flex;
}

/* =========================================
   MOBILE-SPECIFIC ENHANCEMENTS (< 768px)
   ========================================= */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 12px;
    gap: 8px;
  }

  .header-stats {
    display: none; /* Hide header stats on small phones to save space */
  }

  .search-bar-wrap {
    max-width: 100%;
  }

  .search-input {
    padding: 7px 12px 7px 32px;
    font-size: 0.85rem;
  }

  .nav-tabs {
    padding: 0 8px;
    gap: 2px;
  }

  .nav-tab {
    padding: 8px 10px;
    font-size: 0.8rem;
    gap: 4px;
  }

  main {
    margin: 12px auto 60px;
    padding: 0 10px;
  }

  /* Horizontal swipeable pills for all filter toolbars */
  .filter-toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 10px;
    gap: 8px;
  }

  .filter-group {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 2px;
  }

  .filter-btn {
    padding: 5px 11px;
    font-size: 0.78rem;
  }

  .filter-select {
    padding: 5px 8px;
    font-size: 0.78rem;
    flex: 1;
  }

  .results-count {
    font-size: 0.75rem;
    align-self: flex-end;
  }

  /* Single Column Cards with Optimized Touch Targets */
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .wiki-card {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
  }

  .card-icon {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .card-title {
    font-size: 0.94rem;
  }

  /* Enhance Layout: force single column on mobile */
  #enhanceSimContainer > div {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Bottom sheet modal on mobile */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    max-height: 88vh;
    padding: 20px 16px 24px;
  }

  .modal-close {
    top: 12px;
    right: 12px;
  }
}
