/* Prelims exam layout: question | options | sidebar (rail + palette).
   Loaded after styles.min.css so these rules win. */

body.test-flow-active #test-flow-wrap.test-flow-wrap-v2 {
  display: flex;
  flex-direction: column;
  max-width: none;
  width: 100%;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #f3f4f6;
  position: relative;
}

body.test-flow-active #test-flow-wrap.test-flow-wrap-v2.test-intro-open {
  display: flex;
}

.test-flow-header,
.test-flow-header-v2,
.test-flow-split,
.test-flow-footer {
  display: none !important;
}

.test-flow-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  order: 1;
}

.test-flow-side-col {
  order: 2;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #0a2518;
}

.test-flow-rail {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #0a2a1b;
  color: #fff;
  z-index: 8;
}

.test-flow-rail-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.test-flow-rail .test-flow-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.test-flow-rail .test-flow-title-block {
  display: none;
}

.test-flow-rail-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.test-flow-rail .test-flow-timer,
.test-flow-rail .test-flow-answered-pill {
  font-size: 0.72rem;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(201, 168, 76, 0.4);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.test-flow-rail .test-flow-answered-pill {
  font-family: 'DM Sans', system-ui, sans-serif;
  cursor: default;
}

.test-flow-rail .test-flow-answered-pill span {
  color: #d4af37;
}

.test-flow-rail .test-flow-timer.warn {
  background: rgba(198, 40, 40, 0.85);
  border-color: #fca5a5;
}

.test-flow-rail .test-flow-timer.hidden-timer {
  display: none;
}

.test-flow-rail .test-flow-lang-toggle,
.test-flow-rail .test-instructions-box {
  display: flex !important;
  margin: 0;
}

.test-flow-rail .test-flow-lang-toggle {
  align-items: center;
  gap: 0;
  padding: 3px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  width: auto;
  flex: 0 0 auto;
}

.test-flow-rail .test-lang-btn {
  flex: 0 0 auto;
  padding: 5px 8px;
  font-size: 0.68rem;
  font-weight: 800;
  color: rgba(245, 240, 230, 0.8);
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  max-width: none;
}

.test-flow-rail .test-lang-btn.active {
  color: #0a2518;
  background: #c9a84c;
  box-shadow: none;
}

.test-lang-full {
  display: none;
}

.test-lang-short {
  display: inline;
}

.test-flow-rail .test-instructions-box {
  position: relative;
  padding: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  color: #fff;
  flex: 0 0 auto;
  overflow: visible;
}

.test-flow-rail .test-instructions-box summary {
  padding: 5px 9px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  gap: 4px;
}

.test-flow-rail .test-instructions-box summary i.fa-info-circle {
  color: #c9a84c;
  margin-right: 2px;
}

.test-flow-rail .test-instructions-chevron {
  display: none;
}

.test-flow-rail .test-instructions-box ul {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: auto;
  width: min(320px, calc(100vw - 24px));
  z-index: 40;
  margin: 0;
  padding: 12px 14px 12px 28px;
  background: #fff;
  color: #334155;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  font-size: 0.8rem;
  line-height: 1.5;
}

.test-flow-meta-chips {
  display: none;
}

.test-flow-left {
  flex: 0 0 auto;
  overflow: visible;
  padding: 12px 14px 8px;
  background: #fff;
  max-height: none;
  border: none;
}

.test-flow-right {
  flex: 0 0 auto;
  overflow: visible;
  background: #f8fafc;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.test-flow-options-scroll {
  overflow: visible;
  padding: 8px 14px 12px;
  flex: 0 0 auto;
}

.test-flow-action-wrap {
  flex: 0 0 auto;
  padding: 12px 14px 16px;
  background: #f8fafc;
  border-top: 1px solid #e8ecf0;
}

.test-save-action-btn {
  display: block;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  min-height: 48px;
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  background: #0a2518;
  color: #c9a84c;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(10, 37, 24, 0.22);
  box-sizing: border-box;
}

.test-save-action-btn.test-save-action-submit:not(.disabled) {
  background: #0a2518;
  color: #e8d48a;
}

.test-save-action-btn.disabled,
.test-save-action-btn:disabled {
  background: #d1d5db !important;
  color: #9ca3af !important;
  cursor: not-allowed;
  box-shadow: none !important;
}

.test-save-action-btn:not(.disabled):active {
  transform: scale(0.99);
  opacity: 0.95;
}

.test-question-prompt .test-question-number {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #0a2518;
  letter-spacing: 0;
  text-transform: none;
  font-family: 'Playfair Display', Georgia, serif;
  line-height: 1.25;
}

.test-question-prompt .test-question-card-head {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eef0f2;
}

.test-question-prompt .test-question-text {
  font-size: 0.98rem;
  line-height: 1.65;
}

#test-flow-wrap .test-palette-panel {
  position: static !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
  display: block !important;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 14px 14px 0 0;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1;
  max-height: min(240px, 34vh);
  overflow-x: hidden;
  overflow-y: auto;
  color: #0a2518;
  box-sizing: border-box;
}

