/* Mock Test pages (instructions, player, result). Ported 1:1 from the CSS Modules in
   frontend/src/pages/tests plus the Timer, QuestionPalette and ConfirmDialog components. */

/* ---- Instructions ---- */
.test-page {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.test-page__top-nav {
  display: flex;
  gap: var(--spacing-md);
}

.test-page__back-link {
  font-size: 0.9rem;
}

.test-page__title {
  margin: 0;
  font-size: 1.5rem;
}

.test-page__post-link {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.test-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-sm);
}

@media (min-width: 640px) {
  .test-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.test-stats__item {
  padding: var(--spacing-sm);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  text-align: center;
}

.test-stats__value {
  font-size: 1.2rem;
  font-weight: 700;
}

.test-stats__label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.test-page__instructions {
  white-space: pre-wrap;
  line-height: 1.6;
}

.test-page__details {
  padding: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  line-height: 1.6;
}

.test-page__details h2 {
  margin-top: 0;
}

.test-page__details ul {
  margin-bottom: 0;
  padding-left: var(--spacing-lg);
}

.test-page__start-button {
  align-self: flex-start;
  padding: var(--spacing-sm) var(--spacing-xl);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: white;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}

.test-page__start-button:hover {
  background: var(--color-primary-hover);
}

/* ---- Timer ---- */
.test-timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 700;
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

.test-timer--critical {
  color: var(--color-danger);
}

/* ---- Player ---- */
/* The player fills the viewport exactly (position:fixed rather than 100vh, which `zoom` on <html>
   would scale), so the page never scrolls. The compact header and hidden footer leave the room. */
.layout--test-player {
  position: fixed;
  inset: 0;
  min-height: 0;
  overflow: hidden;
}

/* Footer stays visible but is squeezed into one slim row (links, social icons, copyright). */
.layout--test-player .site-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px var(--spacing-lg);
  padding: 6px var(--spacing-md);
  font-size: 0.78rem;
}

.layout--test-player .site-footer__links,
.layout--test-player .site-footer__social {
  margin-bottom: 0;
  gap: var(--spacing-md);
}

.layout--test-player .site-footer__social {
  gap: var(--spacing-sm);
}

.layout--test-player .site-footer__social-icon {
  width: 24px;
  height: 24px;
}

.layout--test-player .site-footer__social-icon svg {
  width: 14px;
  height: 14px;
}

.layout--test-player .site-header__banner {
  padding-block: 4px;
}

.layout--test-player .site-header__logo {
  width: 40px;
  height: 43px;
}

.layout--test-player .site-nav__link {
  padding-block: 5px;
}

.test-player {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.test-player__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.test-player__palette-toggle {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-background);
  cursor: pointer;
}

@media (min-width: 1024px) {
  .test-player__palette-toggle {
    display: none;
  }
}

.test-player__body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Only the question area scrolls (when a question is long); the palette scrolls separately. */
.test-player__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: var(--spacing-md) var(--spacing-md) 0;
}

.test-player__section-tabs {
  display: flex;
  overflow-x: auto;
  gap: var(--spacing-xs);
  padding-bottom: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
  border-bottom: 1px solid var(--color-border);
}

.test-player__section-tab {
  flex-shrink: 0;
  padding: var(--spacing-xs) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-background);
  cursor: pointer;
  white-space: nowrap;
}

.test-player__section-tab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.test-player__section-tab--active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.player-question__text {
  font-size: 1.05rem;
  line-height: 1.5;
}

.player-question__image {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: var(--spacing-sm) 0;
}

.player-question__options {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-md);
}

.player-question__option {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.test-player__error {
  color: var(--color-danger);
  text-align: center;
}

/* Sits right under the options; for a long question it sticks to the bottom of the question
   area instead of scrolling out of sight. */
.test-player__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  position: sticky;
  bottom: 0;
  margin-top: var(--spacing-md);
  padding: var(--spacing-sm) 0 var(--spacing-md);
  background: var(--color-background);
}

.test-player__action {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-background);
  cursor: pointer;
}

.test-player__action--primary {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
}

.test-player__action--submit {
  border-color: var(--color-danger);
  background: var(--color-danger);
  color: white;
  margin-left: auto;
}

