/*
 * The exam hall: the rules page and the exam paper.
 * Built on site.css (its fonts, colours, buttons and toasts). One question at
 * a time on a white sheet; the answer sheet beside it, or as a drawer on a
 * phone; the clock always in view.
 */

.xm-body { min-height: 100vh; background: var(--ground); }
/* the page hides and shows its parts with the hidden attribute */
.xm-body [hidden] { display: none !important; }

/* ---- top bar ---------------------------------------------------------- */
.xm-top { position: sticky; top: 0; z-index: 40; background: #fff; border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.xm-top-row { max-width: 1320px; margin: 0 auto; padding: 10px 20px; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.xm-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 17px; }
.xm-brand:hover { color: var(--ink); }
.xm-top-title { color: var(--muted); font-size: 13.5px; }
.xm-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.xm-title .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.xm-title .brand-mark::after { top: 7px; right: 13px; }
.xm-title-text { min-width: 0; }
.xm-title h1 { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-title p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-pill { display: inline-block; border-radius: 999px; padding: 0 9px; font-size: 11.5px; font-weight: 700; margin-inline-start: 4px; }
.xm-pill-warn { background: var(--amber-soft); color: var(--amber); }

.xm-tools { display: flex; align-items: center; gap: 10px; flex: none; }
.xm-icon-btn { width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--ground); color: var(--ink-2); display: grid; place-items: center; cursor: pointer; }
.xm-icon-btn:hover { background: #e9edf2; }
.xm-finish { padding: 10px 18px; border-radius: 12px; }

/* saved / saving / not saved */
.xm-save { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); max-width: 240px; }
.xm-save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); flex: none; }
.xm-save[data-state="saving"] .xm-save-dot { background: var(--amber); animation: xm-pulse 1s ease-in-out infinite; }
.xm-save[data-state="error"], .xm-save[data-state="offline"] { color: var(--red); font-weight: 700; }
.xm-save[data-state="error"] .xm-save-dot, .xm-save[data-state="offline"] .xm-save-dot { background: var(--red); }

