:root {
  --bg: #091a2c;
  --bg-soft: #10263c;
  --panel: #11253a;
  --panel-strong: #13283f;
  --panel-raised: #17314d;
  --border: rgba(77, 148, 255, 0.24);
  --border-strong: rgba(77, 148, 255, 0.42);
  --primary: #4d9cff;
  --primary-strong: #6ab0ff;
  --primary-glow: rgba(77, 156, 255, 0.32);
  --text: #eef5ff;
  --muted: #a5b8cd;
  --muted-strong: #c8d8ea;
  --chip: #152a41;
  --chip-active: #2b5888;
  --sidebar-width: 255px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top center, rgba(77, 156, 255, 0.08), transparent 28%),
    linear-gradient(180deg, #081626 0%, #091a2c 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px 16px 14px;
  background: rgba(14, 31, 48, 0.94);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.9rem;
  line-height: 0.95;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  width: 28px;
  height: 28px;
}

.brand-mark span {
  border: 2px solid var(--primary);
  border-radius: 4px;
}

.sidebar-nav {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scroll-behavior: smooth;
}

.nav-link {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.9rem;
}

.nav-link.active {
  background: rgba(77, 156, 255, 0.18);
  color: var(--primary);
}

.nav-icon {
  font-size: 1.2rem;
}

.nav-link span:not(.nav-icon) {
  display: none;
}

.main-panel {
  padding: 18px 14px 40px;
}

.view {
  display: none;
  max-width: 980px;
  margin: 0 auto;
}

.view.active {
  display: block;
}

.view-heading {
  margin-bottom: 28px;
}

.view-heading.center {
  text-align: center;
}

.view-heading h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 7vw, 3.7rem);
  line-height: 1.05;
}

.view-heading p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.search-block {
  width: min(100%, 700px);
  margin: 0 auto 28px;
}

.search-input {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 0 18px;
  background: var(--panel);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 0 0 0 var(--primary-glow);
}

.search-input:focus-within {
  box-shadow: 0 0 0 6px rgba(77, 156, 255, 0.08);
}

.search-input input {
  width: 100%;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 1.08rem;
}

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

.search-icon {
  color: var(--muted);
  font-size: 1.35rem;
}

.search-preview {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.search-result-card,
.browse-word-card,
.letter-summary-card,
.stat-card,
.detail-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.search-result-card,
.browse-word-card {
  width: 100%;
  text-align: left;
  padding: 16px 18px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.search-result-card:hover,
.browse-word-card:hover,
.letter-summary-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.result-line,
.browse-word-line {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.result-word,
.browse-word {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.9rem;
  line-height: 1.05;
}

.result-summary,
.browse-summary {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.tag-row,
.detail-tags,
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag,
.chip,
.meta-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted-strong);
  font-size: 0.9rem;
}

.tag.primary,
.meta-pill.primary {
  color: var(--primary-strong);
  border-color: rgba(77, 156, 255, 0.5);
  background: rgba(77, 156, 255, 0.14);
}

.home-section + .home-section {
  margin-top: 28px;
}

.section-heading {
  margin-bottom: 14px;
  text-align: center;
}

.section-kicker {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
  font-size: 0.86rem;
}

.chip-grid {
  justify-content: center;
}

.chip {
  min-width: 40px;
  min-height: 40px;
  padding: 0 14px;
  background: var(--chip);
  cursor: pointer;
}

.chip.active,
.chip:hover {
  border-color: var(--border-strong);
  background: var(--chip-active);
  color: var(--text);
  box-shadow: 0 0 20px rgba(77, 156, 255, 0.18);
}

.stats-grid {
  margin-top: 38px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 20px 16px;
  text-align: center;
}

.stat-card strong {
  display: block;
  color: var(--primary);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 6vw, 2.8rem);
}

.stat-card span {
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.back-link {
  margin-bottom: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 1.15rem;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.browse-content-grid,
.browse-letters-grid {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.browse-letters-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.letter-summary-card {
  padding: 24px 18px;
  text-align: center;
  cursor: pointer;
}

.letter-summary-card strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 8vw, 3.8rem);
  color: var(--primary);
}

.letter-summary-card span {
  color: var(--muted);
  font-size: 1rem;
}

.browse-letter-banner {
  margin-top: 26px;
  padding: 24px 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.browse-letter-banner strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 11vw, 5rem);
  color: var(--primary);
  line-height: 0.95;
}

.browse-letter-banner span {
  color: var(--muted);
  font-size: 1rem;
}

.browse-content-grid.words {
  grid-template-columns: 1fr;
}

.detail-card {
  padding: 26px 20px;
}

.detail-title-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.detail-title-row h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 11vw, 5rem);
  line-height: 0.95;
}

.word-homonym {
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 700;
}

.detail-tags {
  margin-top: 16px;
}

.detail-sections {
  display: grid;
  gap: 28px;
  margin-top: 28px;
}

.detail-section h3 {
  margin: 0 0 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.88rem;
}

.definition-stack {
  display: grid;
  gap: 16px;
}

.definition-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}

.definition-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(77, 156, 255, 0.18);
  color: var(--primary-strong);
  font-weight: 700;
}

.definition-content strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.35rem;
}

.definition-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.definition-prefix {
  color: var(--primary-strong);
}

.meta-list {
  display: grid;
  gap: 12px;
}

