:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --yellow: #eab308;
  --red: #dc2626;
  --soft: #f1f5f9;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  color: var(--text);
  min-height: 100vh;
}

.page-header {
  padding: 2rem 2rem 1rem;
  max-width: 1300px;
  margin: 0 auto;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-header .subtitle { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }
.page-header code {
  background: var(--soft); padding: 0.1rem 0.4rem; border-radius: 4px;
  font-size: 0.85rem;
}

.layout {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 2rem 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
  margin: 0 0 1.25rem;
}
legend { padding: 0 0.4rem; font-weight: 600; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }

label {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
label:last-child { margin-bottom: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="file"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
input[type="file"] { padding: 0.35rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.hint { color: var(--muted); font-size: 0.8rem; font-weight: normal; }

.subsection {
  background: var(--soft);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}
.subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.subsection-head h3 { margin: 0; font-size: 0.95rem; }

.subject-row, .period-row {
  display: grid;
  grid-template-columns: 2fr 90px 80px auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
.subject-row label, .period-row label { margin-bottom: 0; }
.period-row { grid-template-columns: 1fr 1fr 110px auto; }

button {
  appearance: none;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.75; cursor: not-allowed; }

button#submit-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 140px;
  justify-content: center;
}
button#submit-btn .spinner { display: none; }
button#submit-btn.loading .spinner { display: inline-block; }
button#submit-btn.loading { background: var(--accent-hover); }

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress {
  margin-top: 1rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--soft);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.progress-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.progress-steps li {
  position: relative;
  padding-left: 1.65rem;
  color: var(--muted);
  font-size: 0.875rem;
  transition: color 0.2s ease;
}
.progress-steps li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: background 0.2s ease, transform 0.2s ease;
}
.progress-steps li.done { color: var(--text); }
.progress-steps li.done::before {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}
.progress-steps li.active { color: var(--text); font-weight: 600; }
.progress-steps li.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

form.is-busy fieldset { opacity: 0.7; pointer-events: none; }
form.is-busy #submit-btn { pointer-events: none; }

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  animation: fade-in 0.15s ease-out;
}

.modal-content {
  position: relative;
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
  max-width: 640px;
  width: 100%;
  padding: 1.5rem 1.5rem 1.25rem;
  animation: pop-in 0.18s ease-out;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-close { font-size: 1.5rem; line-height: 1; }

.rules-table {
  width: 100%;
  margin-top: 0.75rem;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.rules-table th, .rules-table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.rules-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.rules-table td:last-child { width: 90px; }

.light-pill {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.light-pill.green  { background: var(--green); }
.light-pill.yellow { background: var(--yellow); color: #422006; }
.light-pill.red    { background: var(--red); }

.header-actions { display: flex; gap: 0.5rem; }

.login-wall {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}
.login-wall[hidden] { display: none; }

.login-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  padding: 1.75rem 1.75rem 1.5rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: pop-in 0.2s ease-out;
}
.login-card h2 { margin: 0; font-size: 1.15rem; }
.login-card .muted { margin: 0 0 0.5rem; font-size: 0.875rem; }
.login-card label { margin-bottom: 0; }

#login-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 0.25rem;
}
#login-submit .spinner { display: none; }
#login-submit.loading .spinner { display: inline-block; }
#login-submit.loading { background: var(--accent-hover); }

#login-error { margin: 0.25rem 0 0; }

button.ghost, a.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}
button.ghost:hover, a.ghost:hover { background: rgba(37, 99, 235, 0.08); }

button.icon {
  background: transparent;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
}
button.icon:hover { color: var(--red); background: transparent; }

.actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}
.status { font-size: 0.875rem; color: var(--muted); }
.status.error { color: var(--red); }

.result-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.result-title h2 { margin: 0; font-size: 1.15rem; }
.muted { color: var(--muted); margin: 0.1rem 0 0; font-size: 0.9rem; }

.traffic-light {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #cbd5e1;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.3);
}
.traffic-light.green { background: var(--green); }
.traffic-light.yellow { background: var(--yellow); }
.traffic-light.red { background: var(--red); }

.score-value {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: right;
  line-height: 1;
}
.score-label { color: var(--muted); font-size: 0.8rem; text-align: right; text-transform: uppercase; letter-spacing: 0.05em; }

.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0 0 1rem;
}
.meta > div { background: var(--soft); padding: 0.75rem 1rem; border-radius: 8px; }
.meta dt { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.meta dd { margin: 0.25rem 0 0; font-weight: 600; }

.prose { line-height: 1.55; white-space: pre-wrap; }

.columns-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 700px) { .columns-2 { grid-template-columns: 1fr; } }

.tag-list { list-style: none; padding: 0; margin: 0.4rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; }
.tag-list li {
  background: var(--soft);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  font-size: 0.875rem;
}
.tag-list li.empty { color: var(--muted); font-style: italic; background: transparent; padding-left: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.875rem;
}
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.05em; }
td.meets-yes { color: var(--green); font-weight: 600; }
td.meets-no { color: var(--red); font-weight: 600; }

.json {
  background: #0f172a;
  color: #e2e8f0;
  padding: 0.9rem 1rem;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  max-height: 400px;
}

details > summary { cursor: pointer; color: var(--accent); font-size: 0.875rem; margin-bottom: 0.5rem; }

h3 { font-size: 0.95rem; margin: 1.25rem 0 0.25rem; }
