* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh; padding: 20px; color: #2d3748; line-height: 1.5;
}
.container { max-width: 1100px; margin: 0 auto; background: #fff;
  border-radius: 16px; box-shadow: 0 25px 70px rgba(0,0,0,.25); padding: 36px; }
.loading { text-align:center; padding:60px; color:#a0aec0; }
h1 { font-size: 28px; margin-bottom: 8px; color: #1a202c; }
h2 { font-size: 20px; margin-bottom: 16px; color: #2d3748; }
h3 { font-size: 16px; margin-bottom: 12px; color: #4a5568; }
p { margin-bottom: 12px; }
.subtitle { color: #718096; margin-bottom: 24px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 12px 14px; border: 2px solid #e2e8f0;
  border-radius: 8px; font-size: 15px; font-family: inherit;
  transition: border-color .2s; background:#fff; }
input:focus, textarea:focus, select:focus { outline: none; border-color: #667eea; }
textarea { min-height: 280px; font-family: Consolas, Monaco, monospace; font-size: 13px; resize: vertical; }
button { padding: 11px 22px; border: none; border-radius: 8px; background: #e2e8f0;
  color: #2d3748; font-size: 15px; font-weight: 500; cursor: pointer;
  transition: all .15s; font-family: inherit; }
button:hover:not(:disabled) { background: #cbd5e0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: #667eea; color: #fff; }
button.primary:hover:not(:disabled) { background: #5568d3; }
button.danger { background: #f56565; color: #fff; }
button.danger:hover:not(:disabled) { background: #e53e3e; }
button.success { background: #48bb78; color: #fff; }
button.success:hover:not(:disabled) { background: #38a169; }
button.small { padding: 7px 14px; font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; color: #4a5568; font-weight: 500; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } }
#accessCode { font-family: Consolas, Monaco, monospace; text-transform: uppercase; }
#accessCode::placeholder { color: #cbd5e0; letter-spacing: 3px; }
.quiz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.quiz-card { border: 2px solid #e2e8f0; border-radius: 12px; padding: 20px;
  cursor: pointer; transition: all .15s; background: #fff; }
.quiz-card:hover { border-color: #667eea; box-shadow: 0 8px 24px rgba(102,126,234,.15); transform: translateY(-2px); }
.quiz-card-title { font-size: 17px; font-weight: 600; color: #1a202c; margin-bottom: 8px; }
.quiz-card-desc { font-size: 13px; color: #718096; margin-bottom: 12px; }
.quiz-card-meta { display: flex; gap: 16px; font-size: 13px; color: #4a5568; flex-wrap: wrap; }
.option { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  border: 2px solid #e2e8f0; border-radius: 10px; margin-bottom: 10px;
  cursor: pointer; transition: all .15s; }
.option:hover { border-color: #a3bffa; background: #f7fafc; }
.option input { margin-top: 3px; transform: scale(1.2); cursor: pointer; }
.option:has(input:checked) { border-color: #667eea; background: #ebf0ff; }
.numeric-wrap { padding: 12px 0 4px; max-width: 420px; margin: 0 auto; }
.numeric-input { width: 100%; padding: 20px 24px; font-size: 28px; font-weight: 700;
  text-align: center; letter-spacing: 1px; border: 3px solid #e2e8f0;
  border-radius: 12px; font-family: inherit; color: #1a202c;
  background: #fff; transition: border-color .2s, background .2s; }
.numeric-input:focus { outline: none; border-color: #667eea; background: #f7faff; }
.numeric-input::placeholder { color: #cbd5e0; font-weight: 400; }
@media (max-width: 600px) { .numeric-input { font-size: 22px; padding: 16px 18px; } }
.progress { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin-bottom: 24px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #667eea, #764ba2); transition: width .3s; }
.test-header { display: flex; justify-content: space-between; margin-bottom: 12px;
  font-size: 14px; color: #718096; font-weight: 500; gap: 12px; flex-wrap: wrap; }
.timer { color: #667eea; font-weight: 700; }
.timer.warning { color: #e53e3e; }
.leave-badge { display: inline-flex; align-items: center; gap: 6px; background: #fed7d7;
  color: #742a2a; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.leave-badge.ok { background: #c6f6d5; color: #22543d; }
.hint { font-size: 13px; color: #718096; margin-bottom: 16px; font-style: italic; }
.nav { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.nav button { flex: 1; min-width: 120px; }
.result-card { text-align: center; padding: 20px; }
.score-circle { width: 170px; height: 170px; border-radius: 50%; margin: 0 auto 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; background: linear-gradient(135deg, #667eea, #764ba2);
  box-shadow: 0 15px 35px rgba(102,126,234,.4); }
.score-circle.pass { background: linear-gradient(135deg, #48bb78, #38a169); box-shadow: 0 15px 35px rgba(72,187,120,.4); }
.score-circle.fail { background: linear-gradient(135deg, #f56565, #e53e3e); box-shadow: 0 15px 35px rgba(245,101,101,.4); }
.score-circle .pct { font-size: 40px; line-height: 1; }
.score-circle .label { font-size: 13px; opacity: .9; font-weight: 500; margin-top: 6px; }
.stats { display: flex; justify-content: center; gap: 30px; margin-bottom: 24px; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .value { font-size: 24px; font-weight: 700; color: #2d3748; }
.stat .value.warn { color: #e53e3e; }
.stat .lbl { font-size: 12px; color: #718096; text-transform: uppercase; letter-spacing: .5px; }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 22px; border-bottom: 2px solid #e2e8f0; flex-wrap: wrap; }
.admin-tabs button { background: transparent; border-radius: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; color: #718096; padding: 10px 16px; }
.admin-tabs button.active { color: #667eea; border-bottom-color: #667eea; background: transparent; }
.sub-tabs { display: flex; gap: 6px; margin-bottom: 18px; background: #f7fafc; padding: 4px; border-radius: 10px; }
.sub-tabs button { flex: 1; background: transparent; color: #718096; border-radius: 8px; padding: 9px 14px; font-size: 14px; }
.sub-tabs button.active { background: #fff; color: #667eea; box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.sub-tabs button:hover:not(.active) { background: #edf2f7; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; }
th { background: #f7fafc; font-weight: 600; color: #4a5568; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
tr:hover td { background: #f7fafc; }
.table-wrap { max-height: 480px; overflow: auto; border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 16px; }
.empty { text-align: center; padding: 40px; color: #a0aec0; }
.actions { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items:center; }
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.pass { background: #c6f6d5; color: #22543d; }
.badge.fail { background: #fed7d7; color: #742a2a; }
.badge.online { background: #c6f6d5; color: #22543d; }
.badge.away { background: #feebc8; color: #7b341e; }
.badge.idle { background: #e2e8f0; color: #4a5568; }
.badge.abandoned { background: #fed7d7; color: #742a2a; }
.badge[onclick] { transition: all .15s; user-select: none; cursor: pointer; }
.badge[onclick]:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert.error { background: #fed7d7; color: #742a2a; border-left: 4px solid #f56565; }
.alert.success { background: #c6f6d5; color: #22543d; border-left: 4px solid #48bb78; }
.alert.info { background: #bee3f8; color: #2a4365; border-left: 4px solid #4299e1; }
.alert.warn { background: #feebc8; color: #7b341e; border-left: 4px solid #ed8936; }
.footer-links { margin-top: 24px; text-align: center; font-size: 13px; color: #a0aec0; }
.footer-links a { color: #667eea; text-decoration: none; margin: 0 8px; cursor: pointer; }
.footer-links a:hover { text-decoration: underline; }
.info-box { background: #f7fafc; border-radius: 10px; padding: 18px; margin-bottom: 20px; font-size: 14px; }
.info-box b { color: #2d3748; }
.info-box code { background: #edf2f7; padding: 1px 6px; border-radius: 4px; font-family: Consolas, monospace; font-size: 12.5px; }
.mini-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; min-width: 90px; }
.mini-bar > div { height: 100%; background: #667eea; transition: width .3s; }
.leave-list { font-size: 12.5px; color: #4a5568; padding: 6px 0; }
.leave-list li { margin-left: 18px; margin-bottom: 3px; }
.analytics-card { background: #f7fafc; padding: 16px; border-radius: 10px; border: 1px solid #e2e8f0; }
.analytics-card h3 { font-size: 14px; margin-bottom: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.75); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 20px; }
.overlay-card { background: #fff; border-radius: 16px; padding: 32px; max-width: 460px; width: 100%; text-align: center; box-shadow: 0 25px 70px rgba(0,0,0,.4); animation: popIn .25s ease-out; }
@keyframes popIn { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.overlay-icon { font-size: 56px; margin-bottom: 12px; }
.overlay-card h2 { color: #e53e3e; margin-bottom: 12px; }
.overlay-count { font-size: 18px; margin: 18px 0 !important; }
.overlay-count b { color: #e53e3e; font-size: 22px; }
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: 10px; color:#fff; font-size:14px; z-index:10000; box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: popIn .2s; }
.toast.error { background:#e53e3e; }
.toast.success { background:#38a169; }
.toast.info { background:#4299e1; }
.toast.warn { background:#ed8936; }
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.7); display: flex; align-items: flex-start; justify-content: center; z-index: 10000; padding: 40px 20px; overflow-y: auto; }
.modal-card { background: #fff; border-radius: 16px; padding: 30px; max-width: 1100px; width: 100%; box-shadow: 0 25px 70px rgba(0,0,0,.4); position: relative; animation: popIn .2s ease-out; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%; background: #edf2f7; color: #4a5568; font-size: 22px; line-height: 1; padding: 0; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: #e2e8f0; }
.proto-ok { background: #f0fff4; }
.proto-ok td { border-bottom-color: #c6f6d5; }
.proto-fail { background: #fff5f5; }
.proto-fail td { border-bottom-color: #fed7d7; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { border: 2px solid #e2e8f0; border-radius: 12px; padding: 20px;
  cursor: pointer; transition: all .15s; background: #fff; position: relative; }
.tile:hover { border-color: #667eea; box-shadow: 0 8px 24px rgba(102,126,234,.15); transform: translateY(-2px); }
.tile-icon { font-size: 32px; margin-bottom: 10px; line-height: 1; }
.tile-subject .tile-icon { font-size: 36px; }
.tile-grade .tile-icon { width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.tile-title { font-size: 16px; font-weight: 600; color: #1a202c; margin-bottom: 6px; line-height: 1.3; }
.tile-meta { font-size: 13px; color: #718096; margin-bottom: 10px; }
.tile-grades { display: flex; flex-wrap: wrap; gap: 4px; }
.grade-chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #edf2f7; color: #4a5568; font-size: 11px; font-weight: 600; }
.tile-archived { opacity: .65; background: #f7fafc; }
.tile-archived:hover { opacity: 1; }
.breadcrumbs { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #f7fafc; border-radius: 8px; margin-bottom: 18px; font-size: 14px; flex-wrap: wrap; }
.breadcrumbs a { color: #667eea; text-decoration: none; cursor: pointer; font-weight: 500; }
.breadcrumbs a:hover { text-decoration: underline; }
.bc-sep { color: #cbd5e0; }
.bc-current { color: #2d3748; font-weight: 600; }
@media (max-width: 700px) { .modal-card { padding: 18px; } .sub-tabs { flex-direction: column; } }
@media (max-width: 600px) { .container { padding: 22px; } h1 { font-size: 22px; } .nav button { flex: 1 1 100%; } }

/* ============ PROMPT GENERATOR (admin) ============ */
.pg-wrap{display:grid;grid-template-columns:1fr 1fr;gap:18px;align-items:start}
@media (max-width:1100px){.pg-wrap{grid-template-columns:1fr}}
.pg-panel{background:#fff;border-radius:14px;padding:18px 22px;
          border:1px solid #e2e8f0;max-height:calc(100vh - 260px);overflow-y:auto}
@media (max-width:1100px){.pg-panel{max-height:none}}
.pg-panel h3{font-size:15px;color:#1a202c;margin:20px 0 10px;
             padding-bottom:6px;border-bottom:2px solid #e2e8f0;
             display:flex;align-items:center;gap:8px}
.pg-panel h3:first-child{margin-top:0}
.pg-panel h3 .num{width:24px;height:24px;border-radius:50%;
                  background:linear-gradient(135deg,#667eea,#764ba2);color:#fff;
                  display:flex;align-items:center;justify-content:center;
                  font-weight:700;font-size:12px;flex-shrink:0}
.pg-field{margin-bottom:10px}
.pg-field label{display:block;margin-bottom:4px;font-size:12.5px;
                color:#4a5568;font-weight:600}
.pg-field label .hint{color:#a0aec0;font-weight:400;font-size:11.5px}
.pg-field input,.pg-field select,.pg-field textarea{
  width:100%;padding:8px 11px;border:2px solid #e2e8f0;
  border-radius:7px;font-size:13.5px;font-family:inherit;transition:.15s}
.pg-field input:focus,.pg-field select:focus,.pg-field textarea:focus{
  outline:none;border-color:#667eea}
.pg-field textarea{min-height:60px;resize:vertical;font-size:13px;line-height:1.5}
.pg-row{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.pg-row-3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px}
@media (max-width:600px){.pg-row,.pg-row-3{grid-template-columns:1fr}}
.pg-checks{display:flex;flex-wrap:wrap;gap:6px;margin:4px 0 10px}
.pg-checks label{display:flex;align-items:center;gap:5px;
                 padding:5px 10px;border:2px solid #e2e8f0;border-radius:7px;
                 font-size:12.5px;cursor:pointer;background:#fff;transition:.15s;
                 font-weight:500;user-select:none}
.pg-checks label:hover{border-color:#a3bffa;background:#f7fafc}
.pg-checks input{accent-color:#667eea;cursor:pointer}
.pg-checks input:checked ~ span{color:#667eea;font-weight:600}
.pg-section-row{background:#fafbfc;border:2px solid #e2e8f0;border-radius:9px;
                padding:10px 12px;margin-bottom:8px;
                display:grid;grid-template-columns:1fr 80px 28px;gap:8px;align-items:center}
.pg-section-row input{padding:6px 9px;border:2px solid #e2e8f0;
                      border-radius:6px;font-size:13px;font-family:inherit}
.pg-section-row input:focus{outline:none;border-color:#667eea}
.pg-section-row .rm{padding:0;width:28px;height:28px;border-radius:6px;
                    background:#fed7d7;color:#c53030;font-size:15px;font-weight:700;
                    display:flex;align-items:center;justify-content:center;
                    cursor:pointer;border:none}
.pg-section-row .rm:hover{background:#feb2b2}
#pgOutput{width:100%;min-height:400px;padding:12px 14px;
          background:#1a202c;color:#e2e8f0;border:none;border-radius:9px;
          font-family:Consolas,Monaco,monospace;font-size:12px;
          line-height:1.55;resize:vertical;white-space:pre-wrap}
#pgOutput:focus{outline:none}
.pg-stats{display:flex;gap:14px;flex-wrap:wrap;padding:8px 12px;
          background:#ebf0ff;border-radius:9px;margin:8px 0;font-size:12.5px}
.pg-stats b{color:#667eea;font-size:13.5px}
.pg-banner{margin-top:10px;padding:10px 14px;border-radius:9px;
           font-size:13px;display:none;border-left:4px solid}
.pg-banner.show{display:block}
.pg-banner.ok{background:#c6f6d5;border-color:#48bb78;color:#22543d}
.pg-banner.warn{background:#feebc8;border-color:#ed8936;color:#7b341e}
.pg-banner.err{background:#fed7d7;border-color:#f56565;color:#742a2a}
.pg-banner ul{margin:5px 0 0 18px}
.pg-banner li{margin-bottom:2px}
#pgJsonPaste{width:100%;min-height:150px;padding:12px 14px;
             border:2px solid #e2e8f0;border-radius:9px;
             font-family:Consolas,Monaco,monospace;font-size:12px;
             line-height:1.55;resize:vertical;background:#fafbfc}
#pgJsonPaste:focus{outline:none;border-color:#667eea;background:#fff}
.pg-viewer{margin-top:14px;display:none}
.pg-viewer.show{display:block}
.pg-viewer-stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));
                 gap:8px;margin-bottom:14px}
.pg-viewer-stat{background:#ebf0ff;border-radius:9px;padding:10px 12px;text-align:center}
.pg-viewer-stat .v{font-size:20px;font-weight:700;color:#667eea;line-height:1.2}
.pg-viewer-stat .l{font-size:10.5px;color:#718096;text-transform:uppercase;
                   letter-spacing:.3px;margin-top:3px}
.pg-viewer-section{background:#f7fafc;border-left:4px solid #667eea;
                   border-radius:9px;padding:14px 16px;margin-bottom:12px}
.pg-viewer-section h4{font-size:14px;color:#1a202c;margin-bottom:8px;
                      display:flex;justify-content:space-between;align-items:center;
                      gap:10px;flex-wrap:wrap}
.pg-viewer-section h4 .meta{font-size:12px;color:#718096;font-weight:500}
.pg-viewer-q{background:#fff;border:1px solid #e2e8f0;border-radius:8px;
             padding:10px 12px;margin-bottom:6px;font-size:13px}
.pg-viewer-q .qhead{display:flex;gap:8px;align-items:flex-start;margin-bottom:6px}
.pg-viewer-q .qnum{font-weight:700;color:#667eea;flex-shrink:0;min-width:22px}
.pg-viewer-q .qtext{flex:1;line-height:1.4;font-weight:500}
.pg-viewer-q .qbadge{background:#ebf0ff;color:#667eea;font-size:10px;
                     font-weight:700;padding:2px 6px;border-radius:4px;
                     text-transform:uppercase;letter-spacing:.3px;flex-shrink:0}
.pg-viewer-q .qbadge.multiple{background:#e9d8fd;color:#6b46c1}
.pg-viewer-q .qbadge.numeric{background:#feebc8;color:#7b341e}
.pg-viewer-opts{margin-left:28px;font-size:12.5px}
.pg-viewer-opt{padding:2px 0;color:#4a5568;line-height:1.4}
.pg-viewer-opt.correct{color:#22543d;font-weight:600}
.pg-viewer-opt.correct::before{content:'✓ ';color:#48bb78;font-weight:700}
.pg-viewer-opt:not(.correct)::before{content:'○ ';color:#cbd5e0}
.pg-viewer-errors{background:#fed7d7;border-left:4px solid #f56565;
                  border-radius:8px;padding:12px 16px;margin-bottom:12px;
                  color:#742a2a;font-size:13px}
.pg-viewer-errors ul{margin:6px 0 0 20px}
.pg-viewer-errors li{margin-bottom:3px}
.pg-viewer-ok{background:#c6f6d5;border-left:4px solid #48bb78;
              border-radius:8px;padding:12px 16px;margin-bottom:12px;
              color:#22543d;font-size:13px}
.pg-dist{background:#fff;border:1px solid #e2e8f0;border-radius:9px;
         padding:12px 16px;margin-bottom:12px}
.pg-dist h5{font-size:11.5px;color:#718096;text-transform:uppercase;
            letter-spacing:.4px;margin-bottom:8px}
.pg-dist-row{display:flex;align-items:center;gap:8px;margin-bottom:5px;font-size:12px}
.pg-dist-row .lbl{min-width:70px;color:#2d3748}
.pg-dist-row .bar{flex:1;height:9px;background:#edf2f7;border-radius:5px;overflow:hidden}
.pg-dist-row .bar > div{height:100%;background:linear-gradient(90deg,#667eea,#764ba2);transition:width .3s}
.pg-dist-row .num{min-width:65px;text-align:right;font-weight:600;color:#667eea}
.pg-mini{padding:3px 8px;font-size:11px;border-radius:5px;background:#ebf0ff;
         color:#667eea;font-weight:600;border:none;cursor:pointer}
.pg-mini:hover{background:#d6e0ff}
/* ============ /PROMPT GENERATOR ============ */

/* ============ VISUAL CONTENT ============ */
.q-image{margin:14px 0;text-align:center}
.q-image img{max-width:100%;height:auto;border-radius:8px;
             border:1px solid #e2e8f0;background:#fff;display:inline-block}
.q-table{margin:14px 0;overflow-x:auto}
.q-table table{width:auto;max-width:100%;margin:0 auto;
               border-collapse:collapse;font-size:14px;
               border:2px solid #cbd5e0;border-radius:6px;overflow:hidden}
.q-table caption{caption-side:top;padding:6px 10px;font-size:13px;color:#4a5568;
                 font-style:italic;text-align:center}
.q-table th,.q-table td{border:1px solid #cbd5e0;padding:8px 14px;text-align:center}
.q-table th{background:#edf2f7;font-weight:700;color:#2d3748}
.q-table tr:nth-child(even) td{background:#f7fafc}
.q-html{margin:12px 0;font-size:15px;line-height:1.65;color:#2d3748;
        background:#f7fafc;border-left:3px solid #667eea;
        padding:12px 16px;border-radius:0 8px 8px 0}
.q-html pre{background:#1a202c;color:#e2e8f0;padding:12px 16px;border-radius:8px;
            overflow-x:auto;font-family:Consolas,monospace;font-size:13px;
            margin:8px 0;white-space:pre}
.q-html code{background:#edf2f7;padding:2px 6px;border-radius:4px;
             font-family:Consolas,monospace;font-size:13px;color:#c53030}
.q-html pre code{background:none;color:inherit;padding:0}
.q-html mark{background:#fefcbf;padding:1px 4px;border-radius:2px}
.q-html sup,.q-html sub{font-size:.75em;line-height:0}

/* ============ GRAPH RENDERING ============ */
.q-graph{margin:16px 0;padding:12px;background:#fff;
         border:1px solid #e2e8f0;border-radius:10px;
         display:flex;justify-content:center;overflow-x:auto}
.q-graph svg{max-width:100%;height:auto;display:block}
@media (max-width:600px){
  .q-graph{padding:6px;border-radius:6px}
}

/* ============ DRAWING (pen + eraser) ============ */
.q-visual-wrap{position:relative}
.q-drawing-canvas{
  position:absolute;
  top:0;left:0;
  width:100%;height:100%;
  touch-action:none;
  cursor:crosshair;
  z-index:5;
  border-radius:10px;
}
.q-drawing-toolbar{
  position:absolute;
  top:8px;right:8px;
  display:flex;gap:4px;
  background:rgba(255,255,255,.96);
  border-radius:10px;
  padding:4px;
  box-shadow:0 2px 10px rgba(0,0,0,.15);
  z-index:10;
}
.q-draw-btn{
  width:34px;height:34px;
  padding:0;border:none;border-radius:7px;
  background:transparent;
  cursor:pointer;
  font-size:16px;
  display:flex;align-items:center;justify-content:center;
  transition:.15s;
  font-family:inherit;
}
.q-draw-btn:hover{background:#edf2f7}
.q-draw-btn.active{
  background:#ebf0ff;
  box-shadow:inset 0 0 0 2px #667eea;
}
@media (max-width:600px){
  .q-draw-btn{width:30px;height:30px;font-size:15px}
  .q-drawing-toolbar{top:6px;right:6px;padding:3px}
}
/* ============ /DRAWING ============ */

/* ============ GAMES ============ */
.games-block{margin-top:36px;padding-top:24px;border-top:1px dashed #e2e8f0}
.games-block h2{color:#805ad5;margin-bottom:16px;font-size:18px;
                display:flex;align-items:center;gap:8px}
.game-card{position:relative;overflow:hidden}
.game-card .game-icon{font-size:36px;margin-bottom:8px;line-height:1}
.game-card:hover{border-color:#805ad5;
                 box-shadow:0 8px 24px rgba(128,90,213,.15)}
.admin-games-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));
                  gap:14px;margin-top:12px}
.admin-game-card{background:#fff;border:2px solid #e2e8f0;
                 border-radius:12px;padding:16px}
.admin-game-card.off{opacity:.55}
.admin-game-card h4{margin:0 0 6px;font-size:15px;color:#1a202c}
.admin-game-card .meta{font-size:12.5px;color:#718096;margin-bottom:8px}
.admin-game-card .actions-inline{display:flex;gap:6px;flex-wrap:wrap}
.admin-game-card .actions-inline button{flex:1;min-width:100px}
button.purple{background:#805ad5;color:#fff}
button.purple:hover:not(:disabled){background:#6b46c1}
/* ============ /GAMES ============ */

/* ============ PREVIEW MODE ============ */
.preview-banner{background:linear-gradient(135deg,#805ad5,#b14aff);color:#fff;
                padding:12px 18px;border-radius:12px;margin-bottom:14px;
                display:flex;justify-content:space-between;align-items:center;
                gap:12px;flex-wrap:wrap;font-weight:600;font-size:14px;
                box-shadow:0 4px 14px rgba(128,90,213,.35);
                animation:previewPulse 2.5s ease-in-out infinite}
@keyframes previewPulse{0%,100%{box-shadow:0 4px 14px rgba(128,90,213,.35)}
  50%{box-shadow:0 4px 22px rgba(128,90,213,.7)}}
.preview-banner .preview-actions button{
  background:rgba(255,255,255,.2);color:#fff;border:none;font-weight:600}
.preview-banner .preview-actions button:hover{background:rgba(255,255,255,.35)}

.preview-filters{display:flex;gap:14px;flex-wrap:wrap;align-items:center;
                 padding:12px 18px;background:#f7fafc;border-radius:10px;
                 margin-bottom:20px;border:1px solid #e2e8f0}
.preview-filters label{display:flex;align-items:center;gap:8px;
                       font-size:13.5px;color:#4a5568;font-weight:600}
.preview-filters select{padding:7px 10px;border:2px solid #e2e8f0;
                        border-radius:7px;font-size:13.5px;font-family:inherit;
                        background:#fff;min-width:120px}
.preview-filters select:focus{outline:none;border-color:#805ad5}
.preview-count{margin-left:auto;font-size:13px;color:#718096}
.preview-grade{font-size:20px;color:#1a202c;margin:24px 0 14px;
               padding-bottom:8px;border-bottom:2px solid #e2e8f0}
.preview-subject{font-size:15px;color:#805ad5;margin:16px 0 10px;
                 text-transform:uppercase;letter-spacing:.5px}
/* ============ /PREVIEW MODE ============ */

/* ============ MOBILE OPTIMIZATION ============ */

/* 1. Убираем автозум iOS — все поля ввода ≥ 16px */
@media (max-width: 768px) {
  input[type=text], input[type=password], input[type=email],
  input[type=number], input[type=tel], input[type=search],
  textarea, select {
    font-size: 16px !important;
  }
}

/* 2. Тач-таргеты минимум 44×44 на сенсорных экранах */
@media (hover: none) and (pointer: coarse) {
  button, .badge[onclick], .tile, .quiz-card, .option, .admin-tabs button,
  .match-item, .drag-item, .letter-tile, .tt-chip {
    min-height: 44px;
  }
  button.small {
    min-height: 38px;
    padding: 9px 14px;
  }
  button, .option, .tile, .quiz-card { touch-action: manipulation; }
}

/* 3. Контейнер на весь экран телефона */
@media (max-width: 640px) {
  body { padding: 0; background: #fff; }
  .container {
    border-radius: 0;
    box-shadow: none;
    padding: 16px 14px 40px;
    min-height: 100vh;
    min-height: 100dvh;
  }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; margin-bottom: 12px; }
  h3 { font-size: 15px; }
  .subtitle { font-size: 13.5px; margin-bottom: 18px; }

  .field { margin-bottom: 12px; }
  .field label { font-size: 13px; }

  /* Кнопки — растягиваются */
  .actions { gap: 8px; }
  .actions > button:not(.small) { flex: 1 1 auto; }

  /* Сетки: тесты — 1 колонка, плитки — 2 в ряд */
  .quiz-grid { grid-template-columns: 1fr; gap: 12px; }
  .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 14px; }
  .tile-icon { font-size: 26px; margin-bottom: 6px; }
  .tile-title { font-size: 14px; line-height: 1.3; }
  .tile-meta { font-size: 12px; }

  /* Админ-табы: горизонтальный скролл */
  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tabs button {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
    padding: 9px 12px;
  }
  .sub-tabs { flex-direction: row; overflow-x: auto; }
  .sub-tabs button { white-space: nowrap; flex-shrink: 0; }

  /* Таблицы — горизонтальный скролл */
  .table-wrap { position: relative; overflow-x: auto; border-radius: 8px; }
  .table-wrap table { min-width: 560px; }
  table { font-size: 13px; }
  th, td { padding: 8px 10px; }
  th { font-size: 11px; }

  /* Модалки */
  .modal-card { padding: 18px; border-radius: 12px; }
  .modal-close { width: 32px; height: 32px; font-size: 20px; }

  /* Тосты — во всю ширину */
  .toast {
    left: 12px;
    right: 12px;
    top: 12px;
    text-align: center;
    font-size: 13.5px;
  }

  /* Тест */
  .test-header { font-size: 13px; gap: 8px; }
  .test-header > div:first-child { flex: 1 1 100%; }
  .timer { font-size: 14px; }
  .leave-badge { font-size: 11px; padding: 3px 8px; }
  .question-card { padding: 18px 16px 22px; border-radius: 16px; }
  .option { padding: 12px 14px; font-size: 14.5px; gap: 10px; }
  .option input { transform: scale(1.3); }
  .numeric-input { font-size: 24px; padding: 18px; }
  .numeric-wrap { max-width: 100%; }
  .nav { gap: 8px; }
  .nav button { min-height: 46px; font-size: 15px; }
  .progress { margin-bottom: 18px; }

  /* Preview-режим */
  .preview-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .preview-filters select { width: 100%; }
  .preview-count { margin-left: 0; text-align: right; }
  .preview-banner {
    font-size: 13px;
    padding: 10px 14px;
    flex-direction: column;
    align-items: stretch;
  }
  .preview-banner .preview-actions { display: flex; justify-content: flex-end; }

  /* Инфо-боксы, бейджи, breadcrumbs */
  .info-box { padding: 14px; font-size: 13.5px; }
  .breadcrumbs { font-size: 13px; padding: 8px 10px; gap: 6px; }
  .top-bar { gap: 8px; }
  .top-bar h1 { font-size: 18px; margin-bottom: 4px; }

  /* Классы */
  .analytics-card { padding: 14px; }
  .stats .stat .value { font-size: 20px; }
  .stats .stat .lbl { font-size: 11px; }
}

/* 4. Планшеты: 2 колонки */
@media (min-width: 641px) and (max-width: 900px) {
  .quiz-grid { grid-template-columns: repeat(2, 1fr); }
  .tile-grid { grid-template-columns: repeat(3, 1fr); }
}

/* 5. Ландшафт на телефоне */
@media (max-height: 500px) and (orientation: landscape) {
  .container { padding: 12px; }
  .question-card { padding: 14px; }
  .option { padding: 10px 12px; }
  .nav button { min-height: 40px; }
}

/* 6. Prevent pull-to-refresh при прохождении теста */
body.test-active {
  overscroll-behavior-y: contain;
}

/* 7. iOS safe-area для «челки» */
@supports (padding: max(0px)) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

/* 8. Красивее отображать скан-код игры */
@media (max-width: 640px) {
  .game-card .game-icon { font-size: 28px; }
  .admin-games-grid { grid-template-columns: 1fr; }
}
/* ============ /MOBILE OPTIMIZATION ============ */

/* ============ MOBILE VERTICAL (aggressive) ============ */

/* --- Основной режим: телефоны до 700px --- */
@media (max-width: 700px) {

  /* 1. Базовый размер шрифта крупнее */
  body { font-size: 17px; line-height: 1.55; padding: 0; background: #fff; }

  .container {
    border-radius: 0;
    box-shadow: none;
    padding: 14px 16px 40px;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* 2. Типографика крупнее */
  h1 { font-size: 26px; line-height: 1.25; margin-bottom: 12px; }
  h2 { font-size: 20px; line-height: 1.3; margin-bottom: 12px; }
  h3 { font-size: 17px; margin-bottom: 10px; }
  p  { margin-bottom: 12px; }
  .subtitle { font-size: 15px; margin-bottom: 18px; }

  /* 3. Поля ввода — крупные, высокие, без автозума */
  input[type=text], input[type=password], input[type=email],
  input[type=number], input[type=tel], input[type=search],
  select, textarea {
    font-size: 17px !important;
    padding: 14px 16px !important;
    min-height: 54px;
    border-width: 2px;
    border-radius: 10px;
  }
  textarea { min-height: 120px; }
  .field { margin-bottom: 16px; }
  .field label { font-size: 14px; margin-bottom: 8px; }

  /* 4. Кнопки — большие тач-таргеты */
  button {
    font-size: 16px;
    padding: 14px 22px;
    min-height: 54px;
    border-radius: 12px;
  }
  button.small {
    font-size: 14.5px;
    min-height: 44px;
    padding: 11px 16px;
  }

  /* 5. Actions: кнопки растягиваются на всю ширину */
  .actions {
    flex-direction: column;
    gap: 10px;
  }
  .actions > button { width: 100%; }
  .actions > .badge,
  .actions > span { margin-left: 0 !important; text-align: center; }

  /* 6. Тесты: карточки вертикально, крупные */
  .quiz-grid { grid-template-columns: 1fr !important; gap: 14px; }
  .quiz-card {
    padding: 20px 18px;
    border-radius: 14px;
  }
  .quiz-card-title { font-size: 19px; margin-bottom: 8px; line-height: 1.35; }
  .quiz-card-desc { font-size: 15px; margin-bottom: 12px; line-height: 1.5; }
  .quiz-card-meta { font-size: 14.5px; gap: 12px; }
  .quiz-card .primary.small { font-size: 16px; min-height: 50px; }

  /* 7. Плитки (классы, предметы) — вертикально, крупно */
  .tile-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .tile {
    padding: 18px;
    border-radius: 14px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }
  .tile-icon {
    font-size: 36px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .tile-grade .tile-icon {
    width: 56px;
    height: 56px;
    font-size: 24px;
  }
  .tile-title { font-size: 18px; margin-bottom: 4px; }
  .tile-meta { font-size: 14px; margin-bottom: 4px; }
  .tile-grades { display: none; }

  /* 8. Варианты ответа в тесте — большие, вертикально */
  .option {
    padding: 16px 18px;
    font-size: 16.5px;
    min-height: 64px;
    border-radius: 12px;
    border-width: 2px;
    gap: 14px;
    line-height: 1.45;
  }
  .option input { transform: scale(1.5); margin-top: 4px; flex-shrink: 0; }

  /* 9. Числовой ввод — очень крупный */
  .numeric-input {
    font-size: 32px !important;
    padding: 24px 20px !important;
    min-height: 90px;
    border-radius: 16px;
  }
  .numeric-wrap { max-width: 100%; }

  /* 10. Заголовок теста */
  .test-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    font-size: 15px;
    margin-bottom: 14px;
  }
  .test-header > div:first-child { font-weight: 700; }
  .test-header > div:last-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .timer { font-size: 22px; font-weight: 800; }
  .leave-badge { font-size: 13px; padding: 6px 12px; min-height: 32px; }

  /* 11. Навигация теста — вертикально */
  .nav { flex-direction: column; gap: 10px; margin-top: 20px; }
  .nav button {
    width: 100%;
    min-height: 58px;
    font-size: 17px;
    font-weight: 600;
  }

  /* 12. Вопрос */
  .question-card {
    padding: 20px 18px 24px;
    border-radius: 16px;
  }
  .q-counter { font-size: 13px; padding: 6px 12px; }
  .q-text { font-size: 19px !important; line-height: 1.45; margin-bottom: 18px; }
  .hint { font-size: 14px; margin-bottom: 14px; }

  /* 13. Прогресс — толще */
  .progress { height: 10px; margin-bottom: 18px; border-radius: 5px; }

  /* 14. Админ-табы: горизонтальный скролл с крупными табами */
  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
    gap: 4px;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tabs button {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 15px;
    padding: 12px 16px;
    min-height: 46px;
  }
  .sub-tabs { flex-direction: column; gap: 6px; padding: 6px; }
  .sub-tabs button {
    font-size: 15px;
    padding: 12px;
    min-height: 46px;
  }

  /* 15. Верхняя панель */
  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .top-bar h1 { margin-bottom: 4px; font-size: 22px; }
  .top-bar > div:first-child { min-width: 0; }
  .top-bar > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; }

  /* 16. ТАБЛИЦЫ → вертикальные карточки */
  .table-wrap {
    max-height: none !important;
    overflow: visible !important;
    border: none;
    border-radius: 0;
    margin-bottom: 16px;
  }
  table.mobile-cards {
    min-width: 0 !important;
    width: 100%;
    font-size: 15px;
    border-collapse: separate;
    border-spacing: 0;
  }
  table.mobile-cards thead { display: none; }
  table.mobile-cards tbody tr {
    display: block;
    margin-bottom: 14px;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
  }
  table.mobile-cards tbody tr:hover td { background: #fff; }
  table.mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid #edf2f7;
    font-size: 15px;
    text-align: right;
    line-height: 1.4;
  }
  table.mobile-cards tbody td:last-child { border-bottom: none; }
  table.mobile-cards tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #718096;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: left;
    flex: 0 0 45%;
    max-width: 45%;
    word-break: break-word;
  }
  table.mobile-cards tbody td > * { flex: 1 1 auto; }
  table.mobile-cards tbody td:empty { display: none; }

  /* 17. Статистика (числа) — 2 колонки, крупные */
  .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
  }
  .stat .value { font-size: 26px; }
  .stat .lbl { font-size: 12px; }

  /* 18. Инфо-боксы, предупреждения */
  .info-box { padding: 16px; font-size: 15px; border-radius: 12px; }
  .alert { padding: 14px 16px; font-size: 15px; border-radius: 10px; }

  /* 19. Бейджи — крупнее */
  .badge { font-size: 13px; padding: 5px 12px; }

  /* 20. Хлебные крошки */
  .breadcrumbs {
    font-size: 14px;
    padding: 10px 12px;
    margin-bottom: 14px;
    gap: 6px;
  }

  /* 21. Модальные окна */
  .modal-overlay { padding: 12px 8px; }
  .modal-card { padding: 20px 18px; border-radius: 14px; }
  .modal-card h2 { font-size: 20px; }
  .modal-close {
    width: 40px;
    height: 40px;
    font-size: 22px;
    top: 12px;
    right: 12px;
  }

  /* 22. Тосты */
  .toast {
    left: 12px;
    right: 12px;
    top: 12px;
    text-align: center;
    font-size: 15px;
    padding: 14px 18px;
    border-radius: 12px;
  }

  /* 23. Preview-фильтры */
  .preview-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }
  .preview-filters label {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    font-size: 14px;
  }
  .preview-filters select { width: 100%; }
  .preview-count { margin-left: 0; text-align: center; font-size: 14px; }
  .preview-grade { font-size: 22px; margin: 22px 0 12px; }
  .preview-subject { font-size: 15px; }
  .preview-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    font-size: 14.5px;
    padding: 14px 16px;
  }
  .preview-banner .preview-actions { display: flex; }
  .preview-banner .preview-actions button { width: 100%; }

  /* 24. Аналитика */
  .analytics-card { padding: 16px; font-size: 14.5px; }
  .analytics-card h3 { font-size: 15px; }

  /* 25. Игры */
  .game-card .game-icon { font-size: 44px; margin-bottom: 10px; }
  .admin-games-grid { grid-template-columns: 1fr !important; }
  .admin-game-card { padding: 18px; }
  .admin-game-card h4 { font-size: 18px; }
  .admin-game-card .meta { font-size: 13.5px; }
  .admin-game-card .actions-inline {
    flex-direction: column;
    gap: 8px;
  }
  .admin-game-card .actions-inline button {
    flex: none;
    width: 100%;
  }

  /* 26. Пустые состояния */
  .empty { padding: 40px 20px; font-size: 15px; }
  .empty p[style*="font-size:48px"] { font-size: 56px !important; }
}

/* --- Очень маленькие телефоны (до 400px) --- */
@media (max-width: 400px) {
  .container { padding: 12px 12px 40px; }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  .q-text { font-size: 17px !important; }
  .option { font-size: 15.5px; padding: 14px 16px; }
  .numeric-input { font-size: 28px !important; padding: 20px 16px !important; }
  table.mobile-cards tbody td::before { flex: 0 0 50%; max-width: 50%; }
}

/* --- Планшет: 2 колонки, но всё равно крупнее --- */
@media (min-width: 701px) and (max-width: 1000px) {
  body { font-size: 16px; }
  .quiz-grid { grid-template-columns: repeat(2, 1fr); }
  .tile-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-tabs button { min-height: 44px; }
}

/* ============ /MOBILE VERTICAL ============ */

/* ============ FLUID RESPONSIVE ============ */

/* 1. Палитра fluid-переменных.
   Формула clamp(мин, база + vw-коэффициент, макс).
   vw считается от ширины viewport: 1vw = 1% ширины экрана.
   Так размеры меняются плавно, без «ступенек» на границах. */
:root {
  /* Типографика */
  --fl-base:     clamp(15px, 13.5px + 0.6vw, 19px);   /* основной текст */
  --fl-small:    clamp(12.5px, 11.5px + 0.4vw, 14.5px); /* подписи */
  --fl-mono:     clamp(12.5px, 11.5px + 0.5vw, 15px);   /* код, моноширинный */
  --fl-h1:       clamp(22px, 17px + 2.2vw, 34px);
  --fl-h2:       clamp(18px, 15px + 1.2vw, 24px);
  --fl-h3:       clamp(15.5px, 14px + 0.7vw, 19px);
  --fl-qtext:    clamp(17px, 15px + 1.3vw, 22px);      /* текст вопроса */
  --fl-timer:    clamp(18px, 15px + 1.8vw, 26px);
  --fl-num:      clamp(26px, 20px + 3vw, 40px);        /* ввод числа */
  --fl-stat:     clamp(20px, 17px + 1.5vw, 28px);      /* цифры в статистике */
  --fl-icon-lg:  clamp(36px, 30px + 3vw, 56px);        /* большие иконки */
  --fl-icon-md:  clamp(26px, 22px + 1.5vw, 36px);

  /* Отступы и промежутки */
  --fl-pad-x:    clamp(12px, 8px + 1.6vw, 24px);   /* горизонтальные поля контейнера */
  --fl-pad-y:    clamp(12px, 8px + 1.4vw, 22px);   /* вертикальные поля */
  --fl-gap:      clamp(8px, 6px + 0.6vw, 14px);    /* сеточные промежутки */
  --fl-field-gap:clamp(10px, 8px + 0.6vw, 16px);   /* между полями формы */
  --fl-card-pad: clamp(14px, 11px + 1.2vw, 22px);  /* внутренние отступы карточек */
  --fl-radius:   clamp(10px, 8px + 0.6vw, 16px);
  --fl-radius-lg:clamp(12px, 10px + 1vw, 20px);

  /* Размеры интерактивных элементов */
  --fl-btn-h:    clamp(46px, 42px + 0.7vw, 56px);   /* кнопки */
  --fl-input-h:  clamp(48px, 44px + 0.7vw, 58px);   /* поля ввода */
  --fl-option-h: clamp(56px, 50px + 1vw, 72px);     /* варианты ответа */

  /* Скругления кнопок и полей */
  --fl-border-w: 2px;

  /* Safe area для «челки» iPhone и жестов Android */
  --fl-safe-top:    env(safe-area-inset-top, 0px);
  --fl-safe-right:  env(safe-area-inset-right, 0px);
  --fl-safe-bottom: env(safe-area-inset-bottom, 0px);
  --fl-safe-left:   env(safe-area-inset-left, 0px);
}

/* 2. Применяем переменные к элементам. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-size: var(--fl-base) !important;
  line-height: 1.55;
  -webkit-tap-highlight-color: rgba(102,126,234,0.15);
  overscroll-behavior-y: contain; /* не даём pull-to-refresh сбить сессию */
  padding:
    var(--fl-safe-top)
    var(--fl-safe-right)
    var(--fl-safe-bottom)
    var(--fl-safe-left);
}

h1 { font-size: var(--fl-h1) !important; line-height: 1.25; }
h2 { font-size: var(--fl-h2) !important; line-height: 1.3; }
h3 { font-size: var(--fl-h3) !important; line-height: 1.35; }
.subtitle { font-size: var(--fl-small); }
p { font-size: var(--fl-base); }
code, pre, .json-preview { font-size: var(--fl-mono); }

/* Контейнер */
.container {
  padding: var(--fl-pad-y) var(--fl-pad-x) calc(var(--fl-pad-y) * 2);
  border-radius: var(--fl-radius-lg);
}
@media (max-width: 700px) {
  body { padding: 0; background: #fff; }
  .container {
    border-radius: 0;
    box-shadow: none;
    padding-top: calc(var(--fl-pad-y) + var(--fl-safe-top));
    padding-bottom: calc(var(--fl-pad-y) * 3 + var(--fl-safe-bottom));
    min-height: 100vh;
    min-height: 100dvh;
  }
}

/* Поля форм */
.field { margin-bottom: var(--fl-field-gap); }
.field label { font-size: var(--fl-small); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email],
input[type=number], input[type=tel], input[type=search],
select, textarea {
  font-size: 16px !important;   /* не даёт iOS Safari автоувеличивать страницу */
  min-height: var(--fl-input-h) !important;
  padding: var(--fl-pad-y) var(--fl-pad-x) !important;
  border-radius: var(--fl-radius);
  border-width: var(--fl-border-w);
}
textarea { min-height: calc(var(--fl-input-h) * 2.5); font-size: var(--fl-mono) !important; }

/* Кнопки */
button {
  font-size: var(--fl-base);
  min-height: var(--fl-btn-h);
  padding: calc(var(--fl-pad-y) * 0.9) var(--fl-pad-x);
  border-radius: var(--fl-radius);
  touch-action: manipulation; /* убирает 300 мс задержку тапа */
}
button.small {
  font-size: var(--fl-small);
  min-height: calc(var(--fl-btn-h) * 0.85);
  padding: calc(var(--fl-pad-y) * 0.7) calc(var(--fl-pad-x) * 0.8);
}

/* Сетки — автоматически подстраиваются под ширину, без медиа-запросов */
.quiz-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)) !important;
  gap: var(--fl-gap) !important;
}
.tile-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)) !important;
  gap: var(--fl-gap) !important;
}
.admin-games-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)) !important;
  gap: var(--fl-gap) !important;
}

/* Карточки */
.quiz-card { padding: var(--fl-card-pad); border-radius: var(--fl-radius-lg); }
.quiz-card-title { font-size: var(--fl-h3); margin-bottom: 8px; }
.quiz-card-desc { font-size: var(--fl-small); margin-bottom: 10px; }
.quiz-card-meta { font-size: var(--fl-small); gap: var(--fl-gap); }
.tile { padding: var(--fl-card-pad); border-radius: var(--fl-radius-lg); }
.tile-icon { font-size: var(--fl-icon-md); }
.tile-title { font-size: var(--fl-h3); }
.tile-meta { font-size: var(--fl-small); }
.question-card { padding: var(--fl-card-pad); border-radius: var(--fl-radius-lg); }
.analytics-card { padding: var(--fl-card-pad); }

/* Варианты ответа */
.option {
  padding: var(--fl-pad-y) var(--fl-pad-x) !important;
  font-size: var(--fl-base) !important;
  min-height: var(--fl-option-h);
  border-radius: var(--fl-radius);
  gap: var(--fl-gap);
}
.option input { transform: scale(clamp(1.2, 1 + 0.3vw, 1.5)); }

/* Числовой ввод */
.numeric-input {
  font-size: var(--fl-num) !important;
  padding: calc(var(--fl-pad-y) * 1.4) var(--fl-pad-x) !important;
  min-height: calc(var(--fl-option-h) * 1.4);
  border-radius: var(--fl-radius-lg);
}
.numeric-wrap { max-width: min(100%, 480px); }

/* Вопрос */
.q-text { font-size: var(--fl-qtext) !important; line-height: 1.45; }
.hint { font-size: var(--fl-small); }
.q-counter { font-size: var(--fl-small); padding: 5px 12px; }

/* Заголовок теста */
.test-header { font-size: var(--fl-small); gap: var(--fl-gap); }
.timer { font-size: var(--fl-timer) !important; }
.leave-badge { font-size: var(--fl-small); padding: 5px 12px; min-height: 32px; }

/* Прогресс */
.progress { height: clamp(6px, 0.8vw, 10px); border-radius: 5px; margin-bottom: calc(var(--fl-pad-y) * 1.2); }

/* Навигация */
.nav { gap: var(--fl-gap); margin-top: calc(var(--fl-pad-y) * 1.5); }
.nav button { min-height: var(--fl-btn-h); font-size: var(--fl-base); }

/* Служебные блоки */
.info-box { padding: var(--fl-card-pad); font-size: var(--fl-base); border-radius: var(--fl-radius-lg); }
.alert { padding: var(--fl-card-pad); font-size: var(--fl-base); border-radius: var(--fl-radius); }
.badge { font-size: var(--fl-small); padding: 4px 10px; }
.breadcrumbs { font-size: var(--fl-small); padding: 8px 12px; gap: 6px; margin-bottom: var(--fl-gap); }
.top-bar { gap: var(--fl-gap); }
.stats { gap: var(--fl-gap); }
.stat .value { font-size: var(--fl-stat); }
.stat .lbl { font-size: var(--fl-small); }
.empty { padding: calc(var(--fl-pad-y) * 3) var(--fl-pad-x); font-size: var(--fl-base); }

/* Табы */
.admin-tabs button,
.sub-tabs button {
  font-size: var(--fl-small);
  padding: calc(var(--fl-pad-y) * 0.75) calc(var(--fl-pad-x) * 0.8);
  min-height: var(--fl-btn-h);
}
.admin-tabs, .sub-tabs { gap: 4px; }

/* Модалки */
.modal-card { padding: var(--fl-card-pad); border-radius: var(--fl-radius-lg); }
.modal-close {
  width: clamp(32px, 5vw, 40px);
  height: clamp(32px, 5vw, 40px);
  font-size: var(--fl-h3);
}

/* Тосты */
.toast {
  font-size: var(--fl-base);
  padding: var(--fl-card-pad);
  border-radius: var(--fl-radius);
}

/* Игры */
.game-card .game-icon { font-size: var(--fl-icon-lg); }
.admin-game-card { padding: var(--fl-card-pad); }
.admin-game-card h4 { font-size: var(--fl-h3); }
.admin-game-card .meta { font-size: var(--fl-small); }

/* Preview-режим */
.preview-filters { gap: var(--fl-gap); padding: var(--fl-card-pad); }
.preview-filters label { font-size: var(--fl-small); gap: 6px; }
.preview-filters select { padding: calc(var(--fl-pad-y) * 0.6) var(--fl-pad-x); min-width: 110px; font-size: var(--fl-small); }
.preview-count { font-size: var(--fl-small); }
.preview-grade { font-size: var(--fl-h2); margin: calc(var(--fl-pad-y) * 1.2) 0 var(--fl-gap); }
.preview-subject { font-size: var(--fl-h3); margin: var(--fl-gap) 0 calc(var(--fl-gap) * 0.7); }
.preview-banner {
  font-size: var(--fl-small);
  padding: calc(var(--fl-pad-y) * 0.9) var(--fl-pad-x);
  border-radius: var(--fl-radius);
  gap: var(--fl-gap);
}

/* 3. Адаптивная раскладка для самых узких экранов.
      Всё в одну колонку, кнопки во всю ширину. */
@media (max-width: 700px) {
  .actions { flex-direction: column; }
  .actions > button { width: 100%; }
  .actions > .badge,
  .actions > span { margin-left: 0 !important; text-align: center; }
  .nav { flex-direction: column; }
  .nav button { width: 100%; }
  .top-bar { flex-direction: column; align-items: stretch; }
  .top-bar > div:last-child { display: flex; gap: var(--fl-gap); flex-wrap: wrap; }
  .test-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .test-header > div:last-child { display: flex; justify-content: space-between; align-items: center; }
  .preview-filters { flex-direction: column; align-items: stretch; }
  .preview-filters label { flex-direction: column; align-items: stretch; }
  .preview-filters select { width: 100%; }
  .preview-count { margin-left: 0; text-align: right; }
  .preview-banner { flex-direction: column; align-items: stretch; }
  .preview-banner .preview-actions { display: flex; }
  .preview-banner .preview-actions button { width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; display: grid; }
  .admin-game-card .actions-inline { flex-direction: column; gap: 6px; }
  .admin-game-card .actions-inline button { width: 100%; }
  .tile-grades { display: none; }
}

/* 4. Очень маленькие экраны (iPhone SE, старые Android). */
@media (max-width: 380px) {
  :root {
    --fl-base:  clamp(14px, 13px + 0.5vw, 16px);
    --fl-h1:    clamp(20px, 17px + 1.5vw, 26px);
    --fl-qtext: clamp(16px, 14px + 1vw, 19px);
    --fl-pad-x: clamp(10px, 8px + 1vw, 14px);
    --fl-pad-y: clamp(10px, 8px + 1vw, 14px);
    --fl-card-pad: clamp(12px, 10px + 1vw, 16px);
    --fl-btn-h: clamp(44px, 40px + 1vw, 50px);
  }
}

/* 5. Планшет: более просторные сетки. */
@media (min-width: 701px) and (max-width: 1024px) {
  .container { padding: calc(var(--fl-pad-y) * 1.3) calc(var(--fl-pad-x) * 1.3) calc(var(--fl-pad-y) * 2); }
}

/* 6. Ландшафт на телефоне: экономим вертикаль. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  :root {
    --fl-pad-y: clamp(6px, 1vw, 10px);
    --fl-pad-x: clamp(10px, 1.5vw, 16px);
    --fl-btn-h: clamp(40px, 5vw, 46px);
  }
  .container { padding-top: 8px; padding-bottom: 16px; }
  .quiz-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .nav { flex-direction: row; }
  .nav button { width: auto; flex: 1; }
  h1 { font-size: var(--fl-h2) !important; }
}

/* 7. Широкие экраны: увеличиваем максимальную ширину контейнера. */
@media (min-width: 1200px) {
  .container { max-width: 1200px; }
}
@media (min-width: 1600px) {
  .container { max-width: 1400px; }
  :root {
    --fl-base: 17px;
    --fl-h1: 32px;
    --fl-h2: 22px;
    --fl-qtext: 20px;
  }
}

/* 8. Таблицы: автоскролл на узких, обычный вид на широких. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 700px) {
  /* уже применён previous патч — оставляем как было, только размер */
  table { font-size: var(--fl-small); }
  th, td { padding: calc(var(--fl-pad-y) * 0.6) calc(var(--fl-pad-x) * 0.7); }
  th { font-size: calc(var(--fl-small) - 1px); }
}

/* 9. Уважение к системным настройкам пользователя. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  body { --fl-border-w: 2.5px; }
  .option, button { border-width: 2.5px; }
}

/* 10. На сенсорных экранах — палец вместо мыши. */
@media (hover: none) and (pointer: coarse) {
  button, .option, .tile, .quiz-card, .match-item, .drag-item,
  .letter-tile, .tt-chip, .admin-tabs button {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
  }
  /* Увеличиваем область нажатия для мелких значков */
  button.small { min-height: 44px; }
  .badge[onclick] { min-height: 32px; padding: 6px 12px; }
}

/* 11. Container queries — если браузер поддерживает. */
@supports (container-type: inline-size) {
  .quiz-card, .tile, .admin-game-card { container-type: inline-size; }
  @container (min-width: 340px) {
    .quiz-card { padding: calc(var(--fl-card-pad) * 1.15); }
  }
}

/* 12. Улучшения для печати. */
@media print {
  body { font-size: 12pt; padding: 0; background: #fff; }
  .container { box-shadow: none; padding: 0; max-width: none; }
}

/* ============ /FLUID RESPONSIVE ============ */
