/* -- Reset & base -- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #040714;
  --surface-1: rgba(255,255,255,.03);
  --surface-2: rgba(255,255,255,.06);
  --surface-3: rgba(255,255,255,.09);
  --border-subtle: rgba(255,255,255,.07);
  --border: rgba(255,255,255,.1);
  --border-strong: rgba(255,255,255,.22);
  --text-primary: #f9f9f9;
  --text-secondary: #cacaca;
  --text-muted: rgba(255,255,255,.45);
  --accent: #c084fc;
  --accent-bright: #d8b4fe;
  --accent-dim: rgba(192,132,252,.12);
  --accent-glow: rgba(192,132,252,.06);
  --font: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem;
  --text-lg: 1.125rem; --text-xl: 1.25rem; --text-2xl: 1.5rem;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 15px;
  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 120ms; --dur: 200ms;
}

body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
  color: var(--text-primary);
  display: flex; flex-direction: column;
  overflow-x: hidden;
}

/* -- Layout -- */
.container {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 30px;
  flex: 1;
  position: relative;
  z-index: 1;
}

.hidden { display: none !important; }

/* -- Header -- */
.header-bar {
  background: linear-gradient(in oklch 135deg, #B015B0 0%, #3D0080 50%, #040714 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-6);
  height: 68px;
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
}

.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.header-logo-img {
  height: 36px; width: auto; flex-shrink: 0;
  filter: brightness(0) invert(1);
  transition: transform 0.3s var(--ease-snap);
  display: block;
}
.header-logo-img:hover { transform: scale(1.14) rotate(-9deg); }

.header-logo h1 { font-size: 1.2em; font-weight: 600; color: var(--text-primary); letter-spacing: .5px; }
.header-subtitle { font-size: .82em; color: rgba(255,255,255,.72); font-weight: 500; margin-top: 3px; }

.header-home {
  display: flex; align-items: center;
  padding: 5px;
  color: rgba(255,255,255,0.9); text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur); flex-shrink: 0;
}
.header-home:hover { color: #fff; background: rgba(255,255,255,0.12); }
.header-home svg { width: 34px; height: 34px; display: block; }

/* -- Canvas dot-map background -- */
.bg-shapes {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* -- Word of the day -- */
.word-of-day {
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-4);
  background: var(--accent-dim);
  border: 1px solid rgba(192,132,252,.15);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--dur);
  text-align: center;
}

.word-of-day:hover {
  border-color: var(--accent);
  background: rgba(192,132,252,.1);
}

.wod-prompt {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.5;
}

.wod-term {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--accent-bright);
  letter-spacing: 0.5px;
}

.wod-flag {
  font-size: var(--text-base);
  margin-left: 6px;
}

.wod-meaning {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

/* -- Search area -- */
.search-area {
  margin-bottom: var(--space-4);
}

.search-wrap {
  position: relative;
  margin-bottom: var(--space-3);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--dur);
}

.search-input:focus ~ .search-icon,
.search-wrap:focus-within .search-icon { color: var(--accent); }

.search-input {
  width: 100%;
  padding: 18px 52px 18px 52px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font: inherit;
  font-size: var(--text-lg);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
  backdrop-filter: blur(16px);
}

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

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 8px 32px rgba(192,132,252,0.08);
  background: rgba(255,255,255,.05);
}

.search-clear {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  border: none;
  color: var(--text-muted);
  font-size: 1.2em;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur);
  line-height: 1;
}
.search-clear:hover { color: var(--text-primary); background: var(--surface-3); }

/* -- Filter bar -- */
.filter-bar {
  display: flex;
  gap: var(--space-2);
}

.filter-select {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  outline: none;
  transition: border-color var(--dur);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.45)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.filter-select:focus {
  border-color: var(--accent);
}

.filter-select option {
  background: #0d0f1a;
  color: var(--text-primary);
}

/* -- Intro state -- */
.intro-state {
  text-align: center;
  padding: var(--space-8) 0 var(--space-8);
}

.intro-text {
  color: var(--text-muted);
  font-size: var(--text-lg);
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.intro-examples {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
}

.example-pill {
  padding: 8px 18px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--accent);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
  backdrop-filter: blur(8px);
}

.example-pill:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(192,132,252,0.12);
}

/* -- Result cards (multiple matches) -- */
.result-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  width: 100%;
  text-align: left;
  padding: var(--space-4) var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  cursor: pointer;
  font: inherit;
  color: var(--text-primary);
  transition: all var(--dur);
  animation: fadeIn 0.25s ease-out both;
  backdrop-filter: blur(10px);
}

