@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* More premium, elegant gradient */
  background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
  min-height: 100vh;
  padding: 0 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-main);
  line-height: 1.75;
}

.site-topbar {
  width: 100%;
  max-width: 1040px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  color: rgba(31, 41, 55, 0.9);
}

.site-topbar a {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.topbar-note {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.8;
}

.app {
  background: var(--card-bg);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border-radius: 24px;
  box-shadow: 0 32px 64px -12px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
  width: 100%;
  max-width: 1040px;
  padding: 48px;
  animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

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

.header p {
  color: var(--text-sec);
  margin-top: 12px;
  font-size: 1.05rem;
  line-height: 1.6;
}

.term-section {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 28px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.term-section summary {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
  transition: opacity 0.2s;
}

.term-section summary:hover {
  opacity: 0.8;
}

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

.term-section summary::before {
  content: "🛡️";
  font-size: 1.2rem;
}

.term-section[open] .term-body {
  margin-top: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.term-hint {
  font-size: 0.9rem;
  color: var(--text-sec);
  margin-bottom: 16px;
  line-height: 1.6;
}

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

.term-input-row input {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(209, 213, 219, 0.8);
  font-size: 0.95rem;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.9);
  transition: all 0.2s;
}

.term-input-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.term-input-row button {
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.term-input-row button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

.term-input-row button.secondary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
}

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

.term-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  background: rgba(221, 214, 254, 0.6);
  color: #5b21b6;
  font-weight: 600;
  border: 1px solid rgba(139, 92, 246, 0.2);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

.term-tag .remove:hover {
  background: rgba(91, 33, 182, 0.25);
  transform: scale(1.1);
}

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

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

.input-group label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

textarea {
  width: 100%;
  flex-grow: 1;
  min-height: 320px;
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(209, 213, 219, 0.6);
  background: rgba(255, 255, 255, 0.6);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-main);
  resize: none;
  transition: all 0.25s;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.02);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.01), 0 0 0 4px rgba(99, 102, 241, 0.15);
}

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

.ctrl-label {
  font-size: 0.85rem;
  color: var(--text-sec);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

select {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(209, 213, 219, 0.8);
  background: rgba(255, 255, 255, 0.9);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  width: 160px;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

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

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

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

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

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

.toggle .slider {
  position: absolute;
  inset: 0;
  background: rgba(209, 213, 219, 0.8);
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

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

.stats-panel {
  display: none;
  margin-top: 32px;
  padding: 32px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 12px 32px rgba(0,0,0,0.04);
  animation: fadeUp 0.4s ease-out;
}

.stats-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: #1e1b4b;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(229, 231, 235, 0.5);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-sec);
  margin-top: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.stat-bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 1s cubic-bezier(0.16, 1, 0.3, 1);
}

.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: 20px;
  font-size: 0.95rem;
  color: var(--text-sec);
  line-height: 1.6;
  padding: 16px 20px;
  background: rgba(99, 102, 241, 0.08);
  border-radius: 12px;
  border-left: 4px solid var(--primary);
}

.action-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  border: none;
  padding: 16px 32px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 160px;
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.4);
}

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

.spinner {
  display: none;
  width: 22px;
  height: 22px;
  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.9rem;
  color: var(--text-sec);
  text-align: center;
  min-height: 20px;
  font-weight: 600;
}

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

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

.result-display {
  display: none;
  min-height: 320px;
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(209, 213, 219, 0.6);
  background: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  color: var(--text-main);
  line-height: 1.8;
  overflow-y: auto;
  max-height: 500px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.02);
}

.result-display .term-hl {
  background: linear-gradient(135deg, #ddd6fe, #c4b5fd);
  color: #5b21b6;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.6;
  text-align: center;
  width: 100%;
  max-width: 1040px;
}

.footer a {
  color: white;
  font-weight: 600;
}

@media (max-width: 768px) {
  .app {
    padding: 24px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .controls {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 24px 0;
  }
  select,
  .action-btn {
    flex: 1;
    width: auto;
  }
}
