* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { overscroll-behavior: auto; -webkit-overflow-scrolling: touch; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  padding-top: max(15px, env(safe-area-inset-top));
  color: white;
}

/* Header */
.header {
  width: calc(100% - 20px);
  max-width: 500px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.header-stats {
  display: flex;
  gap: 15px;
  font-size: 0.85rem;
  color: #aaa;
}

.header-stat { display: flex; align-items: center; gap: 4px; }
.header-stat .value { color: #4ade80; font-weight: bold; }

.settings-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}
.settings-btn:hover { background: rgba(255,255,255,0.1); }

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
}

.tab {
  padding: 8px 16px;
  border-radius: 8px;
  background: #2d2d44;
  color: #888;
  cursor: pointer;
  border: none;
  font-size: 0.85rem;
}
.tab.active { background: #4ade80; color: #000; }

/* Progress Bar */
.progress-section {
  width: calc(100% - 20px);
  max-width: 500px;
  margin-bottom: 15px;
  margin-left: auto;
  margin-right: auto;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 6px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: #2d2d44;
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #22d3ee);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Card */
.card-container {
  perspective: 1000px;
  width: calc(100% - 20px);
  max-width: 500px;
  min-width: 320px;
  height: 320px;
  margin-bottom: 20px;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
  cursor: pointer;
}

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

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

.card-front {
  background: linear-gradient(145deg, #2d2d44 0%, #1f1f2e 100%);
  border: 2px solid #3d3d5c;
}

.card-back {
  background: linear-gradient(145deg, #1e4d2b 0%, #0d2818 100%);
  border: 2px solid #2d7a3d;
  transform: rotateY(180deg);
}

.card-lang {
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.card-word {
  font-size: 1.7rem;
  font-weight: bold;
  margin-bottom: 12px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  line-height: 1.3;
}

.card-example {
  font-size: 0.85rem;
  color: #aaa;
  font-style: italic;
  line-height: 1.4;
}

.card-example-translation {
  font-size: 0.8rem;
  color: #888;
  line-height: 1.4;
  margin-top: 6px;
}

.card-hint {
  font-size: 0.7rem;
  color: #666;
  margin-top: 12px;
}

.card-mastery {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 15px;
  background: rgba(0,0,0,0.3);
}

.speak-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 50%;
  transition: background 0.2s, transform 0.1s;
  line-height: 1;
  min-width: 0;
  min-height: 0;
  box-shadow: none;
}
.speak-btn:hover { background: rgba(255,255,255,0.1); }
.speak-btn:active { transform: scale(0.9); }
.speak-btn.speaking { animation: pulse-speak 0.6s ease-in-out infinite; }
@keyframes pulse-speak { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.mastery-new { color: #888; }
.mastery-learning { color: #fbbf24; }
.mastery-familiar { color: #60a5fa; }
.mastery-mastered { color: #4ade80; }

/* Buttons */
.controls {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
  justify-content: center;
  width: 100%;
  max-width: 500px;
  padding: 0 10px;
}

button {
  padding: 14px 28px;
  border: none;
  border-radius: 16px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-weight: 600;
}

button:active { opacity: 0.8; }

.btn-know, .btn-dont-know {
  flex: 1;
  padding: 20px 24px;
  font-size: 1.2rem;
  min-height: 65px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.btn-know { background: #4ade80; color: #000; }
.btn-know:active { background: #22c55e; }
.btn-dont-know { background: #f87171; color: #000; }
.btn-dont-know:active { background: #ef4444; }
.btn-secondary { background: #3d3d5c; color: white; padding: 12px 24px; font-size: 0.95rem; border-radius: 12px; }

/* Settings Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: #1f1f2e;
  border-radius: 20px;
  padding: 25px;
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid #3d3d5c;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 1.2rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #888;
  padding: 0;
}

.setting-group { margin-bottom: 20px; }

.setting-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-row select {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #3d3d5c;
  background: #2d2d44;
  color: white;
  font-size: 0.95rem;
}

.setting-row .arrow { color: #4ade80; font-weight: bold; }

.setting-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #2d2d44;
  border-radius: 8px;
}

.setting-checkbox input { accent-color: #4ade80; }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #3d3d5c;
}

.modal-actions button {
  width: 100%;
  padding: 12px;
  font-size: 0.9rem;
}

.btn-danger {
  background: transparent;
  border: 1px solid #f87171;
  color: #f87171;
}

/* Complete Screen */
.complete-screen { text-align: center; padding: 30px; }
.complete-screen h2 { font-size: 1.8rem; margin-bottom: 15px; }
.complete-score { font-size: 3rem; font-weight: bold; color: #4ade80; margin-bottom: 10px; }
.complete-message { color: #888; margin-bottom: 25px; }

.review-list {
  text-align: left;
  background: #2d2d44;
  border-radius: 15px;
  padding: 20px;
  margin-top: 20px;
  max-width: 500px;
  width: calc(100% - 20px);
}

.review-list h3 { margin-bottom: 15px; color: #f87171; }

.review-item {
  padding: 10px 0;
  border-bottom: 1px solid #3d3d5c;
}
.review-item:last-child { border-bottom: none; }

/* Word List */
#wordsTab {
  width: 100%;
  display: flex;
  justify-content: center;
}

#wordsTab.hidden { display: none; }

.word-list {
  max-width: 700px;
  width: calc(100% - 30px);
  max-height: 75vh;
  overflow-y: auto;
}

.word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: #2d2d44;
  border-radius: 10px;
  margin-bottom: 8px;
}

.word-item-text { flex: 1; }
.word-item-pt { font-weight: bold; margin-bottom: 2px; }
.word-item-de, .word-item-en { font-size: 0.75rem; color: #888; }

.word-item-mastery {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(0,0,0,0.3);
}

/* News Reader */
.news-btn {
  background: #2d2d44;
  border: 1px solid #3d3d5c;
  color: #888;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 15px;
}
.news-btn:hover { background: #3d3d5c; color: white; }
.news-btn.active { background: #4ade80; color: #000; border-color: #4ade80; }

.news-container {
  width: calc(100% - 20px);
  max-width: 500px;
  margin-bottom: 20px;
}

.news-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.news-header h3 { font-size: 1rem; color: #ccc; }

.news-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.news-date {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e2e8f0;
  text-align: center;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #4ade80;
  text-transform: capitalize;
}

.news-section { margin-bottom: 16px; }

.news-category {
  font-size: 0.85rem;
  font-weight: 700;
  color: #4ade80;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #3d3d5c;
}

.news-story {
  margin-bottom: 10px;
  padding-left: 4px;
}

.news-headline {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e0e0e0;
  line-height: 1.4;
}

.news-text {
  font-size: 0.82rem;
  color: #aaa;
  line-height: 1.5;
  margin-top: 3px;
  padding-left: 12px;
}

.news-source {
  font-size: 0.7rem;
  color: #666;
  margin-top: 10px;
  text-align: right;
}

.news-empty {
  text-align: center;
  color: #666;
  padding: 20px;
  font-size: 0.85rem;
}

.hidden { display: none !important; }
