:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #222;
  --bg-elevated: #2a2a2a;
  
  --text-primary: #f0f0f0;
  --text-secondary: #aaa;
  --text-muted: #666;
  
  --accent: #4a9eff;
  --accent-hover: #6ab0ff;
  --accent-subtle: rgba(74, 158, 255, 0.15);
  
  --success: #4ade80;
  --error: #f87171;
  
  --border: #333;
  --border-hover: #444;
  
  --radius: 8px;
}

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

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 600;
}

.logo-icon { font-size: 1.5rem; }

#auth-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

#user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

#user-info.hidden { display: none; }

#user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

#user-name {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: white;
  color: black;
}
.btn-primary:hover {
  background: #eee;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-card);
  border-color: var(--border-hover);
}

.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-accent:hover {
  background: var(--accent-hover);
}
.btn-accent:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}
.btn-ghost:hover {
  color: var(--text-primary);
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-small:hover {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--text-secondary);
  background: var(--bg-elevated);
}

.tab.active {
  color: var(--accent);
  background: var(--accent-subtle);
}

/* Main Layout */
main {
  height: calc(100vh - 110px);
}

.tab-content {
  display: none;
  height: 100%;
}
.tab-content.active {
  display: block;
}

/* Split Layout - Two Columns */
.split-layout {
  display: flex;
  height: 100%;
}

.lookup-panel {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.card-panel {
  width: 400px;
  min-width: 350px;
  padding: 24px;
  background: var(--bg-secondary);
  overflow-y: auto;
}

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

.panel-header-centered {
  justify-content: center;
}

.panel-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.panel-header-centered h2 {
  font-size: 1.35rem;
  color: #e0e0e0;
  text-align: center;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, rgba(139, 92, 246, 0.1) 100%);
  padding: 14px 24px;
  border-radius: var(--radius);
  border: 1px solid rgba(168, 85, 247, 0.3);
  text-shadow: 0 0 20px rgba(168, 85, 247, 0.4);
}

/* Search */
.search-container {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

#word-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid #a855f7;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1rem;
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.4), 0 0 30px rgba(168, 85, 247, 0.2);
  animation: purple-glow 2s ease-in-out infinite alternate;
}

@keyframes purple-glow {
  from {
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.3), 0 0 20px rgba(168, 85, 247, 0.15);
  }
  to {
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5), 0 0 40px rgba(168, 85, 247, 0.25);
  }
}

#word-input:focus {
  outline: none;
  border-color: #c084fc;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.6), 0 0 40px rgba(168, 85, 247, 0.3);
}

#word-input::placeholder {
  color: var(--text-muted);
}

/* Results */
.hidden { display: none !important; }

.result-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.result-header h3 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.phonetic {
  color: var(--text-muted);
  font-family: monospace;
}

/* Result Groups */
.result-group {
  margin-bottom: 24px;
}

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

.group-actions {
  display: flex;
  gap: 6px;
}

.search-more-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.search-more-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.no-results {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.group-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

/* Definition Items */
.definition-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.definition-item:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.definition-item.added {
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.1);
}

.definition-item .part-of-speech {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.definition-item .def-text {
  flex: 1;
  color: var(--text-secondary);
}

.definition-item .add-icon {
  color: var(--text-muted);
  font-size: 1.25rem;
  opacity: 0;
}

.definition-item:hover .add-icon {
  opacity: 1;
  color: var(--accent);
}

.definition-item.added .add-icon {
  opacity: 1;
  color: var(--success);
}

/* Word Chips */
.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.word-chip {
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.word-chip:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
}

.word-chip.added {
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.1);
  color: var(--success);
}

/* Error Box */
.error-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  color: var(--error);
}

/* Vocab Card */
.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-field {
  margin-bottom: 16px;
}
.card-field:last-child {
  margin-bottom: 0;
}

.card-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-field input,
.card-field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
}

.card-field input:focus,
.card-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Sentence field with generate button */
.sentence-field {
  position: relative;
}

.sentence-field textarea {
  width: 100%;
  padding: 10px 12px;
  padding-right: 90px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
}

