/* ===== Vocabulary App - Left/Right Layout ===== */

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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --secondary: #059669;
  --secondary-hover: #047857;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
}

.hidden { display: none !important; }

/* App Container */
.vocab-app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.vocab-header {
  text-align: center;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 12px;
}

.vocab-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.vocab-header p {
  color: var(--gray-500);
  font-size: 0.9rem;
}

.vocab-header span {
  font-size: 0.82rem;
  color: var(--gray-400);
}

.vocab-header span a {
  color: var(--primary);
}

/* Toolbar - Top */
.vocab-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin-bottom: 12px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar-left {
  display: flex;
  gap: 4px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--gray-200);
  background: #fff;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tool-btn svg {
  width: 14px;
  height: 14px;
}

.toolbar-right {
  font-size: 0.82rem;
  color: var(--gray-400);
}

.toolbar-info {
  font-weight: 500;
}

/* Main Layout */
.vocab-main {
  flex: 1;
  display: flex;
  gap: 16px;
  min-height: 0;
}

/* Left Sidebar - Root List */
.root-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - 220px);
}

.sidebar-search {
  padding: 12px;
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--primary);
}

.sidebar-stats {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--gray-400);
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
}

.sidebar-stats b {
  color: var(--gray-600);
}

.root-nav {
  list-style: none;
  overflow-y: auto;
  padding: 4px 0;
}

.root-nav li {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  font-size: 0.88rem;
}

.root-nav li:hover {
  background: var(--gray-50);
}