.meta-row {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.meta-row span {
  color: var(--muted);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.meta-row strong,
.meta-row div {
  color: var(--text);
  line-height: 1.6;
}

.raw-entry {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  line-height: 1.8;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

@media (min-width: 720px) {
  .main-panel {
    padding: 30px 26px 48px;
  }

  .browse-content-grid.words {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .browse-letters-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  .sidebar {
    min-height: 100vh;
    padding: 28px 22px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 0;
  }

  .sidebar-nav {
    display: grid;
    gap: 10px;
    overflow: visible;
  }

  .nav-link {
    justify-content: flex-start;
    padding: 0 16px;
    font-size: 1rem;
  }

  .nav-link span:not(.nav-icon) {
    display: inline;
  }

  .main-panel {
    padding: 42px 44px 52px;
  }

  .browse-letters-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* ==========================================================================
   Domains, Favorites, & History Custom Styles
   ========================================================================== */

/* Domains Overview Layout */
.domains-overview-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  margin-top: 28px;
}

@media (min-width: 600px) {
  .domains-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .domains-overview-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.domain-overview-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 140px;
  padding: 24px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  transition: transform 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.domain-overview-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
}

.domain-overview-card::before {
  content: "";
  position: absolute;
  top: -50%;
  right: -50%;
  width: 150px;
  height: 150px;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.15;
  pointer-events: none;
  background: var(--accent-gradient, radial-gradient(circle, var(--primary) 0%, transparent 70%));
  transition: opacity 200ms ease;
}

.domain-overview-card:hover::before {
  opacity: 0.28;
}

.domain-overview-card strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  line-height: 1.25;
  color: var(--text);
}

.domain-overview-card span {
  margin-top: 12px;
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* Domain Detail Elements */
.domain-header-banner {
  margin-top: 20px;
  padding: 36px 24px;
  text-align: center;
  background: linear-gradient(135deg, rgba(77, 156, 255, 0.1) 0%, rgba(16, 38, 60, 0.4) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.domain-header-banner::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 250px;
  height: 250px;
  border-radius: 999px;
  background: radial-gradient(circle, var(--primary) 0%, transparent 65%);
  filter: blur(60px);
  opacity: 0.18;
  pointer-events: none;
}

.domain-header-banner h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 8vw, 3.8rem);
  color: var(--primary-strong);
  line-height: 1.05;
  position: relative;
  z-index: 1;
}

.domain-header-banner p {
  margin: 8px 0 0;
  color: var(--muted-strong);
  font-size: 1.05rem;
  position: relative;
  z-index: 1;
}

.domain-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 28px 0;
}

@media (min-width: 600px) {
  .domain-controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  
  .domain-controls .search-block.inline {
    flex: 1;
    max-width: 380px;
    margin: 0;
  }
}

.search-block.inline {
  width: 100%;
}

.chip-grid.small .chip {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
  border-radius: 9px;
}

/* History view Controls */
.history-controls-row {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
}

@media (min-width: 600px) {
  .history-controls-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  
  .history-controls-row .search-block.inline {
    flex: 1;
    max-width: 380px;
    margin: 0;
  }
}

.clear-history-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 58px;
  padding: 0 22px;
  border-radius: 18px;
  border: 1px solid rgba(255, 77, 77, 0.28);
  background: rgba(255, 77, 77, 0.06);
  color: #ff6b6b;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.clear-history-btn:hover {
  background: rgba(255, 77, 77, 0.14);
  border-color: rgba(255, 77, 77, 0.46);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(255, 77, 77, 0.08);
}

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

/* Detail view Flex Layout & Star Button */
.detail-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

.favorite-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
  flex-shrink: 0;
}

.favorite-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-strong);
  transform: scale(1.08);
}

.favorite-toggle-btn:active {
  transform: scale(0.96);
}

.favorite-toggle-btn .star-icon {
  font-size: 1.75rem;
  color: var(--muted);
  transition: color 180ms ease, transform 180ms ease;
  line-height: 1;
}

.favorite-toggle-btn.active {
  border-color: rgba(255, 193, 7, 0.44);
  background: rgba(255, 193, 7, 0.15);
  box-shadow: 0 0 16px rgba(255, 193, 7, 0.22);
}

.favorite-toggle-btn.active .star-icon {
  color: #ffc107;
  transform: scale(1.08);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.01);
  border: 2px dashed rgba(77, 148, 255, 0.16);
  border-radius: var(--radius-lg);
  margin-top: 20px;
}

.empty-state-icon {
  font-size: 3.5rem;
  color: rgba(77, 148, 255, 0.3);
  margin-bottom: 18px;
  line-height: 1;
}

.empty-state h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  color: var(--text);
}

.empty-state p {
  margin: 8px 0 22px;
  color: var(--muted);
  max-width: 340px;
  font-size: 0.96rem;
  line-height: 1.6;
}

.empty-state-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: rgba(77, 156, 255, 0.16);
  color: var(--primary-strong);
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.empty-state-action:hover {
  background: rgba(77, 156, 255, 0.26);
  transform: translateY(-2px);
  box-shadow: 0 0 16px rgba(77, 156, 255, 0.18);
}

/* Sentinel element for infinite scrolls */
.sentinel {
  height: 30px;
  margin-top: 12px;
  opacity: 0;
  pointer-events: none;
}