.generate-sentence-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 4px 10px;
  font-size: 0.75rem;
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.generate-sentence-btn:hover {
  background: var(--accent);
  color: white;
}

/* Card Chips */
.card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 40px;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: flex-start;
  align-content: flex-start;
}

.card-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-size: 0.85rem;
}

.card-chip .remove-chip {
  cursor: pointer;
  opacity: 0.7;
  font-size: 1rem;
  line-height: 1;
}
.card-chip .remove-chip:hover {
  opacity: 1;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.chip-input {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
}

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

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

/* Card Actions */
.card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

/* Placeholder */
.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
}

.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.placeholder-content h2 {
  font-size: 1.5rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Saved Cards Tab */
.saved-cards-container {
  padding: 24px;
  height: 100%;
  overflow-y: auto;
}

.saved-cards-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.saved-cards-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

#cards-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.print-button-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.btn-print {
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 600;
}

.sign-in-reminder {
  margin-top: 24px;
  padding: 16px 20px;
  background: rgba(232, 162, 67, 0.1);
  border: 1px solid rgba(232, 162, 67, 0.3);
  border-radius: var(--radius);
  text-align: center;
}

.sign-in-reminder p {
  color: #e8a243;
  font-size: 1rem;
  font-weight: 500;
  margin: 0;
}

.sign-in-reminder .access-note {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.sign-in-reminder .access-note a {
  color: var(--accent);
  text-decoration: underline;
}

.sign-in-reminder .access-note a:hover {
  color: var(--accent-hover);
}

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

/* Individual Saved Card */
.saved-card-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.15s;
}

.saved-card-box:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.saved-card-word {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.saved-card-section {
  margin-bottom: 12px;
}

.saved-card-section:last-child {
  margin-bottom: 0;
}

.saved-card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.saved-card-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.saved-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.saved-card-chip {
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.saved-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.saved-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.saved-card-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.saved-card-delete:hover {
  background: rgba(248, 113, 113, 0.1);
  color: var(--error);
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  margin-bottom: 4px;
}

.empty-state .empty-hint {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* ============ REVIEW TAB ============ */
.review-container {
  padding: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

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

.review-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.review-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

#review-progress {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.review-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
}

.review-empty .empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Flashcard Container */
.review-card-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

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

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

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

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  padding: 32px;
  overflow-y: auto;
}

.flashcard-front {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border: 1px solid var(--border);
  align-items: center;
  justify-content: center;
  text-align: center;
}

.flashcard-back {
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  transform: rotateY(180deg);
}

.flashcard-word {
  font-size: 2.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.flashcard-back .flashcard-word {
  font-size: 1.5rem;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.flashcard-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 16px;
}

.flashcard-content {
  flex: 1;
  overflow-y: auto;
}

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

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

.flashcard-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.flashcard-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.flashcard-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.flashcard-chip {
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Navigation */
.review-nav {
  display: flex;
  gap: 16px;
}

.review-nav .btn {
  min-width: 120px;
  justify-content: center;
}

.review-nav .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============ HOW TO USE TAB ============ */
.how-to-container {
  padding: 32px;
  max-width: 700px;
  margin: 0 auto;
  height: 100%;
  overflow-y: auto;
}

.how-to-container h2 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.how-to-section {
  margin-bottom: 28px;
}

.how-to-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.how-to-section p {
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.how-to-section ul {
  list-style: none;
  padding: 0;
}

.how-to-section li {
  padding: 8px 0;
  padding-left: 20px;
  position: relative;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.how-to-section li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.how-to-section li strong {
  color: var(--text-primary);
}

/* Hide noise overlay - was causing issues */
.noise { display: none; }

/* Responsive */
@media (max-width: 900px) {
  .split-layout {
    flex-direction: column;
  }
  
  .lookup-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }
  
  .card-panel {
    width: 100%;
    min-width: unset;
  }
}

@media (max-width: 600px) {
  header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }
  
  .tabs {
    padding: 8px 16px;
    overflow-x: auto;
  }
  
  .lookup-panel,
  .card-panel {
    padding: 16px;
  }
}
