:root {
  --bg: #fff;
  --text: #333;
  --panel-bg: #f8f9fa;
  --panel-border: #dee2e6;
  --input-border: #ced4da;
  --input-bg: #fff;
  --problem-number-color: #666;
  --line-color: #333;
  --answer-color: #c00;
  --separator-color: #aaa;
  --problem-color: #000;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --text: #e0e0e0;
  --panel-bg: #16213e;
  --panel-border: #2a2a4a;
  --input-border: #3a3a5a;
  --input-bg: #1a1a3e;
  --problem-number-color: #999;
  --line-color: #c0c0c0;
  --answer-color: #ff6b6b;
  --separator-color: #555;
  --problem-color: #fff;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 {
  margin-bottom: 1.5rem;
  font-size: 1.8rem;
}

/* Theme toggle */
#theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1000;
}

#theme-toggle:hover {
  border-color: var(--text);
}

#theme-toggle .icon-sun { display: none; }
#theme-toggle .icon-moon { display: inline; }

[data-theme="dark"] #theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] #theme-toggle .icon-moon { display: none; }

#config-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2rem;
}

.form-row {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.form-row label {
  flex: 0 0 180px;
  font-weight: 600;
}

.form-row select,
.form-row input[type="text"] {
  flex: 1;
  max-width: 300px;
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text);
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 1rem;
}

button {
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

#generate-btn {
  background: #0d6efd;
  color: white;
}

#generate-btn:hover {
  background: #0b5ed7;
}

#print-btn {
  background: #198754;
  color: white;
}

#print-btn:hover {
  background: #157347;
}

#download-pdf-btn {
  background: #6f42c1;
  color: white;
}

#download-pdf-btn:hover {
  background: #5a32a3;
}

/* Quiz output */
#quiz-output {
  margin-top: 1rem;
}

#quiz-section,
#answer-key-section {
  margin-bottom: 2rem;
}

#quiz-heading,
#answer-key-heading {
  text-align: center;
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  font-size: 1rem;
}

.problems-grid {
  display: grid;
  gap: 5rem 3rem;
  justify-items: center;
}

.problem {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: "Courier New", Courier, monospace;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--problem-color);
  line-height: 1.8;
  position: relative;
  min-width: 6em;
  gap: 0.3em;
}

.problem .problem-number {
  position: absolute;
  left: -2.2em;
  top: 0;
  font-size: 0.9rem;
  color: var(--problem-number-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.problem .top-number {
  text-align: right;
  padding-right: 0.3em;
}

.problem .bottom-row {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

.problem .operator {
  text-align: left;
  margin-right: 0.4em;
}

.problem .bottom-number {
  text-align: right;
  padding-right: 0.3em;
}

.problem .line {
  width: 100%;
  border-bottom: 3px solid var(--problem-color);
  margin-top: 0.2em;
  margin-bottom: 0.4em;
}

.problem .answer {
  text-align: right;
  padding-right: 0.3em;
  color: var(--answer-color);
  font-weight: bold;
}

#quiz-standards {
  text-align: center;
  font-size: 0.7rem;
  color: var(--problem-number-color);
  margin-top: 0.25rem;
  margin-bottom: 2rem;
}

/* Answer key separator */
#answer-key-section {
  border-top: 2px dashed var(--separator-color);
  padding-top: 1.5rem;
}
