:root {
  --bg: #f4f7ff;
  --bg-strong: #dce6ff;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #ffffff;
  --text: #111828;
  --muted: #5b6475;
  --accent: #0ea5a4;
  --accent-2: #ff7a59;
  --line: rgba(17, 24, 40, 0.1);
  --success: #0d9f6e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: linear-gradient(140deg, #eef4ff 0%, #fef6ec 55%, #f4fffb 100%);
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(6px);
  z-index: -1;
}

.bg-shape-1 {
  width: 280px;
  height: 280px;
  background: rgba(14, 165, 164, 0.2);
  left: -110px;
  top: -70px;
}

.bg-shape-2 {
  width: 320px;
  height: 320px;
  background: rgba(255, 122, 89, 0.22);
  right: -120px;
  bottom: -80px;
}

.app {
  width: min(980px, 96vw);
  margin: 10px auto;
  padding: 12px;
  min-height: calc(100vh - 20px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(22px, 4vw, 34px);
}

.pill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  backdrop-filter: blur(10px);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.stats-drawer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  backdrop-filter: blur(10px);
}

.stat p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.mode-switch {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px;
  backdrop-filter: blur(8px);
}

.mode {
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 8px;
  cursor: pointer;
}

.mode.active {
  background: var(--card-solid);
  color: var(--text);
  box-shadow: 0 4px 18px rgba(17, 24, 40, 0.08);
}

.folder-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
}

.folder-select {
  position: relative;
  flex: 1;
}

.folder-select-btn {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
}

.folder-select-btn::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

.folder-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(17, 24, 40, 0.12);
  overflow: hidden;
  z-index: 30;
}

.folder-actions {
  position: relative;
}

.folder-actions-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(17, 24, 40, 0.12);
  overflow: hidden;
  z-index: 40;
}

.folder-actions-menu button {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}

.folder-actions-menu button:last-child {
  border-bottom: none;
}

.folder-actions-menu button.danger {
  color: #c6452c;
}

.folder-item {
  width: 100%;
  background: #fff;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  font: inherit;
}

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

.folder-item.active {
  background: #eef7ff;
}

.panel {
  display: none;
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  backdrop-filter: blur(10px);
  animation: fadeIn 220ms ease;
  min-height: calc(100vh - 175px);
}

.panel.active {
  display: block;
}

.word-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.word-form input {
  color: var(--text);
  caret-color: var(--text);
}

.word-form input:focus {
  border-color: rgba(14, 165, 164, 0.65);
  box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.12);
  outline: none;
}

input,
button {
  font: inherit;
}

input {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 700;
}

button.primary,
.word-form button {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #0f8ea5);
}

button.ghost {
  background: #fff;
  border: 1px solid var(--line);
}

.word-list-wrap h2,
.quiz-start h2 {
  margin: 16px 0 8px;
}

.word-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 320px);
  overflow: auto;
}

.word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}

.word-item strong {
  display: block;
  font-size: 16px;
}

.word-item span {
  color: var(--muted);
  font-size: 14px;
}

.word-item-main {
  min-width: 0;
}

.word-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-item .word-speak {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
}

.speak-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.word-item .word-delete {
  background: transparent;
  border: 1px solid rgba(255, 122, 89, 0.4);
  color: #c6452c;
  border-radius: 10px;
  padding: 7px 10px;
}

.muted {
  color: var(--muted);
}

.card-area {
  perspective: 1200px;
  display: grid;
  gap: 10px;
}

.flashcard {
  width: min(100%, 920px);
  height: calc(100vh - 340px);
  min-height: 330px;
  max-height: 640px;
  margin: 0 auto;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
  cursor: pointer;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.card-side {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  border: 1px solid var(--line);
  display: grid;
  place-content: center;
  text-align: center;
  background: linear-gradient(140deg, #fff, #f7fbff);
  backface-visibility: hidden;
  padding: 14px;
}

.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(140deg, #fff9f1, #fff);
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.card-side h3 {
  margin: 8px 0 0;
  font-size: clamp(24px, 5vw, 42px);
}

.card-speak {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
}

.swipe-hint {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  font-weight: 700;
  color: var(--muted);
}

.swipe-hint span {
  font-size: 13px;
}

.flashcard.swiping-left {
  transition: transform 200ms ease;
  transform: translateX(-28px) rotate(-4deg);
}

.flashcard.swiping-right {
  transition: transform 200ms ease;
  transform: translateX(28px) rotate(4deg);
}

.flashcard.swiping-up {
  transition: transform 200ms ease;
  transform: translateY(-28px);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 40, 0.42);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 80;
}

.modal-content {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(17, 24, 40, 0.2);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.modal-title {
  margin: 0;
  font-size: 20px;
}

.modal-field {
  display: grid;
  gap: 8px;
}

#folderModalInput {
  caret-color: var(--text);
}

#folderModalInput:focus {
  border-color: rgba(14, 165, 164, 0.65);
  box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.12);
  outline: none;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-actions .danger {
  background: #fff;
  border: 1px solid rgba(198, 69, 44, 0.4);
  color: #c6452c;
}

.quiz-single {
  margin-top: 10px;
}

.quiz-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 14px;
}

.quiz-card h3 {
  margin: 0 0 10px;
  font-size: clamp(24px, 6vw, 38px);
}

.quiz-options {
  display: grid;
  gap: 10px;
}

.quiz-option-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.quiz-option-btn.correct {
  border-color: rgba(13, 159, 110, 0.5);
  background: rgba(13, 159, 110, 0.12);
}

.quiz-option-btn.wrong {
  border-color: rgba(198, 69, 44, 0.5);
  background: rgba(198, 69, 44, 0.1);
}

.quiz-feedback {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  font-weight: 700;
}

.quiz-result {
  margin-top: 14px;
  border: 1px solid rgba(13, 159, 110, 0.2);
  background: rgba(13, 159, 110, 0.1);
  color: #095b40;
  border-radius: 14px;
  padding: 12px;
  font-weight: 700;
}

#quizNext {
  margin-top: 10px;
  width: 100%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(17, 24, 40, 0.9);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
}

.hidden {
  display: none;
}

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

@media (max-width: 720px) {
  .stats-drawer {
    grid-template-columns: 1fr;
  }

  .word-form {
    grid-template-columns: 1fr;
  }

  .folder-bar {
    gap: 6px;
  }

  .swipe-hint {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel {
    min-height: calc(100vh - 210px);
  }

  .flashcard {
    height: calc(100vh - 390px);
    min-height: 290px;
  }
}