#test-flow-wrap .test-palette-panel[hidden] {
  display: none !important;
}

#test-flow-wrap.test-intro-open .test-flow-main,
#test-flow-wrap.test-intro-open .test-flow-left,
#test-flow-wrap.test-intro-open .test-flow-right,
#test-flow-wrap.test-intro-open .test-flow-action-wrap,
#test-flow-wrap.test-intro-open .test-flow-side-col,
#test-flow-wrap.test-intro-open .test-palette-panel,
#test-flow-wrap.test-intro-open .test-flow-rail-stats,
#test-flow-wrap.test-intro-open .test-flow-timer,
#test-flow-wrap.test-intro-open .test-flow-answered-pill,
#test-flow-wrap.test-intro-open .test-flow-meta-chips,
#test-flow-wrap.test-intro-open .test-intro-lang-label,
#test-flow-wrap.test-intro-open .test-intro-lang {
  display: none !important;
}

#test-flow-wrap.test-intro-open .test-flow-intro {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.test-q-status-strip {
  display: none !important;
}

@media (min-width: 1024px) {
  body.test-flow-active #test-flow-wrap.test-flow-wrap-v2 {
    display: grid;
    grid-template-columns: minmax(0, 4fr) minmax(0, 4fr) minmax(240px, 2fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "question options side";
    height: 100%;
    max-height: 100%;
    background: #eef1f3;
  }

  .test-flow-main {
    display: contents;
    overflow: visible;
    order: 0;
  }

  .test-flow-left {
    grid-area: question;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 22px 24px 20px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    min-height: 0;
  }

  .test-flow-right {
    grid-area: options;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #f8fafc;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .test-flow-options-scroll {
    flex: 1 1 auto;
    overflow: visible;
    padding: 22px 20px 12px;
  }

  .test-flow-action-wrap {
    flex: 0 0 auto;
    padding: 12px 20px 20px;
    background: #f8fafc;
    border-top: 1px solid #e8ecf0;
  }

  .test-flow-side-col {
    grid-area: side;
    order: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    background: #0a2518;
  }

  .test-flow-rail {
    order: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
    padding: 14px 12px;
    overflow: visible;
    background: #0a2518;
    flex: 0 0 auto;
  }

  .test-flow-rail-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .test-flow-rail .test-flow-title-block {
    display: block;
    min-width: 0;
  }

  .test-flow-rail .test-flow-title {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.2;
    color: #fff;
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 800;
  }

  .test-flow-rail .test-flow-date {
    margin: 4px 0 0;
    color: #d4af37;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .test-flow-rail-stats {
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .test-flow-rail .test-flow-timer,
  .test-flow-rail .test-flow-answered-pill {
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    justify-content: center;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.82rem;
  }

  .test-lang-full {
    display: inline;
  }

  .test-lang-short {
    display: none;
  }

  .test-flow-rail .test-flow-lang-toggle {
    width: 100%;
    padding: 4px;
    border-radius: 12px;
  }

  .test-flow-rail .test-lang-btn {
    flex: 1;
    padding: 8px 6px;
    font-size: 0.78rem;
  }

  .test-flow-rail .test-instructions-box {
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(201, 168, 76, 0.28);
    border-radius: 12px;
    overflow: hidden;
  }

  .test-flow-rail .test-instructions-box summary {
    padding: 9px 12px;
    font-size: 0.8rem;
  }

  .test-flow-rail .test-instructions-chevron {
    display: inline-block;
    color: rgba(245, 240, 230, 0.7);
  }

  .test-flow-rail .test-instructions-box ul {
    position: static;
    width: auto;
    box-shadow: none;
    border: none;
    border-radius: 0;
    background: transparent;
    color: rgba(245, 240, 230, 0.85);
    padding: 0 12px 12px 28px;
  }

  .test-flow-meta-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .test-flow-meta-chips .test-q-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
  }

  .test-flow-meta-chips .test-q-meta-chip {
    background: rgba(255, 255, 255, 0.1);
    color: #f5f0e6;
    border-color: rgba(255, 255, 255, 0.14);
    font-size: 0.62rem;
  }

  .test-flow-meta-chips .test-q-meta-chip.gs {
    background: rgba(201, 168, 76, 0.18);
    color: #c9a84c;
    border-color: rgba(201, 168, 76, 0.35);
  }

  .test-flow-meta-chips .test-q-meta-chip.diff-easy {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
  }

  .test-flow-meta-chips .test-q-meta-chip.diff-moderate,
  .test-flow-meta-chips .test-q-meta-chip.diff-medium {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
  }

  .test-flow-meta-chips .test-q-meta-chip.diff-hard {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
  }

  #test-flow-wrap .test-palette-panel {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    border-radius: 12px;
    margin: 0 10px 10px;
    width: auto;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: none;
    overflow-y: auto;
  }

  #test-flow-wrap .test-palette-head button {
    display: none;
  }

  #test-flow-wrap .test-palette-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .test-question-prompt .test-question-number {
    font-size: 1.28rem;
  }

  .test-question-prompt .test-question-text {
    font-size: 1.05rem;
  }

  .test-flow-wrap-v2 .test-options {
    max-width: none;
    margin: 0;
  }

  .test-save-action-btn {
    max-width: none;
  }

  body.test-flow-active #test-flow-wrap.test-flow-wrap-v2.test-intro-open {
    display: grid;
    grid-template-columns: minmax(0, 8fr) minmax(240px, 2fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "intro side";
  }

  #test-flow-wrap.test-intro-open .test-flow-intro {
    grid-area: intro;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f8fafc;
  }

  #test-flow-wrap.test-intro-open .test-flow-side-col {
    grid-area: side;
    display: flex !important;
  }

  #test-flow-wrap.test-intro-open .test-flow-rail {
    display: flex !important;
  }

  #test-flow-wrap.test-intro-open .test-palette-panel,
  #test-flow-wrap.test-intro-open .test-flow-left,
  #test-flow-wrap.test-intro-open .test-flow-right,
  #test-flow-wrap.test-intro-open .test-flow-action-wrap {
    display: none !important;
  }
}

