/* ─── CSS Custom Properties / Theming ─────────────────────────────────────── */
:root,
[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-card: #ffffff;
  --bg-card-header: #f0f1f3;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e4e8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-header: #22252f;
  --text: #e4e6eb;
  --text-muted: #9ca3af;
  --border: #2d3040;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.5);
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header__title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header__actions { display: flex; gap: 0.5rem; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  background: var(--bg-card-header);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--border); }
.btn--icon { font-size: 1.1rem; padding: 0.4rem 0.6rem; line-height: 1; }
.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover); }

/* ─── Grid ────────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* ─── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card.sortable-ghost {
  opacity: 0.4;
  transform: scale(0.97);
}
.card.sortable-chosen {
  box-shadow: var(--shadow-hover);
}

.card__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
}
.card__header:active { cursor: grabbing; }
.card__icon { font-size: 1rem; }
.card__title {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.card__actions { display: flex; gap: 0.25rem; }
.card__btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
}
.card__btn:hover { background: var(--border); color: var(--text); }

.card__body {
  padding: 0.85rem;
  flex: 1;
  overflow: hidden;
  font-size: 0.9rem;
}
.card__body.collapsed { display: none; }

/* ─── Widget-specific ─────────────────────────────────────────────────────── */
.widget-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
}
.widget-error {
  color: #ef4444;
  font-size: 0.85rem;
  padding: 0.5rem 0;
}
.widget-image {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}
.widget-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}
.widget-word {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.widget-def { margin-bottom: 0.3rem; }
.widget-list { list-style: none; }
.widget-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.widget-list li:last-child { border-bottom: none; }
.widget-list a { font-weight: 500; }

/* ─── Settings Panel ──────────────────────────────────────────────────────── */
.settings { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.settings[hidden] { display: none; }

/* ─── Lightbox ──────────────────────────────────────────────────────────── */
.lightbox { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.85); cursor: pointer; }
.lightbox__img { position: relative; max-width: 90vw; max-height: 90vh; border-radius: 8px; object-fit: contain; }
.settings__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.settings__dialog {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
}
.settings__dialog h2 { margin-bottom: 1rem; }
.settings__dialog h3 { margin: 0.75rem 0 0.5rem; font-size: 0.9rem; }
.settings__dialog hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.settings__field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}
.settings__field span { font-size: 0.8rem; color: var(--text-muted); }
.settings__field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: var(--text);
  font-size: 0.9rem;
}
.widget-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.85rem;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .grid { grid-template-columns: 1fr; padding: 1rem; }
  .header { padding: 0.75rem 1rem; }
}
