/* ============ CSS Custom Properties ============ */
:root {
  --bg: #f0f2f5;
  --panel-bg: #ffffff;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e0e0e0;
  --input-bg: #ffffff;
  --input-border: #e0e0e0;
  --hover-bg: #f0f7ff;
  --selected-bg: #e8f0fe;
  --error-bg: #fdf2f2;
  --error-border: #f5c6cb;
  --error-text: #dc3545;
  --warning-bg: #fff8e1;
  --warning-border: #ffd54f;
  --warning-text: #b07b00;
  --success: #28a745;
  --primary: #4a90d9;
  --primary-hover: #3a7bc8;
  --gradient: linear-gradient(135deg, #4a90d9 0%, #6366f1 100%);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.1);
}

body.dark {
  --bg: #0d0d1a;
  --panel-bg: #1a1a2e;
  --text: #e0e0e0;
  --text-secondary: #aaaaaa;
  --text-muted: #777777;
  --border: #2a2a3e;
  --input-bg: #1e1e3a;
  --input-border: #2a2a3e;
  --hover-bg: #1e2a3e;
  --selected-bg: #1e2a4e;
  --error-bg: #2a1a1a;
  --error-border: #5a2a2a;
  --error-text: #ff6b6b;
  --warning-bg: #2a2516;
  --warning-border: #5a4f1e;
  --warning-text: #f5d76e;
  --success: #4caf50;
  --primary: #5a9ee6;
  --primary-hover: #4a8ed6;
  --gradient: linear-gradient(135deg, #3a6db8 0%, #4a4fc9 100%);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ============ Reset & Base ============ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

/* ============ Header ============ */
.top-bar {
  background: var(--gradient);
  padding: 16px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #ffffff;
}

.top-bar h1 {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
}

.theme-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============ Onboarding Modal ============ */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.25s ease;
  padding: 20px;
}

body.dark .modal-backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.modal {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 36px 32px 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  font-size: 44px;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.modal-steps {
  list-style: none;
  text-align: left;
  margin: 0 0 28px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

.modal-step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.modal-btn {
  width: 100%;
  padding: 12px;
  background: var(--gradient);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.modal-btn:hover {
  opacity: 0.92;
}

.modal-btn:active {
  transform: scale(0.98);
}

/* ============ Split Layout ============ */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 40px;
}

.panel {
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
  transition: background-color 0.3s, box-shadow 0.3s;
}

.panel h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
}

/* ============ Form ============ */
#process-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============ URL Row Inputs ============ */
#url-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.url-row-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: rowIn 0.15s ease;
}

.url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.url-error-msg {
  font-size: 12px;
  color: var(--error-text);
  padding: 0 4px;
}

/* Phase 2.1: HSK 1/2 quality warning. Subtle yellow callout, only shows
   when one of those levels is selected. */
.low-level-warning {
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.45;
  background: var(--warn-bg, rgba(234, 179, 8, 0.10));
  color: var(--warn-text, #92400e);
  border: 1px solid var(--warn-border, rgba(234, 179, 8, 0.35));
  border-radius: 6px;
}
.low-level-warning strong {
  font-weight: 600;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.url-row input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1.5px solid var(--input-border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.url-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.url-row input::placeholder {
  color: var(--text-muted);
}

.url-row input.has-value {
  border-color: var(--success);
}

.url-row input.invalid-url {
  border-color: var(--error-text);
  background: var(--error-bg);
}

.url-row input.invalid-url:focus {
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15);
}

.url-row-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.url-row-remove:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

.url-row-remove.invisible {
  visibility: hidden;
}

.add-url-btn {
  background: none;
  border: none;
  padding: 6px 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  align-self: flex-start;
  transition: opacity 0.2s;
}

.add-url-btn:hover {
  opacity: 0.7;
}

.duplicate-msg {
  color: var(--error-text);
  font-size: 12px;
  margin-top: 4px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============ HSK Buttons (Radio) ============ */
.hsk-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hsk-btn {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 14px 16px;
  border: 1.5px solid var(--input-border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  background: var(--input-bg);
  transition: all 0.2s;
  user-select: none;
}

.hsk-btn:hover {
  border-color: var(--primary);
}

.hsk-btn:has(input:checked) {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.hsk-btn:has(input:checked) .hsk-btn-desc {
  color: rgba(255, 255, 255, 0.85);
}

.hsk-btn input[type="radio"] {
  display: none;
}

.hsk-btn-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hsk-btn-title {
  font-size: 14px;
  font-weight: 600;
}

.hsk-btn-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  transition: color 0.2s;
}

/* ============ Mode Toggle ============ */
.mode-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--input-border);
  border-radius: 10px;
  overflow: hidden;
}

.mode-btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: var(--input-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn:not(:last-child) {
  border-right: 1.5px solid var(--input-border);
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  background: var(--primary);
  color: #ffffff;
}

/* ============ Buttons ============ */
#turnstile-mount {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

#turnstile-mount.hidden {
  display: none;
}

#submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--gradient);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

#submit-btn:hover {
  opacity: 0.9;
}

#submit-btn:active {
  transform: scale(0.98);
}

#submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.submit-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.btn-secondary {
  width: 100%;
  padding: 12px;
  background: var(--input-bg);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 12px;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--hover-bg);
}

