/* Base layout */
:root {
  --background: #f5f7fb;
  --surface: #ffffff;
  --accent: #2d6cdf;
  --accent-dark: #1f4ca3;
  --text-primary: #1c2333;
  --text-secondary: #5a6275;
  --border: #dae0ed;
  --success: #2e8540;
  --warning: #b33630;
  --muted: rgba(28, 35, 51, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0d1117;
    --surface: #161b22;
    --accent: #2d6cdf;
    --accent-dark: #6ea4ff;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --border: #30363d;
    --success: #2ea043;
    --warning: #f85149;
    --muted: rgba(240, 246, 252, 0.08);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover,
a:focus {
  text-decoration: underline;
}

.layout {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  z-index: 1000;
  transition: transform 0.3s ease;
}

.topbar--hidden {
  transform: translateY(-100%);
}

.topbar__inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-pill {
  background: var(--muted);
  color: var(--accent-dark);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
}

.topbar__brand-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--text-primary);
}

.brand:hover {
  text-decoration: none;
}

.topbar__toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.topbar__toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
}

.nav {
  display: flex;
  gap: 1rem;
}

.nav a {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav a:hover,
.nav a:focus {
  background: rgba(45, 108, 223, 0.16);
  color: var(--accent-dark);
}

.flash-list {
  list-style: none;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  background: rgba(45, 108, 223, 0.1);
  border: 1px solid rgba(45, 108, 223, 0.15);
}

.flash-list li {
  margin: 0.25rem 0;
}

h1,
h2,
h3 {
  font-weight: 600;
  color: var(--text-primary);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  .card {
    box-shadow: 0 8px 24px rgba(2, 6, 23, 0.5);
  }
}

.card--narrow {
  max-width: 520px;
  margin: 2rem auto;
}

.auth-card h1 {
  margin-bottom: 0.5rem;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.import-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  background: var(--muted);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}

.import-panel h2 {
  margin-top: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}

.stat-card span {
  display: block;
}

.stat-card .stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  margin-top: 0.2rem;
}

.word-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.word-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.word-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.button,
button,
input[type="submit"] {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.button:hover,
button:hover,
input[type="submit"]:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.button.secondary {
  background: var(--muted);
  color: var(--text-primary);
}

.button.secondary:hover {
  background: rgba(45, 108, 223, 0.16);
}

form p {
  margin-bottom: 1.25rem;
}

label {
  font-weight: 600;
  display: inline-block;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.18);
  outline: none;
}

.form-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.5rem 0;
}

.search-input {
  flex: 1 1 260px;
}

.error-text {
  color: var(--warning);
  font-size: 0.85rem;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

th,
td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: rgba(45, 108, 223, 0.08);
  font-weight: 600;
  color: var(--text-secondary);
}

tr:last-child td {
  border-bottom: none;
}

.word-summary {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.word-summary span {
  background: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
}

.word-table td {
  vertical-align: top;
}

.word-title {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.meaning-col {
  max-width: 360px;
}

.actions-col {
  width: 160px;
}

.actions-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions-group form {
  display: inline;
}

.bulk-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
}

.bulk-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.bulk-edit-table input[type="text"],
.bulk-edit-table textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
}

.bulk-edit-table textarea {
  resize: vertical;
}

.heatmap-card {
  overflow-x: auto;
}

.heatmap-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.heatmap-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.heatmap-filter select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.95rem;
}

.heatmap-wrapper {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.heatmap-weekdays {
  display: grid;
  grid-template-rows: repeat(7, 14px);
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.heatmap-weekdays span {
  line-height: 14px;
}

.heatmap-weeks {
  display: flex;
  gap: 4px;
}

.heatmap-week {
  display: grid;
  grid-template-rows: repeat(7, 14px);
  gap: 4px;
}

.heatmap-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--muted);
}

.heatmap-cell--empty {
  background: rgba(28, 35, 51, 0.16);
}

.heatmap-cell--padding {
  opacity: 0;
}

.heatmap-cell--future {
  opacity: 0.2;
}

.heatmap-cell--level-1 {
  background: #c6e48b;
}

.heatmap-cell--level-2 {
  background: #7bc96f;
}

.heatmap-cell--level-3 {
  background: #239a3b;
}

.heatmap-cell--level-4 {
  background: #196127;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.heatmap-legend .heatmap-cell {
  width: 12px;
  height: 12px;
}

blockquote {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  background: var(--muted);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  color: var(--text-secondary);
}

.review-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.review-actions input[type="submit"] {
  flex: none;
  min-width: 160px;
}

.empty-state {
  text-align: center;
  padding: 3rem 0;
  color: var(--text-secondary);
}

.flashcard-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.flashcard {
  width: min(480px, 100%);
  height: 260px;
  perspective: 1200px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.flashcard.is-flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
  text-align: center;
}

.flashcard-face.back {
  transform: rotateY(180deg);
}

.flashcard-front-title {
  font-size: 2rem;
  font-weight: 600;
}

.flashcard-meta {
  margin-top: 0.75rem;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .topbar__inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .topbar__toggle {
    display: flex;
  }

  .topbar__actions {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .topbar__actions.is-open {
    display: flex;
  }

  .nav {
    flex-direction: column;
    width: 100%;
  }

  .nav a {
    padding: 0.5rem 0;
  }

  .actions-group {
    justify-content: flex-start;
  }

  .review-actions {
    flex-direction: column;
  }
}
