:root {
  --color-bg: #eef8f6;
  --color-surface: #ffffff;
  --color-surface-alt: #f4fbfa;
  --color-border: #dcefec;
  --color-text: #1c2b2a;
  --color-muted: #7c9793;
  --color-primary: #2ec4b6;
  --color-primary-dark: #1fa294;
  --color-primary-light: #d7f5f1;
  --color-accent: #ff9f1c;
  --color-accent-light: #ffe8cc;
  --color-success: #2f9e44;
  --color-danger: #e8590c;
  --color-warning: #f08c00;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 26px;
  --shadow-sm: 0 2px 8px rgba(20, 60, 55, 0.06);
  --shadow: 0 10px 28px rgba(20, 60, 55, 0.09);
  --sidebar-width: 232px;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary-dark);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---- App shell: sidebar + header + content ---- */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 26px;
}
.sidebar-brand .brand-flag {
  font-size: 1.6rem;
}
.sidebar-brand .brand-text {
  font-weight: 800;
  font-size: 1.02rem;
  line-height: 1.15;
}
.sidebar-brand .brand-text small {
  display: block;
  font-weight: 500;
  color: var(--color-muted);
  font-size: 0.72rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  color: var(--color-text);
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.18s ease, color 0.18s ease, transform 0.15s ease;
}
.nav-item .nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}
.nav-item:hover {
  background: var(--color-primary-light);
  text-decoration: none;
  transform: translateX(2px);
}
.nav-item.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(46, 196, 182, 0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
}

.streak-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-accent-light);
  color: #b45500;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: var(--radius);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: rgba(238, 248, 246, 0.85);
  backdrop-filter: blur(6px);
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.3rem;
  margin: 0;
}
.app-header .header-subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.container {
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 4px 28px 32px;
}

/* ---- Cards ---- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 18px;
  animation: fadeInUp 0.45s ease both;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

input[type="text"],
input[type="number"],
select {
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--color-surface-alt);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 0;
  max-width: 100%;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--color-primary);
  color: #fff;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
button:hover:not(:disabled) {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(46, 196, 182, 0.3);
}
button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}
button.secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
button.secondary:hover:not(:disabled) {
  background: var(--color-primary-light);
  box-shadow: none;
}
button.success {
  background: var(--color-success);
}
button.danger {
  background: var(--color-danger);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge.new { background: #e7e9f5; color: #4c5bd4; }
.badge.learning { background: #fff3bf; color: #a1720a; }
.badge.known { background: #d3f9d8; color: #2b8a3e; }

.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  margin-left: 6px;
  cursor: pointer;
  vertical-align: middle;
  transition: transform 0.15s ease, background 0.15s ease;
}
.speak-btn:hover {
  background: var(--color-primary);
  color: #fff;
  transform: scale(1.1);
}
.speak-btn.speak-btn-light {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.speak-btn.speak-btn-light:hover {
  background: rgba(255, 255, 255, 0.4);
}

.badge.der { background: #d0ebff; color: #1864ab; }
.badge.die { background: #ffdeeb; color: #a61e4d; }
.badge.das { background: #e6fcf5; color: #087f5b; }

.word-table {
  width: 100%;
  border-collapse: collapse;
}
.word-table th,
.word-table td {
  text-align: left;
  padding: 11px 8px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.word-table tbody tr {
  transition: background 0.15s ease;
}
.word-table tbody tr:hover {
  background: var(--color-surface-alt);
}
.word-table th {
  font-size: 0.78rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.word-de {
  font-weight: 700;
}
.word-meta {
  color: var(--color-muted);
  font-size: 0.85rem;
}
.word-example {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-top: 4px;
}
.topic-group-title {
  margin: 24px 0 8px;
  font-size: 1rem;
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}
.topic-group-title .topic-group-name {
  flex: 1;
  min-width: 0;
}
.topic-card:first-child .topic-group-title {
  margin-top: 0;
}
.topic-toggle-btn,
.topic-pin-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 0.85rem;
  color: var(--color-muted);
  box-shadow: none;
}
.topic-toggle-btn:hover:not(:disabled),
.topic-pin-btn:hover:not(:disabled) {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  transform: none;
  box-shadow: none;
}
.topic-pin-btn {
  opacity: 0.45;
  filter: grayscale(1);
}
.topic-pin-btn.pinned {
  opacity: 1;
  filter: none;
  color: var(--color-accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: popIn 0.35s ease both;
}
.stat-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-sm);
}
.stat-tile .value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--color-primary-dark);
}
.stat-tile .label {
  font-size: 0.8rem;
  color: var(--color-muted);
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: var(--color-surface-alt);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 16px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-dark));
  border-radius: 999px;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- Charts (progress page) ---- */

