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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  background: #f9f4f4;
  color: #333;
  min-height: 100vh;
}

/* ===== Header ===== */

header {
  background: #8b0000;
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  gap: 12px;
}

header h1 { font-size: 1.05em; font-weight: 600; flex: 1; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.last-updated {
  font-size: 11px;
  opacity: 0.7;
  white-space: nowrap;
}

.secondary-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 5px 11px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.secondary-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== Gist Setup ===== */

#gist-setup {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 50px);
  padding: 24px 16px;
}

.setup-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
}

.setup-card h2 {
  font-size: 1.15em;
  color: #8b0000;
  margin-bottom: 12px;
}

.setup-card p {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 7px;
  font-size: 14px;
  font-family: monospace;
  min-width: 0;
}

.input-row input:focus {
  outline: none;
  border-color: #8b0000;
  box-shadow: 0 0 0 2px rgba(139,0,0,0.12);
}

.btn-primary {
  background: #8b0000;
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.btn-primary:hover { background: #6b0000; }

.hint { font-size: 12px; color: #aaa; }

.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  background: #ffebee;
  color: #c62828;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
}

/* ===== Loading / Error ===== */

.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 50px);
  gap: 16px;
  color: #888;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #f0e0e0;
  border-top-color: #8b0000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-card {
  max-width: 400px;
  margin: 60px auto;
  background: #fff;
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  text-align: center;
  color: #c62828;
}

/* ===== Dashboard ===== */

main { max-width: 860px; margin: 0 auto; padding: 20px 16px 48px; }

.no-data {
  text-align: center;
  padding: 80px 20px;
  color: #888;
}
.no-data p { font-size: 1.1em; }

.section {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.section-title {
  font-size: 0.8em;
  font-weight: 700;
  color: #8b0000;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #f5e0e0;
}

/* Selector */
.selector-row { display: flex; align-items: center; gap: 10px; }
.selector-row label { font-size: 13px; color: #666; white-space: nowrap; }

select {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 13px;
  background: #fff;
  color: #333;
}

/* Overview cards */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.card {
  background: #fdf5f5;
  border: 1px solid #ead5d5;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.card-label { font-size: 11px; color: #999; margin-bottom: 4px; }
.card-value { font-size: 1.5em; font-weight: 700; color: #8b0000; line-height: 1.2; }

/* Charts */
.chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-wrap svg { display: block; min-width: 380px; }

.chart-note {
  color: #999;
  font-size: 13px;
  padding: 24px;
  text-align: center;
  background: #fafafa;
  border-radius: 6px;
}

/* Subject table */
.subject-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 16px;
}

.subject-table th,
.subject-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f0f0f0;
}

.subject-table th {
  background: #fdf5f5;
  color: #8b0000;
  font-weight: 600;
  text-align: left;
  font-size: 12px;
  position: sticky;
  top: 50px;
}

.subject-table tbody tr:hover { background: #fafafa; }
.subject-table td:not(:first-child) { text-align: right; }
.subject-table th:not(:first-child) { text-align: right; }

.rate-bar-cell { width: 110px; }
.rate-bar-wrap { height: 7px; background: #f0f0f0; border-radius: 4px; overflow: hidden; margin-top: 3px; }
.rate-bar { height: 100%; border-radius: 4px; }

/* Sort */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: #f0e0e0; }
th.sort-active { color: #8b0000; }

.col-correct { color: #2e7d32; font-weight: 600; }
.col-partial { color: #e65100; }
.col-incorrect { color: #c62828; font-weight: 600; }
.rate-good { color: #2e7d32; font-weight: 700; }
.rate-mid { color: #e65100; font-weight: 700; }
.rate-bad { color: #c62828; font-weight: 700; }

/* Subject selector */
.subject-selector-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.subject-selector-row label { font-size: 13px; color: #666; white-space: nowrap; }

/* ===== Responsive ===== */

@media (max-width: 540px) {
  header h1 { font-size: 0.95em; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card-value { font-size: 1.25em; }
  .setup-card { padding: 24px 18px; }
  .input-row { flex-direction: column; }
  .input-row input { width: 100%; }
  .subject-table { font-size: 12px; }
  .subject-table th, .subject-table td { padding: 6px 7px; }
  .rate-bar-cell { width: 80px; }
}
