/* === Variables & Reset === */
:root {
  --gm-primary: #1e3a8a;        /* Deep blue */
  --gm-primary-light: #3b5ba5;
  --gm-accent: #f59e0b;          /* Warm gold */
  --gm-bg: #ffffff;
  --gm-surface: #f9fafb;
  --gm-border: #e5e7eb;
  --gm-text: #111827;
  --gm-text-light: #6b7280;
  --gm-shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
  --gm-shadow-md: 0 10px 25px -5px rgba(0,0,0,0.1);
  --gm-radius: 20px;
  --gm-radius-sm: 14px;
  --gm-transition: all 0.2s ease;
}

* {
  box-sizing: border-box;
}

/* === Base Shell === */
.gm-shell {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--gm-text);
  max-width: 1200px;
  margin: 0 auto;
  background: var(--gm-bg);
  border-radius: var(--gm-radius);
  box-shadow: var(--gm-shadow-md);
  padding: 1.5rem;
}

/* === Toolbar === */
.gm-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--gm-border);
}

.gm-toolbar__left,
.gm-toolbar__right {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gm-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gm-text-light);
  margin-bottom: 0.25rem;
}

.gm-select {
  min-width: 220px;
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius-sm);
  padding: 0.6rem 1rem;
  background: var(--gm-surface);
  font-size: 0.95rem;
  transition: var(--gm-transition);
  cursor: pointer;
}

.gm-select:hover {
  border-color: var(--gm-primary-light);
  box-shadow: var(--gm-shadow-sm);
}

.gm-select:focus {
  outline: none;
  border-color: var(--gm-primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.gm-btn {
  border: none;
  background: var(--gm-primary);
  color: white;
  border-radius: var(--gm-radius-sm);
  padding: 0.7rem 1.4rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--gm-transition);
  box-shadow: var(--gm-shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.gm-btn:hover {
  background: var(--gm-primary-light);
  transform: translateY(-1px);
  box-shadow: var(--gm-shadow-md);
}

.gm-btn:active {
  transform: translateY(0);
}

.gm-btn--ghost {
  background: transparent;
  color: var(--gm-primary);
  border: 1px solid var(--gm-primary);
  box-shadow: none;
}

.gm-btn--ghost:hover {
  background: rgba(30, 58, 138, 0.05);
  color: var(--gm-primary-light);
  border-color: var(--gm-primary-light);
}

.gm-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.5);
}

/* === Status Message === */
.gm-status {
  min-height: 2rem;
  font-size: 0.9rem;
  color: var(--gm-text-light);
  margin: 0.5rem 0 1rem;
  padding: 0.5rem 1rem;
  background: var(--gm-surface);
  border-radius: var(--gm-radius-sm);
  border-left: 4px solid var(--gm-primary);
}

.gm-status--err {
  border-left-color: #dc2626;
  color: #b91c1c;
  background: #fee2e2;
}

/* === Paper Output === */
.gm-output {
  margin-top: 1.5rem;
}

.gm-note {
  padding: 1.2rem 1.5rem;
  border: 2px dashed var(--gm-border);
  border-radius: var(--gm-radius);
  background: var(--gm-surface);
  text-align: center;
  color: var(--gm-text-light);
  font-size: 1rem;
}

/* === Print-ready Paper === */
.gm-printwrap {
  background: white;
}

.gm-paper {
  background: white;
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius);
  padding: 2rem 2rem 1.5rem;
  box-shadow: var(--gm-shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 600px;
  min-height: calc(297mm - 30mm);
  transition: var(--gm-transition);
}

.gm-paper:hover {
  box-shadow: var(--gm-shadow-md);
}

.gm-paper__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 3px solid var(--gm-primary);
  flex-wrap: wrap;
}

.gm-paper__title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--gm-primary);
  line-height: 1.2;
}

.gm-paper__pills {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.gm-pill {
  border: 1px solid var(--gm-border);
  border-radius: 100px;
  padding: 0.3rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--gm-surface);
  color: var(--gm-text);
}

.gm-paper__meta {
  font-size: 0.9rem;
  line-height: 1.6;
  min-width: 240px;
  background: var(--gm-surface);
  padding: 0.75rem 1rem;
  border-radius: var(--gm-radius-sm);
}