.root-nav li.active {
  background: var(--primary-light);
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.root-nav .root-text {
  font-weight: 500;
  color: var(--gray-800);
}

.root-nav li.active .root-text {
  color: var(--primary);
}

.root-nav .root-gloss {
  font-size: 0.78rem;
  color: var(--gray-400);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.root-nav .root-count-badge {
  font-size: 0.72rem;
  background: var(--gray-100);
  color: var(--gray-500);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.root-nav li.active .root-count-badge {
  background: var(--primary);
  color: #fff;
}

/* Right Content - Word Detail */
.word-detail {
  flex: 1;
  min-width: 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: calc(100vh - 220px);
}

/* Placeholder */
.detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  color: var(--gray-400);
}

.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.detail-placeholder h3 {
  font-size: 1.1rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.detail-placeholder p {
  font-size: 0.9rem;
}

/* Detail Header */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}

.detail-root-info {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.detail-root-info h2 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.detail-gloss {
  font-size: 1rem;
  color: var(--gray-500);
}

.detail-count {
  font-size: 0.85rem;
  color: var(--gray-400);
  background: var(--gray-50);
  padding: 4px 12px;
  border-radius: 12px;
}

.detail-count span {
  font-weight: 600;
  color: var(--gray-600);
}

/* Word Table */
.word-table {
  padding: 8px 0;
}

.word-row {
  display: flex;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.15s;
}

.word-row:hover {
  background: var(--gray-50);
}

.word-row:last-child {
  border-bottom: none;
}

.word-num {
  width: 32px;
  font-size: 0.78rem;
  color: var(--gray-400);
  flex-shrink: 0;
}

.word-main {
  flex: 1;
  min-width: 0;
}

.word-english {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-audio {
  display: inline-flex;
  gap: 2px;
}

.audio-btn-sm {
  width: 28px;
  height: 26px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--gray-500);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.audio-btn-sm:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.word-breakdown {
  font-size: 0.82rem;
  color: var(--gray-400);
}

.word-breakdown .morpheme {
  color: var(--primary);
  font-weight: 500;
}

.word-meaning-col {
  width: 160px;
  flex-shrink: 0;
  text-align: right;
  font-size: 1rem;
  color: var(--gray-700);
  font-weight: 500;
}

/* ===== Card Modal ===== */
.card-modal,
.test-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-overlay,
.test-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.card-wrapper,
.test-wrapper {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 1;
}

.card-close,
.test-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.card-close:hover,
.test-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* Progress */
.progress-mini {
  text-align: center;
  margin-bottom: 20px;
}

.progress-mini span {
  font-size: 0.82rem;
  color: var(--gray-400);
}

.progress-bar-mini {
  height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill-mini {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

/* Flashcard */
.flashcard {
  position: relative;
  width: 100%;
  height: 220px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 20px;
}

.flashcard .card-front,
.flashcard .card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: transform 0.5s;
}

.flashcard .card-front {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.flashcard .card-back {
  background: #fff;
  border: 2px solid var(--primary);
  transform: rotateY(180deg);
}

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

.flashcard.flipped .card-back {
  transform: rotateY(0deg);
}

.card-word {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.card-audio {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.audio-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  background: rgba(255,255,255,0.15);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.audio-btn:hover {
  background: rgba(255,255,255,0.3);
  border-color: rgba(255,255,255,0.5);
}

.card-hint {
  font-size: 0.8rem;
  opacity: 0.7;
  position: absolute;
  bottom: 16px;
}

.card-meaning {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 12px;
}

.card-decomposition {
  font-size: 0.9rem;
  color: var(--gray-500);
  text-align: center;
}

/* Card Nav */
.card-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.nav-btn {
  padding: 10px 20px;
  border: 1px solid var(--gray-200);
  background: #fff;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.15s;
}

.nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.nav-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.nav-btn.primary:hover {
  background: var(--primary-hover);
}

/* ===== Test Modal ===== */
.test-header-bar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  font-size: 0.9rem;
  color: var(--gray-500);
}

.test-header-bar b {
  color: var(--primary);
}

.test-question {
  text-align: center;
  margin-bottom: 24px;
}

.test-word {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.test-hint {
  font-size: 0.9rem;
  color: var(--gray-400);
}

.test-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.test-option {
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--gray-700);
  text-align: left;
  transition: all 0.15s;
}

.test-option:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.test-option:disabled {
  cursor: default;
}

.test-option.correct {
  border-color: var(--secondary);
  background: #ecfdf5;
  color: var(--secondary);
}

.test-option.wrong {
  border-color: #ef4444;
  background: #fef2f2;
  color: #ef4444;
}

.test-option .opt-label {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  background: var(--gray-100);
  border-radius: 50%;
  margin-right: 10px;
  font-weight: 600;
  font-size: 0.8rem;
}

.test-feedback {
  text-align: center;
}

.feedback-text {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--gray-700);
}

.test-result {
  text-align: center;
  padding: 20px 0;
}

.test-result h3 {
  font-size: 1.3rem;
  margin-bottom: 16px;
  color: var(--gray-800);
}

.result-big {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.result-acc {
  font-size: 1rem;
  color: var(--gray-500);
  margin-bottom: 24px;
}

.result-acc span {
  font-weight: 600;
  color: var(--secondary);
}

/* ===== Footer Sections ===== */
.links-section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-top: 16px;
}

.links-section h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--gray-100);
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.links-grid a {
  font-size: 0.85rem;
  color: var(--gray-600);
  text-decoration: none;
  padding: 6px 10px;
  transition: color 0.15s;
}

.links-grid a:hover {
  color: var(--primary);
}

footer {
  text-align: center;
  padding: 20px;
  margin-top: 16px;
  color: var(--gray-400);
  font-size: 0.82rem;
}

footer a {
  color: var(--gray-500);
  text-decoration: none;
}

footer a:hover {
  color: var(--primary);
}

footer .copyright {
  margin-top: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .toolbar-info {
    display: none;
  }

  .vocab-main {
    flex-direction: column;
  }

  .root-sidebar {
    width: 100%;
    max-height: 220px;
  }

  .word-detail {
    max-height: 500px;
  }

  .word-row {
    padding: 12px 16px;
  }

  .word-meaning-col {
    width: 100px;
    font-size: 0.9rem;
  }

  .test-options {
    grid-template-columns: 1fr;
  }

  .card-wrapper,
  .test-wrapper {
    width: 95%;
    padding: 24px;
  }

  .links-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

@media (max-width: 480px) {
  .vocab-app {
    padding: 8px;
  }

  .detail-header {
    padding: 14px 16px;
  }

  .detail-root-info h2 {
    font-size: 1.4rem;
  }
}
