/* ==========================================================================
   Westerosdle - Component Styles
   Header, Search Bar, Autocomplete, Guess Grid, Cards, Modals, Toasts
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Header & Navigation Refactored
   -------------------------------------------------------------------------- */
.app-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0 1.25rem 0;
  border-bottom: 1px solid var(--border-medium);
  position: relative;
}

.header-top {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

.game-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-decoration: none;
  text-align: center;
}

.logo-crown {
  font-size: 2.2rem;
  line-height: 1;
  filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.6));
  animation: crown-float 4s ease-in-out infinite alternate;
}

@keyframes crown-float {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-3px) rotate(2deg); }
}

.logo-text-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo-title {
  font-size: 2.1rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #ffffff 0%, var(--gold-light) 45%, var(--gold-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 25px rgba(212, 175, 55, 0.35);
  line-height: 1.1;
}

html[data-theme="light"] .logo-title {
  background: linear-gradient(135deg, #1e293b 0%, #b8860b 60%, #7a500b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(184, 134, 11, 0.2);
}

.logo-subtitle {
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 0.15rem;
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--gold-light);
  border-color: var(--border-medium);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.25);
  transform: translateY(-2px);
}

.icon-btn:active {
  transform: translateY(0);
}

.lang-btn {
  font-size: 0.8rem;
  font-weight: 700;
  width: auto;
  min-width: 2.8rem;
  padding: 0 0.55rem;
  letter-spacing: 0.05em;
  font-family: var(--font-body);
}

.theme-btn {
  font-size: 1.15rem;
}

/* Mode Selector Tabs */
.mode-selector {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.3rem;
  gap: 0.35rem;
  box-shadow: var(--shadow-sm);
}

.mode-tab {
  padding: 0.45rem 1.25rem;
  font-size: 0.86rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  transition: all var(--transition-normal);
  cursor: pointer;
  border: 0;
  background: transparent;
}

.mode-tab.active {
  background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-primary) 100%);
  color: #0a0c10;
  font-weight: 800;
  box-shadow: 0 2px 12px rgba(212, 175, 55, 0.4);
}

html[data-theme="light"] .mode-tab.active {
  background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%);
  color: #ffffff;
}

.mode-tab:not(.active):hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

/* --------------------------------------------------------------------------
   2. Target Hint & Status Bar (Lives & Hearts)
   -------------------------------------------------------------------------- */
.game-status-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 650px;
  padding: 0.65rem 1.2rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  gap: 0.4rem;
  margin: 0 auto;
  text-align: center;
}

.lives-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  width: 100%;
}

.lives-hearts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.heart {
  font-size: 1.15rem;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-block;
  user-select: none;
}

.heart.filled {
  filter: drop-shadow(0 0 5px rgba(239, 68, 68, 0.7));
  transform: scale(1);
}

.heart.lost {
  opacity: 0.3;
  filter: grayscale(100%);
  transform: scale(0.85);
}

.guess-counter-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.guess-counter-text span {
  color: var(--gold-light);
  font-weight: 700;
  font-size: 0.95rem;
}

.give-up-btn {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  white-space: nowrap;
}
.give-up-btn:hover {
  color: var(--targaryen-red);
}

/* --------------------------------------------------------------------------
   3. Search & Autocomplete
   -------------------------------------------------------------------------- */
.search-section {
  width: 100%;
  max-width: 650px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 50;
}

.search-input-wrapper {
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 0.85rem 3rem 0.85rem 1.2rem;
  font-size: 1.05rem;
  font-family: var(--font-body);
  background: var(--bg-surface);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-normal);
}

.search-input:focus {
  border-color: var(--gold-primary);
  box-shadow: var(--shadow-gold), 0 0 0 3px rgba(212, 175, 55, 0.15);
  background: var(--bg-card);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

.search-btn {
  position: absolute;
  right: 0.5rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-primary) 100%);
  color: #0a0c10;
  font-size: 1rem;
  font-weight: bold;
}