.gm-fill {
  display: inline-block;
  border-bottom: 2px dotted var(--gm-border);
  min-width: 160px;
  padding: 0 0.25rem;
  font-weight: 500;
  color: var(--gm-primary);
}

.gm-paper__body {
  padding: 1.5rem 0;
  display: grid;
  gap: 1.2rem;
  flex: 1;
}

.gm-cols-2 {
  grid-template-columns: repeat(2, 1fr);
  column-gap: 1.5rem;
}

@media (max-width: 640px) {
  .gm-cols-2 {
    grid-template-columns: 1fr;
  }
}

.gm-q {
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius-sm);
  padding: 1rem 1.2rem;
  background: white;
  break-inside: avoid;
  transition: var(--gm-transition);
}

.gm-q:hover {
  border-color: var(--gm-primary-light);
  box-shadow: var(--gm-shadow-sm);
}

.gm-q__row {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
}

.gm-q__num {
  font-weight: 700;
  color: var(--gm-primary);
  min-width: 2rem;
  font-size: 1.1rem;
}

.gm-q__text {
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.4;
}

.gm-q__ans {
  margin-top: 0.8rem;
  font-size: 0.95rem;
  display: flex;
  gap: 0.8rem;
  align-items: center;
  color: var(--gm-text-light);
}

.gm-anslbl {
  font-weight: 600;
  color: var(--gm-text);
}

.gm-ansline {
  flex: 1;
  border-bottom: 2px dashed var(--gm-border);
  height: 1px;
}

.gm-paper__footer {
  border-top: 1px solid var(--gm-border);
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--gm-text-light);
}

/* === Fractions === */
.gm-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1;
  margin: 0 2px;
}

.gm-frac__top,
.gm-frac__bot {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--gm-primary);
}

.gm-frac__bar {
  width: 1.2em;
  border-top: 2px solid var(--gm-primary);
  margin: 2px 0;
}

/* === Test10 & Flashcards === */
.gm-test10, .gm-fc {
  margin-top: 1.5rem;
}

.gm-testhdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gm-surface);
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius-sm);
  padding: 1rem 1.5rem;
  font-weight: 600;
}

.gm-timer {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gm-primary);
  background: white;
  padding: 0.3rem 1rem;
  border-radius: 100px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.gm-testbody {
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius-sm);
  padding: 1.5rem;
  margin: 1rem 0;
  background: white;
}

.gm-qnum {
  font-size: 0.85rem;
  color: var(--gm-text-light);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.gm-input {
  width: 100%;
  border: 2px solid var(--gm-border);
  border-radius: var(--gm-radius-sm);
  padding: 0.8rem 1rem;
  font-size: 1rem;
  transition: var(--gm-transition);
}

.gm-input:focus {
  outline: none;
  border-color: var(--gm-primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}

.gm-testctrl {
  display: flex;
  gap: 0.8rem;
  margin-top: 1rem;
}

/* Flashcards */
.gm-fcbox {
  border: 1px solid var(--gm-border);
  border-radius: var(--gm-radius);
  padding: 1.5rem;
  background: white;
}

.gm-fchdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.gm-fccard {
  border: 2px solid var(--gm-border);
  border-radius: var(--gm-radius);
  padding: 2rem;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--gm-surface);
  transition: var(--gm-transition);
}

.gm-fccard:hover {
  border-color: var(--gm-primary-light);
}

.gm-fcq {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gm-primary);
  line-height: 1.3;
}

.gm-fca {
  margin-top: 1.5rem;
  font-size: 1.2rem;
  padding-top: 1rem;
  border-top: 2px dashed var(--gm-border);
}

.gm-fcctrl {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* === Print Styles === */
@media print {
  @page {
    size: A4;
    margin: 15mm;
  }
  body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    background: white;
  }
  .gm-toolbar,
  .gm-status,
  .gm-note,
  .gm-testctrl,
  .gm-fcctrl,
  [data-gm-generate],
  [data-gm-print] {
    display: none !important;
  }
  .gm-shell {
    box-shadow: none;
    padding: 0;
    max-width: 100%;
  }
  .gm-paper {
    box-shadow: none;
    border: 2px solid var(--gm-primary);
    page-break-after: always;
    min-height: auto;
  }
  .gm-pagebreak {
    break-after: page;
    page-break-after: always;
  }
  .gm-fill {
    border-bottom: 1px solid black;
  }
}