:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #2b2620;
  --text-dim: #797264;
  --border: #e3ddd0;
  --accent: #b5432b;
  --accent-soft: #f0ddd6;
  --easy: #3f8f5f;
  --easy-soft: #dcefe2;
  --medium: #c98a1f;
  --medium-soft: #f6e7cd;
  --hard: #b5432b;
  --hard-soft: #f5ddd4;
  --shadow: 0 2px 10px rgba(43, 38, 32, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #26231e;
    --text: #ede8de;
    --text-dim: #a89e8c;
    --border: #3a352c;
    --accent: #e07856;
    --accent-soft: #3a2822;
    --easy: #6fc290;
    --easy-soft: #1e3327;
    --medium: #e3ab4f;
    --medium-soft: #3a2f18;
    --hard: #e07856;
    --hard-soft: #3a2620;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #1c1a17;
  --surface: #26231e;
  --text: #ede8de;
  --text-dim: #a89e8c;
  --border: #3a352c;
  --accent: #e07856;
  --accent-soft: #3a2822;
  --easy: #6fc290;
  --easy-soft: #1e3327;
  --medium: #e3ab4f;
  --medium-soft: #3a2f18;
  --hard: #e07856;
  --hard-soft: #3a2620;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #2b2620;
  --text-dim: #79726d;
  --border: #e3ddd0;
  --accent: #b5432b;
  --accent-soft: #f0ddd6;
  --easy: #3f8f5f;
  --easy-soft: #dcefe2;
  --medium: #c98a1f;
  --medium-soft: #f6e7cd;
  --hard: #b5432b;
  --hard-soft: #f5ddd4;
  --shadow: 0 2px 10px rgba(43, 38, 32, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.topbar {
  padding: 20px 20px 0;
  max-width: 720px;
  margin: 0 auto;
}
.topbar h1 {
  font-size: 1.4rem;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--accent-soft); color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-btn.active .badge { background: rgba(255,255,255,0.25); color: #fff; }

.badge {
  background: var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 14px;
  text-align: center;
}

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.view { display: none; }
.view.active { display: block; }

/* Study view */
.study-wrap { display: flex; flex-direction: column; align-items: center; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state p { margin: 6px 0; }
.empty-sub { font-size: 0.9rem; max-width: 380px; margin: 8px auto 0; }

.card-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.topic-tag {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  font-weight: 600;
}

.flashcard {
  width: 100%;
  max-width: 420px;
  height: 260px;
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: 22px;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.flashcard-face.back {
  transform: rotateY(180deg);
}

.article {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: lowercase;
  margin-bottom: 6px;
  min-height: 1.2em;
}
.german-word {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.pos-tag {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.english-word {
  font-size: 1.7rem;
  font-weight: 600;
}
.flip-hint {
  position: absolute;
  bottom: 14px;
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.7;
}

.rating-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}
.rate-btn {
  border: none;
  border-radius: 12px;
  padding: 12px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: inherit;
  transition: transform 0.1s, filter 0.15s;
}
.rate-btn:hover { filter: brightness(0.96); }
.rate-btn:active { transform: scale(0.97); }
.rate-label { font-weight: 700; font-size: 0.95rem; }
.rate-sub { font-size: 0.68rem; opacity: 0.75; }

.rate-btn.easy { background: var(--easy-soft); color: var(--easy); }
.rate-btn.medium { background: var(--medium-soft); color: var(--medium); }
.rate-btn.hard { background: var(--hard-soft); color: var(--hard); }

.discard-btn {
  margin-top: 18px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
.discard-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* List views */
.list-header { margin-bottom: 18px; }
.list-header h2 { margin: 0 0 4px; font-size: 1.2rem; }
.list-sub { margin: 0; color: var(--text-dim); font-size: 0.88rem; }

.word-list { display: flex; flex-direction: column; gap: 8px; }

.word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.word-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.word-row-de { font-weight: 700; font-size: 1rem; }
.word-row-de .article { display: inline; font-size: 0.85em; margin-right: 4px; }
.word-row-en { color: var(--text-dim); font-size: 0.85rem; }
.word-row-topic { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

.word-row-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.chip-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.empty-list-msg { color: var(--text-dim); padding: 30px 10px; text-align: center; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { font-size: 0.78rem; color: var(--text-dim); margin-top: 4px; }

.stats-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.secondary-btn, .danger-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
.secondary-btn:hover { background: var(--accent-soft); }
.danger-btn { color: var(--hard); border-color: var(--hard-soft); }
.danger-btn:hover { background: var(--hard-soft); }

@media (max-width: 480px) {
  .german-word { font-size: 1.6rem; }
  .flashcard { height: 220px; }
  .rate-sub { display: none; }
}
