:root {
  --bg: #2c2f33;
  --text: #e3e6ea;
  --card-bg: #36393f;
  --accent: #4d6bfe;
  --accent-hover: #4166d5;
  --accent-contrast: #ffffff;
}

.light {
  --bg: #f5f6f8;
  --text: #1f1f24;
  --card-bg: #ffffff;
  --accent: #4d6bfe;
  --accent-hover: #2e55d4;
  --accent-contrast: #ffffff;
  color-scheme: light;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background-color 0.25s, color 0.25s;
}

#button-wrapper {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  z-index: 15;
}

#button-wrapper button {
  width: 44px;
  height: 44px;
  font-size: 1.7em;
  background: transparent;
  border: none;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#button-wrapper button#new-word-toggle {
  width: 44px;
  height: 44px;
  font-size: 2.04em;
}

#button-wrapper button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  #button-wrapper {
    flex-direction: row;
    gap: 15px;
  }
}

#filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  z-index: 10;
}

.filter {
  position: relative;
}

.filter-title {
  width: 160px;
  max-width: 160px;
  height: 43px;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  box-sizing: border-box;
  transition: background 0.2s;
}

.filter-title:hover,
.filter-title:focus-visible {
  background: var(--accent-hover);
}

.badge {
  display: none;
  background: var(--accent-contrast);
  color: var(--accent);
  font-size: 0.75em;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 10px;
  margin-right: 6px;
}

.filter.open .filter-title i {
  transform: rotate(180deg);
}

.filter-options {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 220px;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: none;
  z-index: 5;
}

.filter.open .filter-options {
  display: block;
}

.filter-options-inner {
  max-height: 220px;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .filter-options {
    width: 160px;
  }
}

.filter-options-inner label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.filter-options-inner label:hover {
  background: var(--accent-hover);
  color: var(--accent-contrast);
}

.filter-options-inner input {
  accent-color: var(--accent);
}

.filter-options-inner label.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.filter-options-inner::-webkit-scrollbar {
  width: 8px;
}

.filter-options-inner::-webkit-scrollbar-track {
  background: var(--card-bg);
  border-radius: 8px;
}

.filter-options-inner::-webkit-scrollbar-thumb {
  background: var(--accent-hover);
  border-radius: 8px;
}

#flashcards-container {
  width: 90vw;
  max-width: 1000px;
  aspect-ratio: 1000 / 700;
  position: relative;
  perspective: 1000px;
  min-height: 420px;
  z-index: 1;
}

.card {
  width: 100%;
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  cursor: pointer;
  background: var(--card-bg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  will-change: transform;
  transition: transform 0.6s ease-in-out;
}

.face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  box-sizing: border-box;
}

.front {
  font-size: 4em;
  font-weight: 600;
}

.definition-front {
  font-size: 2em;
  font-weight: 500;
}

.back {
  transform: rotateX(180deg);
}

.word-back {
  font-size: 3em;
  font-weight: 600;
  margin: 12px 0;
}

.ipa {
  font-size: 2em;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
}

.speaker-icon {
  margin-left: 12px;
  font-size: 1.2em;
  cursor: pointer;
  user-select: none;
}

.definition,
.example {
  font-size: 1.2em;
  margin: 8px 0;
}

.definition {
  font-style: italic;
}

.back img {
  max-width: 100%;
  max-height: 40%;
  margin-top: 15px;
  border-radius: 6px;
  object-fit: contain;
}

#controls {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  width: 90vw;
  max-width: 1000px;
  justify-content: center;
  z-index: 0;
}

#controls button {
  flex: 1;
  max-width: 160px;
  max-height: 43px;
  padding: 12px 0;
  font-size: 1em;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#controls button:hover,
#controls button:focus-visible {
  background: var(--accent-hover);
}

#controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.slide-in {
  animation: slideIn 0.24s ease both;
}

.slide-out {
  animation: slideOut 0.25s ease-out forwards;
}

@keyframes slideIn {
  from {
    transform: translateX(var(--dist));
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(var(--dist));
    opacity: 0;
  }
}

.empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  padding: 0 20px;
  text-align: center;
}

@media (prefers-color-scheme: light) {
  :root:not(.light) {
    --bg: #ffffff;
    --text: #000000;
    --card-bg: #f9f9f9;
    --accent: #4d6bfe;
    --accent-hover: #2e55d4;
    --accent-contrast: #ffffff;
    color-scheme: light;
  }
}

#add-word-screen {
  display: none;
  width: 90vw;
  max-width: 1000px;
  min-height: 420px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
}

body.add-mode #add-word-screen {
  display: flex;
}

body.add-mode #filters,
body.add-mode #flashcards-container,
body.add-mode #controls {
  display: none;
}

#new-word-input {
  width: min(560px, 90%);
  height: 52px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: transparent;
  color: var(--text);
  font-size: 1.3em;
  padding: 0 14px;
  outline: none;
}

#new-word-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 107, 254, 0.25);
}

#add-word-btn {
  width: min(220px, 90%);
  height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1em;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
}

#add-word-btn:hover,
#add-word-btn:focus-visible {
  background: var(--accent-hover);
}

#add-word-btn:active {
  transform: scale(0.99);
}

#add-word-toast {
  height: 18px;
  font-size: 0.95em;
  opacity: 0.9;
}

#add-word-screen.added {
  animation: addedPop 0.22s ease-out both;
}

@keyframes addedPop {
  from {
    transform: scale(0.985);
  }
  to {
    transform: scale(1);
  }
}

