*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0e0c;
  --surface: #1a1916;
  --border: #2e2c28;
  --accent: #e8c84a;
  --accent-dim: #b89c2e;
  --text: #f0ead8;
  --muted: #6b6455;
  --en-color: #7ec8a4;
  --pt-color: #e8844a;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "DM Mono", monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}

/* Subtle grain texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

.wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 620px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 8px;
}
.logo {
  font-family: "Fraunces", serif;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 300;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}
.logo em {
  font-style: italic;
  color: var(--accent);
}
.sub {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* Unit selector */
.unit-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
  transition: all 0.3s ease;
}
.unit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
}
.unit-header:hover {
  background: rgba(255, 255, 255, 0.02);
}
.unit-label {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}
.unit-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.unit-selected-pill {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: #0f0e0c;
  background: var(--accent);
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 500;
  display: none;
}
.unit-selected-pill.visible {
  display: block;
}
.unit-chevron {
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.3s ease;
  line-height: 1;
}
.unit-chevron.open {
  transform: rotate(180deg);
}
.unit-body {
  padding: 0 20px 20px;
  display: none;
}
.unit-body.open {
  display: block;
}
.unit-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.unit-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.unit-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}
.unit-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f0e0c;
  font-weight: 500;
}
/* Units up to selected: slightly lit */
.unit-btn.in-range {
  border-color: #3a3830;
  color: var(--text);
  background: #1f1e1b;
}
.unit-info {
  margin-top: 12px;
  font-size: 0.7rem;
  color: var(--muted);
}
.unit-info span {
  color: var(--accent);
}

/* Translate link */
.translate-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}
.translate-link.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.translate-link:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
}
.translate-link svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
  flex-shrink: 0;
}
#quizArea {
  height: calc(100vh-4rem);
}

/* Card */
.card-wrap {
  min-height: 50vh;
  perspective: 1000px;
  margin-bottom: 20px;
}
.card {
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease;
}
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--lang-color, var(--accent));
  transition: background 0.3s ease;
}
.lang-tag {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--lang-color, var(--accent));
  color: #0f0e0c;
  font-weight: 500;
  transition: background 0.3s ease;
}
.unit-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.prompt-text {
  height: 100%;
  font-family: "Fraunces", serif;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  font-weight: 300;
  line-height: 1.4;
  color: var(--text);
  transition: opacity 0.2s ease;
}
.prompt-text.hidden {
  opacity: 0;
}

/* Answer reveal */
.answer-area {
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  width: 100%;
}
.answer-text {
  height: 100%;
  font-family: "Fraunces", serif;
  font-size: clamp(1.1rem, 3.5vw, 1.5rem);
  font-weight: 300;
  font-style: italic;
  color: var(--accent);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.35s ease,
    transform 0.35s ease;
  text-align: center;
  line-height: 1.4;
}
.answer-text.visible {
  opacity: 1;
  transform: translateY(0);
}
.answer-lang {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-style: normal;
  font-family: "DM Mono", monospace;
  display: block;
  margin-bottom: 8px;
}

/* Buttons */
.btn-row {
  display: flex;
  gap: 12px;
}
.btn {
  flex: 1;
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
}
.btn-reveal {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f0e0c;
  font-weight: 500;
}
.btn-reveal:hover {
  background: #f0d454;
  border-color: #f0d454;
}
.btn-next {
  background: transparent;
  color: var(--muted);
}
.btn-next:hover {
  border-color: var(--text);
  color: var(--text);
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Stats bar */
.stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat {
  text-align: center;
}
.stat-val {
  font-size: 1.4rem;
  font-family: "Fraunces", serif;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.stat-lbl {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

/* Flip animation */
@keyframes cardFlip {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(8deg);
    opacity: 0.7;
  }
  100% {
    transform: rotateY(0deg);
  }
}
.card.flip {
  animation: cardFlip 0.3s ease;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.8;
}

@media (max-width: 480px) {
  body {
    padding: 0;
    min-height: 100vh;
    overflow-y: auto;
  }
  .sub {
    display: none;
  }
  .wrap {
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100%;
  }
  
  /* Fixed unit selector at top */
  .unit-section {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .unit-header {
    padding: 12px 12px;
  }
  .unit-label {
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    white-space: nowrap;
  }
  .unit-selected-pill {
    font-size: 0.6rem;
    padding: 2px 6px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .unit-header-right {
    gap: 6px;
  }
  .unit-chevron {
    font-size: 0.7rem;
  }
  .unit-body {
    max-height: 50vh;
    overflow-y: auto;
    background: var(--surface);
  }
  .unit-btn {
    width: 36px;
    height: 36px;
    font-size: 0.7rem;
  }
  
  /* Quiz area fills remaining space */
  #quizArea {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    margin-top: 56px; /* Space for fixed unit bar */
    margin-bottom: 180px; /* Space for fixed bottom controls */
    overflow: hidden;
  }
  
  /* Card fills available space */
  .card-wrap {
    flex: 1;
    margin-bottom: 0;
    min-height: auto;
  }
  .card {
    height: 100%;
    min-height: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
  }
  
  /* Split layout: prompt on top, answer on bottom */
  .prompt-text {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto;
    font-size: clamp(1.4rem, 5vw, 2rem);
    padding: 20px 0;
  }
  
  .answer-area {
    flex: 1;
    min-height: auto;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--border);
  }
  
  .answer-text {
    height: auto;
    font-size: clamp(1.3rem, 4.5vw, 1.8rem);
  }
  
  /* Fixed bottom controls */
  .btn-row {
    position: fixed;
    bottom: 80px;
    left: 8px;
    right: 8px;
    z-index: 100;
    flex-direction: column;
    gap: 8px;
  }
  
  .stats {
    position: fixed;
    bottom: 8px;
    left: 8px;
    right: 8px;
    z-index: 100;
    margin-top: 0;
    gap: 20px;
    border-radius: var(--radius);
  }
  
  .btn-next {
    display: none;
  }
  
  /* Empty state positioning */
  .empty {
    margin-top: 60px;
    padding: 40px 20px;
  }
}