/* the clock */
.xm-timer { display: flex; align-items: center; gap: 8px; background: var(--ink); color: #fff; border-radius: 14px; padding: 7px 14px; transition: background .3s; }
.xm-timer-label { font-size: 12px; opacity: .72; }
.xm-timer-clock { direction: ltr; font-size: 20px; font-weight: 800; letter-spacing: .5px; min-width: 92px; text-align: center; }
.xm-timer.is-warn { background: var(--amber); }
.xm-timer.is-low { background: var(--red); animation: xm-pulse 1.4s ease-in-out infinite; }
.xm-timebar { height: 3px; background: var(--line); }
.xm-timebar span { display: block; height: 100%; width: 100%; background: var(--teal); transition: width 1s linear, background .3s; }
.time-low .xm-timebar span { background: var(--red); }
@keyframes xm-pulse { 50% { opacity: .55; } }

.xm-preview-note { max-width: 1320px; margin: 16px auto 0; padding: 10px 16px; border-radius: 12px; background: var(--amber-soft); color: #7a5414; font-size: 13.5px; width: calc(100% - 40px); }

/* ---- the hall: paper + answer sheet ----------------------------------- */
.xm-hall { max-width: 1320px; margin: 24px auto; padding-inline: 20px; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.xm-main { background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); padding: 28px 34px 22px; min-width: 0; }

.xm-q-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; padding-bottom: 16px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.xm-q-no { font-size: 15px; font-weight: 600; color: var(--muted); }
.xm-q-no b { font-size: 26px; font-weight: 800; color: var(--ink); margin-inline: 2px; }
.xm-q-no:focus { outline: none; }
.xm-q-lesson { background: var(--teal-soft); color: var(--teal-dark); font-size: 12.5px; font-weight: 700; border-radius: 999px; padding: 4px 12px; }
.xm-flag { margin-inline-start: auto; display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--muted); font-size: 13px; padding: 7px 12px; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.xm-flag:hover { border-color: #f0d79c; color: var(--amber); }
.xm-flag[aria-pressed="true"] { background: var(--amber-soft); border-color: #f0d79c; color: var(--amber); font-weight: 700; }
.xm-flag[aria-pressed="true"] svg { fill: currentColor; }

.xm-q-text { font-size: 17.5px; font-weight: 500; line-height: 2.15; margin-bottom: 24px; }
.xm-q-text p:last-child, .xm-option-text p:last-child { margin-bottom: 0; }
.xm-q-text img { border-radius: 10px; }

.xm-options { display: grid; gap: 12px; }
.xm-option { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; border: 1.5px solid var(--line); border-radius: 16px; background: #fff; padding: 13px 16px; cursor: pointer; transition: border-color .12s, background .12s, box-shadow .12s; }
.xm-option:hover { border-color: #b9e3d6; background: #fbfefd; }
.xm-option input { position: absolute; opacity: 0; pointer-events: none; }
.xm-key { width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 13.5px; font-weight: 800; color: var(--muted); transition: background .12s, color .12s, border-color .12s; }
.xm-option-text { font-size: 16px; line-height: 2; }
.xm-tick { color: var(--teal); opacity: 0; transition: opacity .12s; }
.xm-option:has(input:checked) { border-color: var(--teal); background: #effaf6; box-shadow: 0 0 0 3px rgba(19, 169, 131, .12); }
.xm-option:has(input:checked) .xm-key { background: var(--teal); border-color: var(--teal); color: #fff; }
.xm-option:has(input:checked) .xm-tick { opacity: 1; }
.xm-option:has(input:focus-visible) { outline: 3px solid rgba(19, 169, 131, .45); outline-offset: 2px; }
.xm-option:has(input:disabled) { cursor: default; }

.xm-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.xm-pager .btn { min-width: 150px; }
.xm-pager .btn:disabled { opacity: .45; cursor: default; box-shadow: none; }
.xm-clear { background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; padding: 8px; }
.xm-clear:hover { color: var(--red); }
.xm-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 0; }
.xm-hint kbd { font: inherit; font-size: 11.5px; background: var(--ground); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; }
@media (hover: none) { .xm-hint { display: none; } }

/* ---- answer sheet ----------------------------------------------------- */
.xm-sheet { position: sticky; top: 96px; background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); padding: 20px; max-height: calc(100vh - 120px); overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.xm-sheet-head { display: flex; align-items: center; justify-content: space-between; }
.xm-sheet-head h2 { font-size: 16px; font-weight: 800; }
.xm-sheet-close { display: none; }
.xm-progress-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.xm-progress-row b { color: var(--ink); }
.xm-progress-bar { height: 8px; border-radius: 99px; background: var(--ground); overflow: hidden; }
.xm-progress-bar span { display: block; height: 100%; width: 0; background: var(--teal); border-radius: inherit; transition: width .25s; }
.xm-sheet-groups { display: grid; gap: 16px; }
.xm-group h3 { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.xm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }

.xm-cell { position: relative; height: 38px; min-width: 38px; padding: 0; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink-2); font-size: 13px; font-weight: 700; display: inline-grid; place-items: center; cursor: pointer; transition: background .12s, border-color .12s; }
.xm-cell:hover { border-color: #b9e3d6; }
.xm-cell.is-answered { background: var(--teal); border-color: var(--teal); color: #fff; }
.xm-cell.is-flagged::after { content: ''; position: absolute; top: -4px; left: -4px; width: 11px; height: 11px; border-radius: 50%; background: var(--amber); border: 2px solid #fff; }
.xm-cell.is-current { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

.xm-legend { list-style: none; margin: 0; padding: 14px 0 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12px; color: var(--muted); }
.xm-legend li { display: flex; align-items: center; gap: 8px; }
.xm-legend .xm-cell { width: 18px; height: 18px; min-width: 0; border-radius: 6px; cursor: default; }
.xm-legend .xm-cell.is-flagged::after { width: 8px; height: 8px; top: -3px; left: -3px; }
.xm-legend .xm-cell.is-current { box-shadow: 0 0 0 1.5px var(--ink); }

.xm-backdrop { position: fixed; inset: 0; background: rgba(23, 32, 51, .45); z-index: 55; }
.xm-dock { display: none; }

/* ---- finish dialog and time-up ---------------------------------------- */
.xm-dialog { border: 0; border-radius: 22px; padding: 26px; max-width: 470px; width: calc(100% - 32px); box-shadow: 0 24px 60px rgba(23, 32, 51, .25); color: var(--ink); }
.xm-dialog::backdrop { background: rgba(23, 32, 51, .5); }
.xm-dialog h2 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.xm-dialog > .muted { font-size: 13.5px; margin-bottom: 16px; }
.xm-summary { list-style: none; margin: 0 0 6px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.xm-summary li { background: var(--ground); border-radius: 14px; padding: 12px 8px; text-align: center; }
.xm-summary b { display: block; font-size: 24px; font-weight: 800; line-height: 1.4; }
.xm-summary span { font-size: 12.5px; color: var(--muted); }
.xm-summary .is-ok b { color: var(--teal-dark); }
.xm-summary .is-flag b { color: var(--amber); }
.xm-jump { display: flex; flex-wrap: wrap; gap: 6px; }
.xm-jump:empty { display: none; }
.xm-jump p { width: 100%; margin: 10px 0 0; font-size: 13px; font-weight: 700; }
.xm-jump .xm-cell { width: 38px; }
.xm-dialog-time { font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.xm-dialog-time b { color: var(--ink); direction: ltr; display: inline-block; }
.xm-dialog-actions { display: flex; gap: 10px; margin-top: 18px; }
.xm-dialog-actions .btn { flex: 1; }

.xm-timeup { position: fixed; inset: 0; z-index: 100; background: rgba(23, 32, 51, .72); display: grid; place-items: center; padding: 16px; }
.xm-timeup > div { background: #fff; border-radius: 22px; padding: 32px 28px; text-align: center; max-width: 360px; }
.xm-timeup svg { color: var(--red); }
.xm-timeup h2 { font-size: 19px; font-weight: 800; margin: 10px 0 6px; }
.xm-timeup p { color: var(--muted); margin: 0; }

.toast-warn { background: var(--amber); }

/* ---- rules page ------------------------------------------------------- */
.xm-intro { max-width: 980px; margin: 32px auto; padding-inline: 20px; }
.xm-intro-card { background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); padding: 32px 36px; }
.xm-intro-head { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.xm-eyebrow { color: var(--teal-dark); font-size: 13px; font-weight: 700; margin: 0 0 4px; }
.xm-intro h1 { font-size: 24px; font-weight: 800; }
.xm-candidate { display: flex; flex-wrap: wrap; gap: 10px 32px; margin: 16px 0 0; }
.xm-candidate dt { font-size: 12px; color: var(--muted); }
.xm-candidate dd { margin: 0; font-size: 15px; font-weight: 700; }
.xm-facts { list-style: none; margin: 24px 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.xm-facts li { background: var(--ground); border-radius: 16px; padding: 16px 10px; text-align: center; }
.xm-facts b { display: block; font-size: 26px; font-weight: 800; line-height: 1.5; }
.xm-facts span { font-size: 13px; color: var(--muted); }
.xm-facts .is-warn { background: var(--amber-soft); }
.xm-facts .is-warn b { color: var(--amber); }
.xm-intro-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 32px; }
.xm-intro-grid h2 { font-size: 16px; font-weight: 800; margin-bottom: 10px; }
.xm-lessons { width: 100%; border-collapse: collapse; font-size: 14px; }
.xm-lessons th { text-align: right; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.xm-lessons td { padding: 10px; border-bottom: 1px solid var(--line); }
.xm-lessons tr:last-child td { border-bottom: 0; }
.xm-rules { margin: 0; padding-inline-start: 22px; list-style-type: persian; font-size: 14px; line-height: 2; }
.xm-rules li { margin-bottom: 6px; }
.xm-rules li::marker { color: var(--teal); font-weight: 800; }
.xm-intro-start { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; }
.xm-agree { display: flex; align-items: center; gap: 10px; font-size: 14.5px; font-weight: 600; cursor: pointer; }
.xm-agree input { width: 20px; height: 20px; accent-color: var(--teal); flex: none; }
.xm-intro-actions { display: flex; gap: 10px; }
.xm-intro-actions .btn-primary { min-width: 180px; }
.xm-intro-actions .btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ---- tablets and phones ----------------------------------------------- */
@media (max-width: 1100px) {
    .xm-hall { grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; }
    .xm-save-text { display: none; }
    .xm-save[data-state="error"] .xm-save-text, .xm-save[data-state="offline"] .xm-save-text { display: inline; }
}

@media (max-width: 960px) {
    .xm-hall { grid-template-columns: minmax(0, 1fr); margin: 14px auto; padding-inline: 12px; padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
    .xm-main { padding: 20px 18px; border-radius: 18px; }
    .xm-pager #prev-btn, .xm-pager #next-btn { display: none; }
    .xm-pager { justify-content: center; margin-top: 18px; padding-top: 12px; }
    .xm-pager:not(:has(.xm-clear:not([hidden]))) { display: none; }

    .xm-sheet { position: fixed; inset: auto 0 0 0; top: auto; z-index: 60; max-height: 82vh; border-radius: 22px 22px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateY(105%); transition: transform .25s ease; visibility: hidden; }
    .sheet-open .xm-sheet { transform: none; visibility: visible; }
    .sheet-open { overflow: hidden; }
    .xm-sheet-close { display: grid; }
    .xm-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
    .xm-cell { height: 42px; }

    .xm-dock { display: flex; gap: 10px; position: fixed; inset: auto 0 0 0; z-index: 50; background: #fff; border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
    .xm-dock-btn { width: 52px; height: 48px; flex: none; border: 0; border-radius: 14px; background: var(--ground); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
    .xm-dock-btn:disabled { opacity: .4; }
    .xm-dock-btn.is-next { background: var(--teal); color: #fff; }
    .xm-dock-btn.is-next.is-last { background: var(--ink); }
    .xm-dock-sheet { flex: 1; height: 48px; border: 0; border-radius: 14px; background: var(--ground); color: var(--ink); font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
    .xm-dock-sheet .num { color: var(--muted); font-weight: 600; }
    .toast { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

    .xm-intro-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; }
}

@media (max-width: 720px) {
    .xm-top-row { padding: 8px 12px; min-height: 60px; gap: 10px; }
    .xm-title .brand-mark, .xm-title .brand-logo { display: none; }
    .xm-title h1 { font-size: 14px; }
    .xm-who { display: none; }
    .xm-tools { gap: 8px; }
    .xm-timer { padding: 6px 10px; gap: 6px; border-radius: 12px; }
    .xm-timer svg, .xm-timer-label, #fullscreen-btn { display: none; }
    .xm-timer-clock { font-size: 17px; min-width: 78px; }
    .xm-finish { padding: 9px 12px; font-size: 13px; }
    .xm-save { position: absolute; top: 100%; right: 12px; margin-top: 6px; }
    .xm-save[data-state="saved"], .xm-save[data-state="saving"] { display: none; }
    .xm-save[data-state="error"], .xm-save[data-state="offline"] { background: var(--red-soft); padding: 4px 10px; border-radius: 10px; }

    .xm-q-head { margin-bottom: 16px; padding-bottom: 12px; }
    .xm-q-no b { font-size: 22px; }
    .xm-flag span { display: none; }
    .xm-flag { padding: 8px; }
    .xm-q-text { font-size: 16.5px; margin-bottom: 18px; }
    .xm-option { padding: 11px 12px; gap: 10px; border-radius: 14px; }
    .xm-key { width: 32px; height: 32px; font-size: 12.5px; }
    .xm-option-text { font-size: 15.5px; }

    .xm-intro { margin: 14px auto; padding-inline: 12px; }
    .xm-intro-card { padding: 22px 18px; border-radius: 20px; }
    .xm-intro h1 { font-size: 20px; }
    .xm-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .xm-intro-actions { width: 100%; }
    .xm-intro-actions .btn { flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .xm-timer.is-low, .xm-save-dot { animation: none !important; }
    .xm-sheet, .xm-timebar span { transition: none; }
}

@media print { .xm-body:not(.cert-body) { display: none; } }