.result-card:hover {
  border-color: var(--accent);
  border-left-color: var(--accent-bright);
  background: var(--surface-2);
  transform: translateX(4px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.result-body { flex: 1; }

.result-term {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: 4px;
}

.result-flags {
  font-size: var(--text-base);
  margin-left: var(--space-2);
}

.result-meaning {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-bottom: 4px;
}

.result-category {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.result-arrow {
  color: var(--text-muted);
  font-size: 1.2em;
  margin-top: 6px;
  transition: transform var(--dur), color var(--dur);
}

.result-card:hover .result-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

/* -- No results -- */
.no-results {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-8) 0;
  font-size: var(--text-base);
}

/* -- Diagram -- */
.diagram-area {
  position: relative;
  width: 100%;
  min-height: 400px;
  margin: 0;
  padding: 0 var(--space-4);
}

.diagram-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.diagram-line {
  animation: lineIn 0.5s ease-out both;
}

@keyframes lineIn {
  from { stroke-dashoffset: 200; opacity: 0; }
  to { stroke-dashoffset: 0; opacity: 1; }
}

/* -- Diagram center node -- */
.diagram-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  background: rgba(192,132,252,0.08);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 16px 28px;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: 0 0 40px rgba(192,132,252,0.1), inset 0 0 20px rgba(192,132,252,0.03);
  animation: centerIn 0.4s var(--ease-snap) both;
  max-width: 240px;
}

@keyframes centerIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.center-term {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--accent-bright);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.center-meaning {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.4;
}

.center-category {
  font-size: 0.65rem;
  color: rgba(255,255,255,.3);
  margin-top: 6px;
}

/* -- Diagram nodes -- */
.diagram-nodes {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.diagram-node {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(4,7,20,0.85);
  border: 1px solid var(--border);
  border-left: 3px solid var(--node-color, var(--border));
  border-radius: var(--radius);
  padding: 10px 14px;
  text-align: left;
  backdrop-filter: blur(12px);
  min-width: 100px;
  max-width: 170px;
  cursor: default;
  transition: transform var(--dur), box-shadow var(--dur), border-color var(--dur);
  animation: nodeIn 0.4s var(--ease-snap) both;
}

.diagram-node:hover {
  transform: translate(-50%, -50%) scale(1.06);
  box-shadow: 0 0 24px color-mix(in srgb, var(--node-color) 20%, transparent);
  z-index: 10;
  border-color: var(--node-color);
}

.diagram-node.matched {
  border-left-width: 4px;
  background: color-mix(in srgb, var(--node-color) 6%, rgba(4,7,20,0.9));
  box-shadow: 0 0 20px color-mix(in srgb, var(--node-color) 15%, transparent);
}

@keyframes nodeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.6) translateY(8px); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1) translateY(0); }
}

.node-flags {
  font-size: var(--text-sm);
  margin-bottom: 3px;
  letter-spacing: 2px;
}

.node-term {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.node-countries {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 3px;
}

.node-note {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 3px;
  opacity: 0.7;
}

/* -- Back button -- */
.diagram-back {
  position: absolute;
  top: 16px;
  left: 24px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  backdrop-filter: blur(12px);
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
}

.diagram-back:hover,
.diagram-share:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.diagram-back svg,
.diagram-share svg {
  width: 14px;
  height: 14px;
}

.diagram-share {
  position: absolute;
  top: 16px;
  left: 104px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  backdrop-filter: blur(12px);
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
}

.center-flag {
  font-size: var(--text-lg);
  margin-left: 4px;
}

/* -- Browse section -- */
.browse-area {
  margin-top: var(--space-4);
}

.browse-section {
  margin-bottom: var(--space-8);
}

.browse-heading {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cat-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.browse-expand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  margin-top: var(--space-2);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
}

.browse-expand:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.browse-expand svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur);
}

.browse-expand.expanded svg {
  transform: rotate(180deg);
}

.browse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: var(--space-3);
}

.browse-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  color: var(--text-primary);
  transition: all var(--dur);
  backdrop-filter: blur(10px);
}

.browse-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.browse-hero {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--accent-bright);
  margin-bottom: var(--space-2);
  letter-spacing: 0.3px;
  line-height: 1.3;
}

.browse-hero-flag {
  font-size: var(--text-base);
  margin-left: 4px;
}

.browse-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-3);
}

.browse-term {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-2);
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.browse-term-flags {
  font-size: var(--text-xs);
  letter-spacing: 1px;
}

.browse-meaning {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
}

.browse-more {
  font-size: var(--text-xs);
  color: var(--accent);
  padding: 4px 10px;
  align-self: center;
}

/* -- Toast -- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: #1a1730; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 10px 16px;
  font-size: 0.84rem; color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.55);
  pointer-events: none;
  transform: translateY(8px); opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* -- Focus & a11y -- */
:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent-bright);
  color: #000;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--dur);
}
.skip-link:focus { top: 0; }

/* -- Button press -- */
button:active:not(.diagram-node):not(.diagram-back) {
  transform: scale(0.97);
  transition-duration: var(--dur-fast);
}

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

/* -- Reduced motion -- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* -- Responsive -- */
@media (max-width: 600px) {
  .header-bar { padding: 0 var(--space-4); }
  .container { padding: var(--space-4); }

  .search-input {
    font-size: var(--text-base);
    padding: 14px 44px 14px 48px;
  }

  .diagram-area { min-height: 360px; }

  .diagram-center {
    padding: 12px 18px;
    max-width: 180px;
  }

  .center-term { font-size: var(--text-lg); }
  .center-meaning { font-size: 0.7rem; }

  .diagram-node {
    padding: 8px 10px;
    min-width: 80px;
    max-width: 130px;
  }

  .node-term { font-size: var(--text-xs); }
  .node-countries { font-size: 0.65rem; }
  .node-flags { font-size: var(--text-xs); }

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

  .filter-bar {
    flex-direction: column;
  }
}

@media (max-width: 400px) {
  .diagram-area { min-height: 300px; }
  .diagram-node { min-width: 65px; max-width: 110px; padding: 6px 8px; }
}
