/* ============================================================
   MATHSPARK — STYLESHEET  (style.css)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=DM+Sans:wght@700;800&display=swap');

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

:root {
  --accent:   #2563eb;
  --accent2:  #f59e0b;
  --bg:       #f0f2f8;
  --surface:  #ffffff;
  --border:   #dde1ef;
  --text:     #1e1b3a;
  --muted:    #6b7280;
  --light:    #f5f4fa;
  --green:    #16a34a;
  --radius:   12px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LAYOUT ── */
.app { max-width: 980px; margin: 0 auto; padding: 32px 16px 80px; }

/* ── HEADER ── */
.header { text-align: center; margin-bottom: 36px; }
#logo-wrap { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.logo-img  { height: 38px; object-fit: contain; }
.app-name  { font-family: 'DM Sans', sans-serif; font-size: 2.2rem; color: var(--accent); letter-spacing: -0.5px; }
.app-tagline { color: var(--muted); font-size: 0.9rem; }

/* ── CARD ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.card-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── TYPE GRID ── */
#type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--light);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}
.type-btn:hover {
  border-color: var(--accent);
  background: #eff4ff;
  transform: translateY(-1px);
}
.type-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 14px rgba(37,99,235,0.25);
}
.type-emoji { font-size: 1.5rem; line-height: 1; }
.type-label { font-size: 0.78rem; font-weight: 600; text-align: center; }

/* ── CONTROLS ROW ── */
.controls-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  align-items: end;
}
@media (max-width: 600px) { .controls-row { grid-template-columns: 1fr 1fr; } }

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 7px;
}
.field select,
.field input[type="number"],
.field input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--light);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s;
}
.field select:focus,
.field input:focus { border-color: var(--accent); }

/* ── GENERATE BUTTON ── */
#btn-generate {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 4px;
  letter-spacing: 0.2px;
}
#btn-generate:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.3); }

/* ── ACTION BAR ── */
#action-bar {
  display: none;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.action-label { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-right: 4px; }

.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-export  { background: var(--accent); color: white; }
.btn-export:hover:not(:disabled)  { background: #1d4ed8; }
.btn-print   { background: #0f766e; color: white; }
.btn-print:hover:not(:disabled)   { background: #115e59; }
.btn-regen   { background: var(--light); border: 1.5px solid var(--border); color: var(--text); }
.btn-regen:hover:not(:disabled)   { border-color: var(--accent); color: var(--accent); }
.btn-clear   { background: transparent; border: 1.5px solid var(--border); color: var(--muted); margin-left: auto; }
.btn-clear:hover:not(:disabled)   { border-color: #dc2626; color: #dc2626; }

/* ── STUDENT NAME in action bar ── */
.sn-wrap { display: flex; align-items: center; gap: 8px; }
.sn-wrap label { font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.sn-wrap input {
  padding: 7px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--light);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  outline: none;
  width: 150px;
  transition: border-color 0.2s;
}
.sn-wrap input:focus { border-color: var(--accent); }

/* ── PREVIEW SECTION ── */
#preview-section { display: none; }

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
#preview-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}
.preview-badge {
  font-size: 0.72rem;
  background: #eff4ff;
  color: var(--accent);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: 3px 10px;
  font-weight: 700;
}

#preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 500px) { #preview-grid { grid-template-columns: 1fr; } }

.preview-card {
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  position: relative;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.preview-card.word-card { min-height: 90px; justify-content: flex-start; }

.pc-num {
  position: absolute;
  top: 8px; right: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  color: white;
  background: var(--accent);
  border-radius: 20px;
  padding: 1px 7px;
}
.pc-q {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}
.pc-q.word { font-size: 0.88rem; font-weight: 500; margin-top: 4px; }
.pc-blank {
  display: inline-block;
  width: 48px; height: 22px;
  border-bottom: 2.5px solid var(--accent);
  vertical-align: bottom;
  margin-left: 4px;
}
.pc-line {
  border-bottom: 1.5px solid var(--border);
  margin-top: 12px;
}

/* ── EMPTY STATE ── */
#empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 3.5rem; margin-bottom: 12px; }
#empty-state h2 { font-family: 'DM Sans', sans-serif; font-size: 1.5rem; color: var(--text); margin-bottom: 6px; }
#empty-state p  { color: var(--muted); font-size: 0.92rem; }

/* ── FOOTER ── */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
  margin-top: 60px;
}
.footer a { color: var(--accent); text-decoration: none; }

/* ── PRINT AREA (hidden on screen) ── */
#print-area { display: none; }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  body > * { display: none !important; }
  #print-area { display: block !important; }

  .print-sheet {
    font-family: Arial, sans-serif;
    padding: 14mm 14mm 10mm;
    color: #111;
  }

  /* Header */
  .print-header { border-bottom: 2px solid #2563eb; padding-bottom: 6px; margin-bottom: 10px; }
  .print-title  { font-size: 14pt; font-weight: 900; color: #1e3a8a; }
  .print-sub    { font-size: 8pt; color: #555; margin-top: 2px; }

  /* Name / Date / Score row */
  .print-meta-row {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 12px; font-size: 9pt; color: #333;
  }
  .meta-field  { display: flex; align-items: center; gap: 4px; }
  .meta-line   { display: inline-block; width: 80px; border-bottom: 1px solid #999; }
  .meta-line.short { width: 50px; }
  .meta-score  {
    margin-left: auto;
    border: 1px solid #999;
    border-radius: 4px;
    padding: 3px 10px;
    font-weight: 700;
    font-size: 8.5pt;
  }

  /* Problems grid — 2 columns */
  .print-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .pp {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px 12px;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    background: #fafbff;
  }

  .pn {
    position: absolute;
    top: 5px; right: 8px;
    font-size: 7pt;
    font-weight: 700;
    color: white;
    background: #2563eb;
    border-radius: 20px;
    padding: 1px 6px;
  }

  .pq {
    font-size: 14pt;
    font-weight: 900;
    line-height: 1.3;
    color: #111;
  }
  .pq.word {
    font-size: 8.5pt;
    font-weight: 500;
    margin-top: 4px;
    white-space: pre-line;
  }

  .blank {
    display: inline-block;
    width: 44px;
    border-bottom: 2px solid #2563eb;
    vertical-align: bottom;
    margin-left: 4px;
  }

  .pline {
    border-bottom: 1px solid #ccc;
    margin-top: 10px;
  }

  /* Answer key — page break before, 5-col grid */
  .print-answer-key {
    page-break-before: always;
    padding-top: 10mm;
  }

  .ak-title {
    font-size: 13pt;
    font-weight: 900;
    color: #1e3a8a;
    border-bottom: 2px solid #2563eb;
    padding-bottom: 5px;
    margin-bottom: 12px;
  }

  .ak-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }

  .ak-item {
    font-size: 9pt;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 6px 8px;
    background: #f5f4fa;
    text-align: center;
  }
}
