:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #8b5cf6;
  --success: #10b981;
  --error: #ef4444;
  --warn: #f59e0b;
  --card-bg: rgba(255, 255, 255, 0.88);
  --text-main: #1f2937;
  --text-sec: #6b7280;
  --radius: 14px;
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 0 16px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.site-topbar {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  color: rgba(255, 255, 255, 0.95);
}

.site-topbar a {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.site-topbar a:hover {
  opacity: 0.9;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.topbar-note {
  font-size: 12px;
  opacity: 0.85;
}

.app {
  background: var(--card-bg);
  backdrop-filter: blur(24px);
  border-radius: 20px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
  width: 100%;
  max-width: 960px;
  padding: 36px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  animation: fadeUp 0.6s ease-out;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  font-size: 2rem;
  color: #111827;
  letter-spacing: -0.02em;
}

.header p {
  color: var(--text-sec);
  margin-top: 8px;
  font-size: 0.95rem;
}

.term-section {
  background: linear-gradient(135deg, #eef2ff, #f5f3ff);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  border: 1px solid #e0e7ff;
}

.term-section summary {
  font-weight: 600;
  font-size: 0.95rem;
  color: #4338ca;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.term-section summary::marker {
  content: "";
}

.term-section summary::before {
  content: "🛡️";
}

.term-section[open] .term-body {
  margin-top: 12px;
}

.term-hint {
  font-size: 0.82rem;
  color: var(--text-sec);
  margin-bottom: 10px;
}

.term-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.term-input-row input {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #c7d2fe;
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
}

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

.term-input-row button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: background 0.2s;
}

.term-input-row button:hover {
  background: var(--primary-hover);
}

.term-input-row button.secondary {
  background: var(--accent);
}

.term-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.term-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.82rem;
  background: #ddd6fe;
  color: #5b21b6;
  font-weight: 500;
  animation: popIn 0.25s ease-out;
}

@keyframes popIn {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.term-tag .remove {
  cursor: pointer;
  font-size: 0.75rem;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(91, 33, 182, 0.15);
  transition: background 0.2s;
}

.term-tag .remove:hover {
  background: rgba(91, 33, 182, 0.3);
}

.grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: stretch;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-weight: 600;
  font-size: 0.9rem;
  color: #374151;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

textarea {
  width: 100%;
  flex-grow: 1;
  min-height: 260px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: rgba(255, 255, 255, 0.9);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-main);
  resize: none;
  transition: all 0.25s;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.03);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
}

.ctrl-label {
  font-size: 0.8rem;
  color: var(--text-sec);
  font-weight: 600;
}

select {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: white;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  width: 140px;
  transition: all 0.2s;
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-row label {
  font-size: 0.8rem;
  color: var(--text-sec);
  font-weight: 500;
  cursor: pointer;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
}

.toggle .slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s;
}

.toggle input:checked + .slider {
  background: var(--primary);
}

.toggle input:checked + .slider::before {
  transform: translateX(16px);
}

.stats-panel {
  display: none;
  margin-top: 20px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #eef2ff, #f0fdf4);
  border-radius: var(--radius);
  border: 1px solid #c7d2fe;
  animation: fadeUp 0.4s ease-out;
}

.stats-title {
  font-weight: 700;
  font-size: 1rem;
  color: #1e1b4b;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: 1px solid #e5e7eb;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-sec);
  margin-top: 6px;
  font-weight: 500;
}

.stat-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 6px;
  background: #e5e7eb;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.8s ease-out;
}

.stat-good .stat-value {
  color: #059669;
}

.stat-good .stat-bar-fill {
  background: linear-gradient(90deg, #34d399, #059669);
}

.stat-mid .stat-value {
  color: #d97706;
}

.stat-mid .stat-bar-fill {
  background: linear-gradient(90deg, #fcd34d, #d97706);
}

.stat-bad .stat-value {
  color: #dc2626;
}

.stat-bad .stat-bar-fill {
  background: linear-gradient(90deg, #fca5a5, #dc2626);
}

.stats-tip {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--text-sec);
  line-height: 1.5;
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.06);
  border-radius: 8px;
}

.action-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 13px 22px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
}

.action-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
}

.action-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

.status {
  font-size: 0.82rem;
  color: var(--text-sec);
  text-align: center;
  min-height: 18px;
  font-weight: 500;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(99, 102, 241, 0.1);
}

.result-display {
  display: none;
  min-height: 260px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.7;
  overflow-y: auto;
  max-height: 400px;
}

.result-display .term-hl {
  background: linear-gradient(135deg, #ddd6fe, #c4b5fd);
  color: #5b21b6;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 500;
}

.footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.82rem;
  color: var(--text-sec);
  line-height: 1.6;
  text-align: center;
}

.footer a {
  color: inherit;
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

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

  .controls {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 16px 0;
  }

  select,
  .action-btn {
    flex: 1;
    width: auto;
  }
}