.result-btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--success);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  margin-top: 16px;
  transition: opacity 0.2s;
}

.result-btn:hover {
  opacity: 0.9;
}

/* ============ Error Message ============ */
.error-msg {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 8px;
  color: var(--error-text);
  font-size: 14px;
}

/* ============ Right Panel: Empty State ============ */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 0;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-text {
  color: var(--text-muted);
  font-size: 15px;
}

.empty-text.small {
  font-size: 13px;
}

.empty-examples {
  margin-top: 24px;
  width: 100%;
  text-align: left;
}

.empty-examples-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  text-align: center;
}

.example-url {
  display: block;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'SF Mono', Consolas, monospace;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ Queue Banner (when queued behind others) ============ */
.queue-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--warning-text);
}

.queue-banner-icon {
  font-size: 18px;
}

.queue-banner-text {
  font-weight: 500;
}

/* ============ Step List ============ */
.step-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
}

.step-list li {
  padding: 10px 0;
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.step-list li:last-child {
  border-bottom: none;
}

.step-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.icon-pending,
.icon-spinner,
.icon-done {
  display: none;
}

/* Pending state */
.step-list li.pending .icon-pending { display: inline; }
.step-list li.pending { color: var(--text-muted); }

/* Active state — show spinner */
.step-list li.active .icon-spinner {
  display: block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.step-list li.active {
  color: var(--primary);
  font-weight: 600;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Done state */
.step-list li.done .icon-done { display: inline; color: var(--success); font-weight: bold; }
.step-list li.done { color: var(--success); }

.step-name {
  flex: 1;
}

.step-count {
  color: var(--text-muted);
  font-size: 13px;
}

/* ============ Queue Items (multi-job) ============ */
#queue-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.queue-item {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  transition: border-color 0.2s, background-color 0.2s;
}

.queue-item-url {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 12px;
}

.queue-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.queue-item.processing {
  border-color: var(--primary);
  background: var(--hover-bg);
}

.queue-item.complete {
  border-color: var(--success);
}

.queue-item.error {
  border-color: var(--error-text);
}

.queue-item .view-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.queue-item .view-link:hover {
  text-decoration: underline;
}

.queue-item .status-text {
  font-weight: 500;
}

.queue-item .status-text.complete { color: var(--success); }
.queue-item .status-text.processing { color: var(--primary); }
.queue-item .status-text.error { color: var(--error-text); }
.queue-item .status-text.pending { color: var(--text-muted); }

/* ============ History Section ============ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0 16px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--input-bg);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  transition: background-color 0.2s;
}

.history-item:hover {
  background: var(--hover-bg);
}

.history-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  flex: 1;
  margin-right: 12px;
}

.history-item-status {
  color: var(--success);
  font-size: 14px;
  flex-shrink: 0;
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
}

.history-item-url {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-time {
  font-size: 11px;
  color: var(--text-muted);
}

.history-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.history-item a, .history-item-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.history-item a:hover, .history-item-link:hover {
  text-decoration: underline;
}

.history-item-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.history-item-delete:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

/* ============ Utility ============ */
.hidden {
  display: none !important;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .top-bar {
    padding: 14px 20px;
  }

  .top-bar h1 {
    font-size: 17px;
  }

  .modal {
    padding: 28px 24px 24px;
  }

  .modal-title {
    font-size: 19px;
  }

  .split {
    grid-template-columns: 1fr;
    padding: 0 16px;
    margin: 16px auto 24px;
    gap: 16px;
  }

  .panel {
    padding: 24px 20px;
  }

  .hsk-group {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .panel {
    padding: 20px 16px;
  }

  .hsk-btn {
    padding: 12px 14px;
  }

  .mode-btn {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* ============ Tab Navigation (Phase 3.2) ============ */
.tab-nav {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.3s, border-color 0.3s;
}

.tab-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn-label { font-weight: 600; }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  background: var(--selected-bg);
  color: var(--primary);
  border-radius: 11px;
  font-size: 12px;
  font-weight: 600;
}

.tab-btn.active .tab-badge {
  background: var(--primary);
  color: #ffffff;
}

/* ============ Flashcards Tab ============ */
.flashcards-wrap {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 40px;
}

.flashcards-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.flashcards-header h2 { margin-bottom: 4px; }

.flashcards-subtitle {
  color: var(--text-muted);
  font-size: 13px;
}

.flashcards-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-link-danger {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
}

.btn-link-danger:hover { color: var(--error-text); }

.flashcards-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.flashcards-search {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

.flashcards-search:focus { border-color: var(--primary); }

.flashcards-filter {
  padding: 10px 14px;
  font-size: 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

/* ============ Flashcards Card Grid ============ */
/* align-items: start so flipped cards (which grow taller) don't stretch
   neighboring unflipped cards to match. Each card sits at the top of its
   grid cell with its own height. */
.flashcards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
}

/* Outer container — establishes 3D perspective. Has a fixed height (220px)
   in study mode so all cards look uniform. min-height:0 overrides the
   grid-item default of min-height:auto, which would otherwise size the
   card to back-content. overflow:hidden clips the back face's content
   while the card is closed. */
.flashcard {
  perspective: 1000px;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 220px;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
  overflow: hidden;
  transition: height 0.5s ease, border-color 0.15s, box-shadow 0.15s;
}

.flashcard:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.flashcard-inner {
  position: relative;
  width: 100%;
  flex: 1;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.flashcard-inner.flipped { transform: rotateY(180deg); }

/* Faces use absolute positioning so the inner element controls size — long
   meanings on the back face overflow internally and get clipped by the
   parent's overflow:hidden when the card is closed. */
.flashcard-face {
  background: var(--input-bg);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flashcard-back { transform: rotateY(180deg); }

/* "Show all" mode — disable flipping; show only the back face statically.
   Override the study-mode 220px lock so each card sizes to its full content. */
.flashcards-grid.show-all .flashcard {
  cursor: default;
  perspective: none;
  height: auto;
  overflow: visible;
}
.flashcards-grid.show-all .flashcard-inner { transform: none !important; }
.flashcards-grid.show-all .flashcard-front { display: none; }
.flashcards-grid.show-all .flashcard-back {
  position: relative;
  transform: none;
  overflow: visible;
}

/* ============ Card Content ============ */
.flashcard-hanzi {
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}

.flashcard-front .flashcard-hanzi {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 8px;
}

.flashcard-back .flashcard-hanzi {
  font-size: 22px;
  margin-bottom: 8px;
}

.flashcard-pinyin {
  font-size: 16px;
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
  margin-bottom: 10px;
}

.flashcard-meaning {
  font-size: 14px;
  color: var(--text);
  text-align: center;
  flex-grow: 1;
  padding: 4px;
  line-height: 1.5;
  word-wrap: break-word;
}

.flashcard-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.flashcard-saved {
  font-size: 11px;
  color: var(--text-muted);
}

.hsk-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--selected-bg);
  color: var(--primary);
}

.hsk-pill.above {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.flashcard-front-hint {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  margin-top: -4px;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.15s;
}

.flashcard:hover .flashcard-front-hint { opacity: 1; }
.flashcards-grid.show-all .flashcard-front-hint { display: none; }

/* Per-card remove button — top-right corner, only visible on hover.
   z-index keeps it above the rotating .flashcard-inner. */
.btn-card-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  z-index: 2;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s;
}

.flashcard:hover .btn-card-remove { opacity: 1; }

.btn-card-remove:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

.toggle-icon {
  display: inline-block;
  margin-right: 4px;
}

/* Empty state */
.flashcards-empty {
  text-align: center;
  padding: 60px 20px;
}

.flashcards-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.flashcards-empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.flashcards-empty-text {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.5;
}

@media (max-width: 768px) {
  .tab-nav-inner { padding: 0 16px; }
  .flashcards-wrap {
    padding: 0 16px;
    margin: 16px auto;
  }
  .flashcards-header {
    flex-direction: column;
    align-items: stretch;
  }
  .flashcards-actions { justify-content: flex-end; }
  .flashcards-toolbar { flex-direction: column; }
  .flashcards-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
  .flashcard {
    height: 200px;
  }
  .flashcard-hanzi { font-size: 28px; }
}