.charts-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  align-items: start;
}

.donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: popIn 0.5s ease both;
}

.donut-chart {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.6s ease;
}

.donut-center {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.donut-center .donut-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-primary-dark);
}
.donut-center .donut-label {
  font-size: 0.72rem;
  color: var(--color-muted);
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.chart-legend .legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.chart-legend .legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chart-legend .legend-count {
  margin-left: auto;
  font-weight: 700;
  color: var(--color-text);
}

.topic-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 6px;
}
.topic-bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 56px;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.topic-bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
  font-weight: 600;
}
.topic-bar-track {
  height: 10px;
  background: var(--color-surface-alt);
  border-radius: 999px;
  overflow: hidden;
}
.topic-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-primary));
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
.topic-bar-pct {
  text-align: right;
  color: var(--color-muted);
  font-weight: 700;
  font-size: 0.8rem;
}

/* ---- Game tabs ---- */

.game-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.game-tab {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.game-tab:hover:not(:disabled) {
  background: var(--color-primary-light);
  box-shadow: none;
}
.game-tab.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ---- Matching game ---- */

.game-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.game-stats strong {
  color: var(--color-text);
}

.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.match-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.match-card {
  width: 100%;
  text-align: left;
  background: var(--color-surface-alt);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-text);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.3s ease;
}
.match-card:hover:not(:disabled) {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  background: var(--color-surface);
}
.match-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.match-card.correct {
  border-color: var(--color-success);
  background: #ebfbee;
  color: #2b8a3e;
  opacity: 0.55;
  cursor: default;
}
.match-card.wrong {
  border-color: var(--color-danger);
  background: #fff0eb;
  animation: cardShake 0.35s ease;
}

.match-complete {
  grid-column: 1 / -1;
}

/* ---- Fill-word game ---- */

.fill-meaning {
  font-size: 1.05rem;
  margin-bottom: 16px;
}

.fill-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  transition: transform 0.1s ease;
}
.fill-tiles.fill-wrong {
  animation: cardShake 0.35s ease;
}
.fill-tiles.fill-correct .fill-tile.revealed {
  border-color: var(--color-success);
  background: #ebfbee;
  color: #2b8a3e;
}

.fill-tile {
  width: 38px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface-alt);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
  text-transform: none;
  padding: 0;
}
.fill-tile.hint-slot {
  color: var(--color-muted);
  cursor: not-allowed;
  background: var(--color-surface);
}
.fill-tile.hint-slot.next-hint {
  cursor: pointer;
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-light);
}
.fill-tile.hint-slot.next-hint:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.fill-tile.revealed {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}
.fill-tile.fill-gap {
  border: none;
  background: transparent;
  width: 16px;
}

.fill-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.fill-controls input[type="text"] {
  flex: 1;
  min-width: 180px;
}

.fill-progress-text {
  margin: 14px 0 0;
}

/* ---- Special German character helper buttons ---- */

