/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f8;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  --max-width: 40rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --radius: 6px;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Layout === */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--text-muted);
  border-radius: var(--radius);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-alt);
}

.icon-btn.hidden {
  visibility: hidden;
}

/* === Progress Bar === */
#progress-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-alt);
}

#progress-fill {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill::after {
  content: '';
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

#progress-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  min-width: 4rem;
  text-align: right;
}

/* === Section Tabs === */
#section-tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

#section-tabs:empty {
  display: none;
}

.section-tab {
  padding: var(--space-2) var(--space-3);
  border: none;
  background: var(--bg-alt);
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text);
}

.section-tab:hover {
  background: var(--border);
}

.section-tab.active {
  background: var(--primary);
  color: white;
}

/* === Main Content === */
main {
  flex: 1;
  padding: var(--space-3);
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

/* === Typography === */
h2 {
  font-size: 1.25rem;
  margin: var(--space-4) 0 var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

h3 {
  font-size: 1.1rem;
  margin: var(--space-3) 0 var(--space-2);
}

h4 {
  font-size: 1rem;
  margin: var(--space-2) 0;
}

p {
  margin: var(--space-2) 0;
}

/* === Lojban Text === */
code, .lojban {
  font-family: var(--font-mono);
  background: var(--bg-alt);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.95em;
}

pre {
  background: var(--bg-alt);
  padding: var(--space-3);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
}

pre code {
  padding: 0;
  background: none;
  border-radius: 0;
  font-size: inherit;
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
  margin: var(--space-3) 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

th {
  background: var(--bg-alt);
  font-weight: 600;
}

tr:nth-child(even) {
  background: var(--bg-alt);
}

/* === Blockquotes (Key Points) === */
blockquote {
  border-left: 3px solid var(--primary);
  padding: var(--space-3);
  margin: var(--space-3) 0;
  background: var(--bg-alt);
  border-radius: 0 var(--radius) var(--radius) 0;
}

blockquote p {
  margin: 0;
}

/* === Lists === */
ul, ol {
  padding-left: 1.5rem;
  margin: var(--space-2) 0;
}

li {
  margin: var(--space-1) 0;
}

/* === Exercises === */
.exercise {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: var(--space-3) 0;
}

.exercise-instructions {
  font-weight: 500;
  margin-bottom: var(--space-3);
}

.exercise-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.exercise-item:last-child {
  border-bottom: none;
}

.exercise-prompt {
  font-family: var(--font-mono);
}

.exercise-prompt .english-hint {
  font-family: var(--font-sans);
  font-style: italic;
  color: var(--text-muted);
}

.exercise-input-row {
  display: flex;
  gap: var(--space-2);
}

.exercise-input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1rem;
}

.exercise-input:focus {
  outline: none;
  border-color: var(--primary);
}

.exercise-input.correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.exercise-input.incorrect {
  border-color: var(--error);
  background: #fef2f2;
}

.check-btn {
  padding: var(--space-2) var(--space-3);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}

.check-btn:hover {
  background: var(--primary-hover);
}

.check-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.exercise-feedback {
  font-size: 0.9rem;
  padding: var(--space-2);
  border-radius: var(--radius);
}

.exercise-feedback.correct {
  color: var(--success);
  background: #f0fdf4;
}

.exercise-feedback.incorrect {
  color: var(--error);
  background: #fef2f2;
}

/* === Reveal Button === */
.reveal-btn {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: 0.9rem;
}

.reveal-btn:hover {
  background: var(--border);
}

.revealed-answer {
  font-family: var(--font-mono);
  background: var(--bg-alt);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  margin-top: var(--space-2);
}

/* === Matching Exercise === */
.matching-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.matching-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.matching-item {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-alt);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.matching-item:hover {
  border-color: var(--primary);
}

.matching-item.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

.matching-item.matched {
  border-color: var(--success);
  background: #f0fdf4;
  cursor: default;
}

.matching-item.wrong {
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* === Footer Navigation === */
footer {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}

.nav-btn {
  flex: 1;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  min-height: 44px;
}

.nav-btn:hover {
  background: var(--bg-alt);
}

.nav-btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.nav-btn.primary:hover {
  background: var(--primary-hover);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Home Screen === */
.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.week-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  cursor: pointer;
  transition: all 0.15s ease;
}

.week-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.week-card-title {
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.week-card-progress {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.week-card-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: var(--space-2);
  overflow: hidden;
}

.week-card-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
}

/* === Settings Modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--space-4);
  max-width: 90%;
  width: 20rem;
}

.modal h2 {
  margin: 0 0 var(--space-3);
  padding: 0;
  border: none;
}

.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* === Utilities === */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