@media (max-width: 1023px) {
  body.test-flow-active #test-flow-wrap.test-flow-wrap-v2 {
    display: flex;
    flex-direction: column;
  }

  .test-flow-side-col {
    display: contents;
  }

  .test-flow-rail {
    order: 0;
    flex-wrap: wrap;
  }

  .test-flow-main {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
  }

  #test-flow-wrap .test-palette-panel {
    order: 2;
    flex: 0 0 auto;
    border-radius: 14px 14px 0 0;
    max-height: min(220px, 32vh);
  }

  .test-flow-rail-top {
    order: 0;
    width: 100%;
  }

  .test-flow-rail-stats {
    display: contents;
    margin-left: 0;
  }

  .test-flow-rail .test-flow-timer {
    order: 1;
  }

  .test-flow-rail .test-flow-lang-toggle {
    order: 2;
  }

  .test-flow-rail .test-instructions-box {
    order: 3;
  }

  .test-flow-rail .test-flow-answered-pill {
    order: 4;
    margin-left: auto;
  }

  .test-flow-rail .test-flow-back-btn span {
    display: inline;
  }

  .test-instr-label {
    display: none;
  }

  .test-flow-rail .test-instructions-box summary span {
    display: inline-flex;
    align-items: center;
  }

  .test-flow-rail .test-instructions-box summary .fa-info-circle {
    margin: 0;
  }

  .test-flow-rail .test-instructions-box summary::after {
    content: 'Info';
    margin-left: 4px;
  }

  .test-flow-action-wrap {
    padding: 12px 14px 14px;
  }

  .test-save-action-btn {
    max-width: none;
  }
}