.special-chars {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.special-char-btn {
  min-width: 34px;
  padding: 6px 10px;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--color-surface-alt);
  color: var(--color-primary-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.special-char-btn:hover:not(:disabled) {
  background: var(--color-primary-light);
  box-shadow: none;
  transform: none;
}

/* ---- Number game ---- */

.num-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 28px 10px;
  margin-bottom: 12px;
  background: var(--color-surface-alt);
  border-radius: var(--radius);
}
.num-prompt-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-primary-dark);
  text-transform: capitalize;
}
.num-prompt .speak-btn {
  width: 34px;
  height: 34px;
  font-size: 1.05rem;
  margin-left: 0;
}
.num-prompt.num-wrong {
  animation: cardShake 0.35s ease;
}

/* ---- Flashcard ---- */
.flashcard-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.flashcard-scene {
  width: 100%;
  max-width: 420px;
  height: 260px;
  perspective: 1200px;
}
.flashcard {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard:hover {
  transform: translateY(-2px);
}
.flashcard.flipped {
  transform: rotateY(180deg);
}
.flashcard.flipped:hover {
  transform: rotateY(180deg) translateY(-2px);
}
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}
.flashcard-front {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
}
.flashcard-front .word-de {
  font-size: 2.1rem;
}
.flashcard-back {
  background: #fff;
  border: 1px solid var(--color-border);
  transform: rotateY(180deg);
  gap: 6px;
}
.flashcard-back .phonetic {
  color: var(--color-muted);
  font-style: italic;
}
.flashcard-back .example-de {
  margin-top: 8px;
  font-weight: 600;
}
.flashcard-back .example-tr {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.status-badge {
  position: absolute;
  top: 14px;
  right: 14px;
}

.status-toggle {
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.status-toggle:hover {
  transform: scale(1.06);
  filter: brightness(0.96);
}

@keyframes flipGlow {
  0% { box-shadow: 0 0 0 0 rgba(46, 196, 182, 0); }
  45% { box-shadow: 0 0 0 16px rgba(46, 196, 182, 0.14); }
  100% { box-shadow: 0 0 0 0 rgba(46, 196, 182, 0); }
}
.flashcard-scene.flipping {
  border-radius: var(--radius-lg);
  animation: flipGlow 0.6s ease;
}

.answer-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.answer-buttons button {
  min-width: 130px;
}

.nav-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
}
.nav-buttons button {
  min-width: 100px;
}

.card-progress {
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: 40px 20px;
  animation: fadeIn 0.4s ease both;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.help-text {
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* ---- Library / book shelf ---- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  animation: fadeInUp 0.35s ease both;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.book-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.book-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
}

.book-subtitle {
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-top: 2px;
}

.book-progress {
  margin-top: 4px;
}

.btn-read {
  display: inline-block;
  align-self: flex-start;
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 7px 16px;
  border-radius: 999px;
  text-decoration: none;
  margin-top: 4px;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.btn-read:hover {
  background: var(--color-primary-dark);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(46, 196, 182, 0.3);
}

@media (max-width: 900px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--color-border);
  }
  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }
  .sidebar-nav {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
  }
  .nav-item {
    flex-direction: column;
    gap: 2px;
    font-size: 0.68rem;
    padding: 6px 10px;
  }
  .nav-item:hover {
    transform: none;
  }
  .app-header {
    padding: 16px 18px;
  }
  .container {
    padding: 4px 18px 90px;
  }
}

@media (max-width: 640px) {
  .word-table thead {
    display: none;
  }
  .word-table tr {
    display: block;
    border-bottom: 1px solid var(--color-border);
    padding: 10px 0;
  }
  .word-table td {
    display: block;
    border: none;
    padding: 2px 0;
  }
  .topic-bar-row {
    grid-template-columns: 100px 1fr 44px;
  }
  .topic-group-title {
    flex-wrap: wrap;
  }
  .topic-group-title a {
    flex: 1 0 100%;
    margin-top: 2px;
    font-size: 0.85rem;
  }
  .match-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .game-tabs {
    flex-wrap: wrap;
  }
  .toolbar input[type="text"] {
    width: 100%;
  }
}