/* Palette: a sidebar on desktop, a slide-in drawer (toggled by "Questions") below 1024px. */
.test-player__palette {
  display: none;
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--color-border);
  padding: var(--spacing-md);
  overflow-x: hidden;
  overflow-y: auto;
}

.test-player__palette.is-open {
  display: block;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 320px;
  background: var(--color-background);
  z-index: 101;
}

.test-player__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
}

@media (min-width: 1024px) {
  .test-player__palette,
  .test-player__palette.is-open {
    display: block;
    position: static;
    width: 280px;
    max-width: none;
    z-index: auto;
  }

  .test-player__overlay {
    display: none;
  }
}

/* ---- QuestionPalette ---- */
.palette__section {
  margin-bottom: var(--spacing-md);
}

.palette__section-name {
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
}

.palette__grid {
  display: grid;
  /* Fit as many cells as the sidebar allows; the old fixed 8 columns overflowed it. */
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: var(--spacing-xs);
}

.palette__cell {
  min-width: 0;
  padding: 0;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  background: #9aa0a6; /* not-visited */
}

.palette__cell--not-answered {
  background: var(--color-danger);
}

.palette__cell--answered {
  background: var(--color-success);
}

.palette__cell--marked {
  background: #8b5cf6;
}

.palette__cell--current {
  border-color: var(--color-text);
}

.palette__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  font-size: 0.8rem;
  margin-top: var(--spacing-sm);
  color: var(--color-text-muted);
  /* Stays visible at the bottom of the scrolling palette. */
  position: sticky;
  bottom: calc(var(--spacing-md) * -1);
  padding: var(--spacing-sm) 0;
  background: var(--color-background);
}

.palette__swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: var(--spacing-xs);
  vertical-align: middle;
}

/* ---- Confirm dialog (native <dialog>; same look as Modal + ConfirmDialog) ---- */
.test-dialog {
  background: var(--color-background);
  color: var(--color-text);
  border: none;
  border-radius: var(--radius-md);
  max-width: 480px;
  width: calc(100% - 2 * var(--spacing-md));
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--spacing-lg);
}

.test-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.test-dialog__title {
  margin: 0 0 var(--spacing-md);
  font-size: 1.25rem;
}

.test-dialog__message {
  margin: 0 0 var(--spacing-lg);
  color: var(--color-text-muted);
}

.test-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
}

.test-dialog__button {
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-background);
  cursor: pointer;
}

.test-dialog__button--danger {
  border-color: var(--color-danger);
  background: var(--color-danger);
  color: white;
}

/* ---- Result ---- */
.result-page {
  max-width: 860px;
  margin: 0 auto;
  padding: var(--spacing-lg) var(--spacing-md);
  width: 100%;
}

.result-page__top-nav {
  display: flex;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
  font-size: 0.9rem;
}

.result-page__title {
  margin-bottom: var(--spacing-md);
}

.result-page__summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

@media (min-width: 640px) {
  .result-page__summary {
    grid-template-columns: repeat(4, 1fr);
  }
}

.result-page__card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm);
  text-align: center;
}

.result-page__value {
  font-size: 1.4rem;
  font-weight: 700;
}

.result-page__label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.result-page__section-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--spacing-lg);
}

.result-page__section-table th,
.result-page__section-table td {
  border: 1px solid var(--color-border);
  padding: var(--spacing-xs) var(--spacing-sm);
  text-align: left;
}

.result-review__toggle {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-background);
  cursor: pointer;
  margin-bottom: var(--spacing-md);
}

.result-review__question {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
}

.result-review__question--correct {
  border-left: 4px solid var(--color-success);
}

.result-review__question--wrong {
  border-left: 4px solid var(--color-danger);
}

.result-review__question--unattempted {
  border-left: 4px solid var(--color-border);
}

.result-review__image {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: var(--spacing-sm) 0;
}

.result-review__options {
  list-style: none;
  padding: 0;
  margin: var(--spacing-sm) 0;
}

.result-review__option {
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

.result-review__option--correct {
  background: rgba(34, 197, 94, 0.15);
  font-weight: 600;
}

.result-review__option--wrong {
  background: rgba(239, 68, 68, 0.15);
  font-weight: 600;
}

.result-review__marks {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.result-review__explanation {
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px dashed var(--color-border);
  font-size: 0.95rem;
}
