@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:wght@400;500;600;700&family=Noto+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #1a1a1a;
  --bg-card: #242424;
  --bg-card-hover: #2d2d2d;
  --accent-primary: #f5c518;
  --accent-secondary: #ff6b35;
  --accent-success: #4ade80;
  --accent-danger: #f87171;
  --text-primary: #fafafa;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  --border-color: #333;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* Layout */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 100px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.header h1 {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--accent-primary);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-radius: 24px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.user-badge:hover {
  background: var(--bg-card);
}

.user-badge::before {
  content: '👤';
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Section headers */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: #ffd43b;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-success {
  background: var(--accent-success);
  color: var(--bg-primary);
}

.btn-danger {
  background: var(--accent-danger);
  color: var(--bg-primary);
}

.btn-icon {
  padding: 10px;
  min-width: 44px;
  justify-content: center;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-large {
  padding: 16px 32px;
  font-size: 17px;
}

/* Deck Grid */
.deck-grid {
  display: grid;
  gap: 12px;
}

.deck-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.deck-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.deck-card-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  margin-bottom: 4px;
}

.deck-card-chapter {
  font-size: 14px;
  color: var(--accent-secondary);
  margin-bottom: 12px;
}

.deck-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

.deck-card-count {
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: 12px;
}

/* Deck Detail */
.deck-header {
  margin-bottom: 24px;
}

.deck-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 32px;
  font-weight: 400;
  margin-bottom: 4px;
}

.deck-chapter {
  font-size: 16px;
  color: var(--accent-secondary);
  margin-bottom: 8px;
}

.deck-description {
  color: var(--text-secondary);
  font-size: 15px;
}

.deck-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* Cards List */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 32px;
}

.card-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-primary);
}

.card-item-content {
  flex: 1;
}

.card-item-word {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 2px;
  word-break: break-word;
  overflow-wrap: break-word;
}

.card-item-translation {
  font-size: 14px;
  color: var(--text-secondary);
}

.card-item-actions {
  display: flex;
  gap: 4px;
}

.card-item-actions .btn {
  padding: 8px;
  font-size: 14px;
}

/* Card Stack */
.card-stack {
  position: relative;
  cursor: pointer;
  margin-bottom: 32px;
  perspective: 1000px;
}

.card-stack.empty {
  cursor: default;
}

.stacked-cards {
  position: relative;
  height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stack-card {
  position: absolute;
  width: 90%;
  max-width: 320px;
  height: 80px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-primary);
  padding: 16px;
  transition: all 0.3s ease;
  transform-origin: center bottom;
}

.stack-card:nth-child(1) {
  z-index: 3;
  transform: translateY(0) scale(1);
}

.stack-card:nth-child(2) {
  z-index: 2;
  transform: translateY(-8px) scale(0.95);
  opacity: 0.7;
}

.stack-card:nth-child(3) {
  z-index: 1;
  transform: translateY(-16px) scale(0.9);
  opacity: 0.4;
}

.card-stack:hover .stack-card:nth-child(1) {
  transform: translateY(4px) scale(1);
}

.card-stack:hover .stack-card:nth-child(2) {
  transform: translateY(-12px) scale(0.95);
}

.card-stack:hover .stack-card:nth-child(3) {
  transform: translateY(-24px) scale(0.9);
}

.stack-card-word {
  font-size: 16px;
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: break-word;
}

.stack-card-translation {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

.stack-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

.stack-empty {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Modal Large */
.modal-large {
  max-width: 600px;
  max-height: 80vh;
}

.modal-large .modal-body {
  max-height: 60vh;
  overflow-y: auto;
}

/* Search input in modal */
.modal-search {
  position: sticky;
  top: -20px;
  background: var(--bg-card);
  margin: -20px -20px 16px -20px;
  padding: 20px 20px 16px 20px;
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
}

.modal-search .form-input {
  padding: 12px 16px;
  padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23737373'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
}

.no-results {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Card Preview Modal */
.card-preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 300;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.card-preview-overlay.active {
  opacity: 1;
  visibility: visible;
}

.card-preview {
  display: flex;
  gap: 16px;
  max-width: 800px;
  width: 100%;
}

.card-preview-side {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 200px;
  max-height: 70vh;
  overflow-y: auto;
}

.card-preview-side.front {
  border: 2px solid var(--accent-primary);
}

.card-preview-side.back {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: var(--bg-primary);
}

.card-preview-word {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 28px;
  text-align: center;
  margin-bottom: 8px;
  word-break: break-word;
  overflow-wrap: break-word;
}

.card-preview-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
  margin-bottom: 4px;
  margin-top: 16px;
}

.card-preview-label:first-child {
  margin-top: 0;
}

.card-preview-content {
  font-size: 15px;
}

.card-preview-list {
  margin: 0;
  padding-left: 20px;
}

.card-preview-list li {
  margin-bottom: 4px;
}

.card-preview-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--bg-card);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .card-preview {
    flex-direction: column;
  }
  
  .card-preview-side {
    max-height: 40vh;
  }
}

/* Peer Activity */
.peer-section {
  margin-bottom: 32px;
}

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

.peer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
}

.peer-name {
  font-weight: 500;
}

.peer-score {
  display: flex;
  align-items: center;
  gap: 8px;
}

