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

:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --border: #e8e0d4;
  --text: #2c2416;
  --text-soft: #6b5d4d;
  --accent: #8b6914;
  --accent-light: #c49b2a;
  --accent-bg: #f5ecd8;
  --warm-shadow: rgba(139, 105, 20, 0.08);
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1.2rem;
}

main {
  max-width: 620px;
  width: 100%;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-top: 4rem;
}

h1 {
  font-size: 2.6rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-bottom: 0.8rem;
  color: var(--accent);
}

.tagline {
  color: var(--text-soft);
  font-size: 1.1rem;
  line-height: 1.6;
  max-width: 440px;
  margin: 0 auto;
}

/* Form */
form {
  margin-bottom: 2rem;
  text-align: center;
}

textarea {
  width: 100%;
  padding: 1.2rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 1.08rem;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px var(--warm-shadow);
}

textarea:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 2px 16px var(--warm-shadow);
}

textarea::placeholder {
  color: #b5a68e;
  font-style: italic;
}

button[type="submit"] {
  margin-top: 1rem;
  padding: 0.8rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

button[type="submit"]:hover {
  background: var(--accent-light);
}

button[type="submit"]:active {
  transform: scale(0.98);
}

button[type="submit"]:disabled {
  background: #c4b896;
  cursor: not-allowed;
  transform: none;
}

/* Loading */
#loading {
  text-align: center;
  padding: 3rem 0;
}

.loader {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

#loading p {
  color: var(--text-soft);
  font-style: italic;
  font-size: 0.95rem;
}

/* Best match */
#best-match {
  margin-bottom: 1.5rem;
}

.best-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 2rem 1.8rem;
  box-shadow: 0 4px 20px var(--warm-shadow);
}

.best-connection {
  font-size: 1.2rem;
  font-style: italic;
  color: var(--accent);
  line-height: 1.55;
  margin-bottom: 1.4rem;
}

.best-concept {
  margin-bottom: 1.2rem;
}

.concept-name {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
}

.original-term {
  color: var(--accent);
  font-size: 1.05rem;
  margin-left: 0.35rem;
  font-weight: 400;
}

.tradition {
  display: inline-block;
  font-size: 0.8rem;
  font-family: system-ui, -apple-system, sans-serif;
  padding: 0.2rem 0.6rem;
  background: var(--accent-bg);
  border-radius: 20px;
  color: var(--text-soft);
  margin-left: 0.5rem;
  vertical-align: middle;
}

.explanation {
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 1.2rem;
}

.source-line {
  font-size: 0.88rem;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--text-soft);
  padding-left: 0.8rem;
  border-left: 2px solid var(--border);
  margin-bottom: 0.8rem;
}

.source-link {
  display: inline-block;
  font-size: 0.88rem;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.source-link:hover {
  color: var(--accent-light);
  text-decoration: underline;
}

/* Others */
.toggle-btn {
  display: block;
  margin: 0 auto 1.5rem;
  padding: 0.5rem 1.4rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text-soft);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.toggle-btn:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

.other-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem 1.6rem;
  margin-bottom: 0.8rem;
  box-shadow: 0 2px 8px var(--warm-shadow);
}

.other-connection {
  font-size: 0.98rem;
  font-style: italic;
  color: var(--accent);
  line-height: 1.5;
  margin-bottom: 0.8rem;
}

.other-card .concept-name {
  font-size: 1.1rem;
}

.other-card .original-term {
  font-size: 0.92rem;
}

.other-card .explanation {
  font-size: 0.95rem;
  line-height: 1.65;
  margin-bottom: 0.8rem;
}

.other-card .source-line {
  font-size: 0.82rem;
}

.other-card .source-link {
  font-size: 0.82rem;
}

/* Action buttons (save/share) */
#result-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.action-btn {
  padding: 0.5rem 1.2rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.88rem;
  color: var(--text-soft);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.action-btn:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

.action-btn:disabled {
  color: var(--accent);
  border-color: var(--accent-light);
  cursor: default;
}

.action-btn-subtle {
  border: none;
  font-size: 0.82rem;
  color: #b5a68e;
  margin-top: 0.8rem;
}

.action-btn-subtle:hover {
  color: var(--accent);
}

/* Saved ideas */
#saved-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.saved-title {
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--text-soft);
  margin-bottom: 1.2rem;
}

.saved-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 0.6rem;
  text-align: left;
  transition: border-color 0.2s;
}

.saved-card:hover {
  border-color: var(--accent-light);
}

.saved-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.saved-idea {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text);
  margin-bottom: 0.4rem;
  line-height: 1.5;
}

.delete-saved {
  background: none;
  border: none;
  color: #c5b9a8;
  font-size: 0.85rem;
  font-family: system-ui, -apple-system, sans-serif;
  cursor: pointer;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
}

.delete-saved:hover {
  color: var(--accent);
  background: var(--accent-bg);
}

.saved-connection {
  font-size: 0.88rem;
  font-style: italic;
  color: var(--accent);
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.saved-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-family: system-ui, -apple-system, sans-serif;
}

.concept-name-sm {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.original-term-sm {
  font-size: 0.8rem;
  color: var(--accent);
}

.tradition-sm {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  background: var(--accent-bg);
  border-radius: 20px;
  color: var(--text-soft);
}

.saved-date {
  font-size: 0.75rem;
  color: #b5a68e;
  margin-left: auto;
}

/* Utility */
.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 500px) {
  header { padding-top: 2rem; }
  h1 { font-size: 2rem; }
  .tagline { font-size: 1rem; }
  .best-card { padding: 1.4rem 1.2rem; }
  .best-connection { font-size: 1.05rem; }
}
