:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --ink: #1e1e1e;
  --muted: #6b6b6b;
  --accent: #2f5d50;
  --accent-light: #e7f0ec;
  --border: #e3e1dc;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 28px 20px 20px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.tagline {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.search-wrap {
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

#searchInput {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--bg);
}

#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--card);
}

.result-count {
  display: block;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- Word list ---------- */
main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

.word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.word-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.word-list a {
  display: block;
  padding: 10px 14px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word-list a:hover,
.word-list a:focus {
  background: var(--accent-light);
  color: var(--accent);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

.see-more-btn {
  display: block;
  margin: 20px auto 0;
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.see-more-btn:hover {
  background: var(--accent);
  color: #fff;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 18px 12px 30px;
}

/* ---------- Word page ---------- */
.word-topbar {
  text-align: left;
  padding: 16px 20px;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.back-link:hover { text-decoration: underline; }

.back-link-bottom {
  display: inline-block;
  margin-top: 24px;
}

.word-main {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
  flex: 1;
}

.loading-state {
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
}

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

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

.word-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
}

.word-title {
  margin: 0 0 4px;
  font-size: 2.1rem;
  text-transform: capitalize;
  color: var(--ink);
}

.phonetic {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 18px;
}

.variants-box {
  background: var(--accent-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}

.variants-box h3 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.variants-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.9rem;
}

.variant-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}

.variant-chip b { color: var(--accent); }

.meaning-block {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.meaning-block:last-child {
  border-bottom: none;
}

.pos-tag {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.definition-item {
  margin: 0 0 10px;
  padding-left: 0;
}

.definition-item .def-text {
  margin: 0 0 4px;
  line-height: 1.5;
}

.definition-item .example {
  margin: 0 0 2px;
  color: var(--muted);
  font-style: italic;
  font-size: 0.92rem;
}

.synonyms {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}

.ai-section {
  margin-top: 10px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
}

.ai-section h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--accent);
}

.ai-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.ai-btn:hover { opacity: 0.88; }
.ai-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #9a9a9a; }

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fdf3e0;
  border: 1px solid #f0d9a8;
  border-radius: 999px;
  padding: 8px 14px;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: #7a5b1e;
  width: fit-content;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e0a020;
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.server-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.server-status.ready {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.server-status.ready .status-dot {
  background: var(--accent);
  animation: none;
}

.ai-example-text {
  background: var(--accent-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-style: italic;
  line-height: 1.5;
}

.not-found-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .topbar h1 { font-size: 1.5rem; }
  .word-list { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .word-card { padding: 20px 16px; }
  .word-title { font-size: 1.7rem; }
}