.search-btn:hover:not(:disabled) {
  filter: brightness(1.15);
  transform: scale(1.05);
}

.search-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--bg-glass-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  max-height: 280px;
  overflow-y: auto;
  list-style: none;
  display: none;
  z-index: 100;
}

.autocomplete-dropdown.show {
  display: block;
}

.autocomplete-item {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover, .autocomplete-item.selected {
  background: rgba(212, 175, 55, 0.15);
}

.autocomplete-item-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sigil-badge {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.sigil-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.house-name-text {
  font-weight: 600;
  color: var(--text-primary);
}

.house-region-pill {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* --------------------------------------------------------------------------
   4. Guess Grid & Results Table (Pixel-Perfect Column Alignment)
   -------------------------------------------------------------------------- */
.grid-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.grid-header {
  display: grid;
  grid-template-columns: minmax(170px, 2fr) repeat(7, minmax(95px, 1.1fr));
  gap: 0.45rem;
  padding: 0.5rem;
  border-bottom: 2px solid var(--border-medium);
  text-align: center;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
}

.grid-header-col {
  font-family: var(--font-title);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.grid-rows {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

/* Single Guess Row - Exactly Same Tracks as Header */
.guess-row {
  display: grid;
  grid-template-columns: minmax(170px, 2fr) repeat(7, minmax(95px, 1.1fr));
  gap: 0.45rem;
  padding: 0 0.5rem;
  perspective: 1000px;
  box-sizing: border-box;
  width: 100%;
  align-items: stretch;
}

.cell {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  min-height: 4.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.25rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: #ffffff;
  position: relative;
  transition: all var(--transition-normal);
  word-break: break-word;
  box-sizing: border-box;
}

/* Color Circles Container */
.color-dots-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-bottom: 0.2rem;
}

.color-dot {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  display: inline-block;
  flex-shrink: 0;
}

.cell-house {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.88rem;
  background: var(--bg-surface);
  border-color: var(--border-medium);
  color: var(--text-primary);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
  padding: 0.4rem 0.6rem;
}

.cell-house .house-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cell-house .house-title {
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.cell-house .house-arms {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Feedback Status Modifiers */
.cell.match-green {
  background: var(--match-green) !important;
  border-color: var(--match-green-light);
  box-shadow: 0 0 14px var(--match-green-glow);
}

.cell.match-yellow {
  background: var(--match-yellow) !important;
  border-color: var(--match-yellow-light);
  box-shadow: 0 0 14px var(--match-yellow-glow);
}

.cell.match-red {
  background: var(--match-red) !important;
  border-color: var(--match-red-light);
  box-shadow: 0 0 14px var(--match-red-glow);
}

.cell-subtext {
  font-size: 0.72rem;
  opacity: 0.9;
  margin-top: 0.2rem;
  font-weight: 400;
}

.weapon-pill {
  display: block;
  font-size: 0.72rem;
  color: #fff;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.35rem;
  margin-top: 0.25rem;
  line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  word-break: normal;
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   5. Modals & Overlays
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-bounce);
}

.modal-overlay.open .modal-container {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.modal-title {
  font-size: 1.25rem;
  color: var(--gold-light);
}

.modal-close-btn {
  font-size: 1.5rem;
  color: var(--text-muted);
}
.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Legend items in How to Play */
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
}

.legend-badge {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}

/* Stats Layout */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  text-align: center;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.85rem 0.5rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--font-title);
  color: var(--gold-light);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Distribution Chart Styles */
.distribution-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.distribution-title {
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.05em;
  text-align: center;
}

.distribution-bars {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.dist-label {
  width: 1.2rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-align: right;
}

.dist-bar-wrapper {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 1.4rem;
  display: flex;
  align-items: center;
}

.dist-bar {
  background: var(--bg-card-hover);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  min-width: 1.5rem;
  border-radius: var(--radius-sm);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dist-bar.highlight {
  background: linear-gradient(90deg, var(--gold-dark) 0%, var(--gold-primary) 100%);
  color: #0a0c10;
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

.share-btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-primary) 100%);
  color: #0a0c10;
  font-weight: 700;
  font-size: 1rem;
  border-radius: var(--radius-md);
  gap: 0.5rem;
  box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4);
}

.share-btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

/* --------------------------------------------------------------------------
   6. Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--gold-primary);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   7. Responsive Adaptations & Mobile Polish
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .app-container {
    padding: 0.5rem 0.5rem 2rem;
    gap: 0.85rem;
  }
  
  .header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
  }

  .header-left {
    order: 1;
  }

  .header-actions {
    order: 2;
    gap: 0.35rem;
  }

  .game-logo {
    order: 3;
    width: 100%;
    margin-top: 0.2rem;
    gap: 0.5rem;
  }

  .logo-crown {
    font-size: 1.8rem;
  }

  .logo-title {
    font-size: 1.65rem;
    letter-spacing: 0.08em;
  }

  .logo-subtitle {
    font-size: 0.68rem;
    letter-spacing: 0.12em;
  }

  .icon-btn {
    width: 2.3rem;
    height: 2.3rem;
    font-size: 1.05rem;
  }

  .lang-btn {
    min-width: 2.6rem;
    font-size: 0.75rem;
    padding: 0 0.45rem;
  }

  .mode-selector {
    width: 100%;
    max-width: 420px;
  }

  .mode-tab {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }

  .game-status-bar {
    padding: 0.55rem 0.8rem;
  }

  .lives-panel {
    gap: 0.5rem;
  }

  .heart {
    font-size: 1.05rem;
  }

  .guess-counter-text {
    font-size: 0.78rem;
  }

  .search-section {
    max-width: 100%;
  }

  .search-input {
    font-size: 16px; /* Prevents auto-zoom on iOS */
    padding: 0.75rem 2.8rem 0.75rem 0.9rem;
  }

  .grid-container {
    overflow-x: auto;
    padding-bottom: 0.6rem;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border-radius: var(--radius-md);
  }

  .grid-header, .guess-row {
    min-width: 780px;
    grid-template-columns: minmax(140px, 1.8fr) repeat(7, minmax(85px, 1.1fr));
    gap: 0.35rem;
    padding: 0 0.35rem;
  }

  .grid-header {
    padding: 0.4rem 0.35rem;
  }

  .grid-header-col {
    font-size: 0.66rem;
  }

  /* Sticky House Column on Mobile */
  .grid-header-col[data-col="house"],
  .guess-row .cell-house {
    position: sticky;
    left: 0;
    z-index: 10;
    box-shadow: 3px 0 8px rgba(0, 0, 0, 0.4);
  }

  .grid-header-col[data-col="house"] {
    background: var(--bg-surface);
  }

  .guess-row .cell-house {
    background: var(--bg-surface);
  }

  .cell {
    min-height: 3.8rem;
    font-size: 0.75rem;
    padding: 0.3rem 0.2rem;
  }
  
  .cell-house {
    font-size: 0.8rem;
  }

  .color-dot {
    width: 0.95rem;
    height: 0.95rem;
  }
  
  .cell-subtext, .weapon-pill {
    font-size: 0.65rem;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }

  .modal-container {
    width: 94vw;
    max-height: 88vh;
    padding: 1.2rem;
  }
}

@media (max-width: 480px) {
  .logo-title {
    font-size: 1.45rem;
  }

  .logo-subtitle {
    font-size: 0.62rem;
  }

  .lives-hearts {
    gap: 0.15rem;
  }

  .heart {
    font-size: 0.95rem;
  }

  .toast {
    padding: 0.6rem 1.1rem;
    font-size: 0.82rem;
  }
}