.peer-score-value {
  font-weight: 600;
  color: var(--accent-success);
}

.peer-time {
  font-size: 13px;
  color: var(--text-muted);
}

.peer-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Study Mode */
.study-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 100;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.study-view.active {
  display: flex;
}

/* Prevent body scroll when study view or modal is active */
body.study-active,
body.modal-open {
  overflow: hidden;
}

.study-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.study-progress {
  flex: 1;
  margin: 0 16px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent-primary);
  transition: width 0.3s;
}

.progress-text {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

.study-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  overflow: hidden;
}

/* Flashcard */
.flashcard {
  width: 100%;
  max-width: 400px;
  height: 100%;
  max-height: 400px;
  min-height: 280px;
  perspective: 1000px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 280px;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

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

/* Disable animation when switching cards to prevent cheating */
.flashcard.no-transition .flashcard-inner {
  transition: none;
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  text-align: center;
  overflow-y: auto;
}

.flashcard-front {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 2px solid var(--accent-primary);
}

.flashcard-back {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  transform: rotateY(180deg);
  color: var(--bg-primary);
}

/* Edit buttons on flashcard */
.edit-word-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 10;
}

.edit-word-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.edit-full-btn {
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--bg-primary);
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.edit-full-btn:hover {
  background: rgba(0, 0, 0, 0.4);
}

.flashcard-word {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 36px;
  font-weight: 400;
  margin-bottom: 8px;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  padding: 0 8px;
}

.flashcard-hint {
  font-size: 14px;
  color: var(--text-muted);
}

.flashcard-translation {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 16px;
}

.flashcard-translation-item {
  margin-bottom: 4px;
}

.flashcard-translation-item:last-child {
  margin-bottom: 0;
}

.flashcard-details {
  width: 100%;
  margin-top: 16px;
}

.flashcard-detail-section {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 8px;
  text-align: left;
}

.flashcard-detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
  margin-bottom: 4px;
}

.flashcard-detail-content {
  font-size: 15px;
}

.flashcard-detail-list {
  font-size: 15px;
  margin: 0;
  padding-left: 20px;
}

.flashcard-detail-list li {
  margin-bottom: 4px;
}

.flashcard-detail-list li:last-child {
  margin-bottom: 0;
}

.lang-tag {
  font-size: 12px;
  opacity: 0.7;
  font-weight: normal;
}

/* Answer buttons */
.study-actions {
  padding: 16px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.study-actions-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 500px;
}

.answer-btn {
  flex: 1;
  padding: 16px 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.btn-success-alt {
  background: #22c55e;
  color: var(--bg-primary);
}

.btn-success-alt:hover {
  background: #16a34a;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

/* Card modal needs higher z-index to appear above cards list modal */
#cardModal {
  z-index: 250;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  min-height: 100px;
  resize: vertical;
}

/* Localized content editor */
.localized-group {
  margin-bottom: 16px;
}

.localized-group > .form-label {
  margin-bottom: 8px;
}

.localized-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.localized-group > .btn-add-item {
  margin-top: 4px;
}

.localized-item {
  display: flex;
  gap: 8px;
}

.localized-item input:first-child {
  width: 70px;
}

.localized-item input:nth-child(2) {
  flex: 1;
}

.btn-add-item {
  padding: 8px 12px;
  font-size: 13px;
}

/* Session Complete */
.complete-view {
  text-align: center;
  padding: 40px 24px;
}

.complete-emoji {
  font-size: 72px;
  margin-bottom: 16px;
}

.complete-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 32px;
  margin-bottom: 8px;
}

.complete-score {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 8px;
}

.complete-detail {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
  margin: 0 auto;
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  margin-bottom: 16px;
}

.back-btn:hover {
  color: var(--text-primary);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-emoji {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 16px;
  margin-bottom: 24px;
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-card);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 300;
  opacity: 0;
  transition: all 0.3s;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--accent-danger);
  color: white;
}

/* Responsive */
@media (min-width: 640px) {
  .container {
    padding: 24px;
  }

  .header h1 {
    font-size: 32px;
  }

  .deck-card {
    padding: 24px;
  }

  .flashcard {
    min-height: 320px;
  }

  .flashcard-front,
  .flashcard-back {
    min-height: 320px;
  }

  .flashcard-word {
    font-size: 42px;
  }
}

/* Usage Category Toggles */
.usage-toggles {
  display: flex;
  gap: 12px;
}

.usage-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-secondary);
}

.usage-toggle:hover {
  background: var(--bg-card);
  border-color: var(--text-muted);
}

.usage-toggle.active {
  border-color: var(--accent-primary);
  background: var(--bg-card);
  color: var(--text-primary);
}

.usage-toggle .toggle-icon {
  font-size: 18px;
}

.usage-toggle .toggle-label {
  font-weight: 500;
}

/* Usage badges on cards */
.usage-badges {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.usage-badge {
  font-size: 12px;
  opacity: 0.7;
}

/* Linguistics-safe font for content areas with special characters */
.form-input,
.flashcard-word,
.flashcard-translation,
.flashcard-translation-item,
.flashcard-detail-list,
.card-item-word,
.card-item-translation,
.stack-card-word,
.stack-card-translation {
  font-family: 'Noto Sans', 'DejaVu Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}
