:root{
  --blue:#287af0;
  --orange:#ffa51b;
  --red:#e9573c;
  --ink:#20304e;
  --muted:#60738f;
  --line:#dbe7f4;
  --surface:#ffffff;
  --page:#eef5fb;
  --shadow:0 8px 22px rgba(26,56,94,.07);
  --radius:20px;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden}
body{
  font-family:'Nunito',Arial,sans-serif;
  color:var(--ink);
  background:var(--page);
}
button,input,textarea,select{font:inherit}
button{cursor:pointer}
.builder-wrap{
  width:100%;
  height:100dvh;
  padding:14px 22px 0;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
/* HEADER */
.builder-header{
  position:relative;
  width:min(1370px,100%);
  height:116px;
  margin:0 auto 14px;
  display:flex;
  justify-content:center;
  align-items:center;
  flex:0 0 auto;
}
.builder-header-main{
  min-width:0;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:13px;
  padding-right:126px;
}
.builder-logo-box{
  width:108px;
  height:108px;
  flex:0 0 108px;
  display:flex;
  align-items:center;
  justify-content:center;
  background:transparent;
}
.builder-app-logo{
  display:block;
  width:106px;
  height:106px;
  object-fit:contain;
  background:transparent;
}
.builder-title-box{
  min-width:min(800px,calc(100vw - 360px));
  display:flex;
  flex-direction:column;
  justify-content:center;
  text-align:center;
  padding:0 10px;
  background:transparent;
}
.builder-header h1{
  margin:0;
  font-size:clamp(40px,4.1vw,58px);
  line-height:1;
  letter-spacing:.04em;
  font-weight:900;
  white-space:nowrap;
}
.title-tug{color:var(--blue)}
.title-to,.title-html{color:var(--orange)}
.title-to{margin:0 .05em}
.builder-header p{
  margin:12px 0 0;
  color:var(--muted);
  font-size:14px;
  font-weight:750;
  line-height:1.3;
}
.builder-header-tools{
  position:absolute;
  top:10px;
  right:0;
  width:116px;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.ui-language-toggle,
.howto-button{
  width:116px;
  height:42px;
  border:1px solid #dce8f5;
  border-radius:999px;
  background:var(--surface);
}
.ui-language-toggle{
  display:flex;
  align-items:center;
  gap:3px;
  padding:3px;
}
.ui-language-toggle button{
  width:53px;
  height:34px;
  border:0;
  border-radius:999px;
  background:transparent;
  color:#657791;
  font-size:13px;
  font-weight:900;
}
.ui-language-toggle button.active{background:var(--blue);color:#fff}
.howto-details{position:relative;width:116px}
.howto-details summary{list-style:none}
.howto-details summary::-webkit-details-marker{display:none}
.howto-button{
  display:flex;
  justify-content:center;
  align-items:center;
  gap:7px;
  color:#324967;
  font-size:13px;
  font-weight:850;
}
.howto-button:hover,.ui-language-toggle:hover{border-color:#c8dbef}
.howto-icon{
  width:19px;height:19px;border-radius:50%;
  display:inline-flex;align-items:center;justify-content:center;
  color:var(--blue);background:#eaf3ff;font-weight:900;
}
.howto-popover{
  position:absolute;top:49px;right:0;z-index:30;
  width:236px;padding:12px 13px;
  display:flex;flex-direction:column;gap:6px;
  border:1px solid var(--line);border-radius:14px;
  background:#fff;box-shadow:0 16px 36px rgba(25,57,94,.15);
  color:var(--muted);font-size:12px;line-height:1.4;
}
.howto-popover strong{color:var(--ink);font-size:13px}
/* MAIN TWO COLUMNS */
.builder-grid{
  width:min(1430px,100%);
  margin:0 auto;
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns:minmax(304px,326px) minmax(0,1fr);
  gap:16px;
  align-items:stretch;
}
.card{
  background:var(--surface);
  border:1px solid #e1eaf5;
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  min-height:0;
}
.settings{
  height:100%;
  padding:15px 15px 12px;
  overflow-y:auto;
  scrollbar-width:thin;
  scrollbar-color:#c8d9ec transparent;
}
.settings h2,.bank-head h2{
  margin:0 0 10px;
  color:var(--ink);
  font-size:21px;
  line-height:1.2;
  font-weight:900;
}
.settings label{
  display:block;
  margin:8px 0 4px;
  font-size:13px;
  font-weight:850;
}
.settings input,.settings select{
  width:100%;height:41px;
  padding:0 12px;
  border:1px solid var(--line);border-radius:12px;
  color:var(--ink);background:#fff;outline:none;
}
.settings select{cursor:pointer}
.settings input:focus,.settings select:focus,.q-field:focus{
  border-color:var(--blue);
  box-shadow:0 0 0 3px rgba(40,122,240,.11);
}
.note{
  margin:5px 0 7px;
  color:var(--muted);
  font-size:11.5px;
  line-height:1.35;
}
.preview{
  margin-top:9px;
  padding:8px 10px;
  display:flex;align-items:center;gap:10px;
  border:1px solid #e3ecf7;border-radius:13px;
  background:#f8fbff;
}
.preview img{width:40px;height:40px;object-fit:contain;border-radius:7px}
.preview strong{display:block;font-size:13px;color:var(--blue);font-weight:900;text-transform:uppercase}
.preview .note{display:block;margin:1px 0 0}
.builder-alert{
  margin:9px 0 0;
  padding:8px 10px;
  border:1px solid #ffdfa0;border-radius:12px;
  background:#fff5df;color:#945b00;
  font-size:11.5px;font-weight:750;line-height:1.35;
}
.builder-alert.ready{background:#ecf9f0;border-color:#bbe6c6;color:#13743c}
.action-main{
  width:100%;min-height:43px;margin-top:10px;padding:0 10px;
  border:0;border-radius:12px;
  color:#fff;background:linear-gradient(135deg,#1872ed,#388ff0);
  font-size:13px;font-weight:900;
}
.action-main:hover{filter:brightness(1.03)}
.technical{margin:7px 0 0;color:var(--muted);font-size:10.5px;line-height:1.35}
.builder-grid>.card:not(.settings){
  height:100%;
  display:flex;flex-direction:column;
  padding:18px 19px 15px;
  overflow:hidden;
}
.bank-head{
  flex:0 0 auto;
  margin-bottom:10px;
  display:flex;align-items:flex-start;justify-content:space-between;gap:18px;
}
.bank-head .note{margin:0;max-width:470px;font-size:13px}
.bank-actions{
  max-width:650px;
  display:flex;justify-content:flex-end;gap:7px;flex-wrap:wrap;
}
.btn{
  min-height:42px;padding:0 14px;
  display:inline-flex;align-items:center;justify-content:center;
  border:1px solid #cfe1f5;border-radius:13px;
  background:#eff6ff;color:#204979;
  font-size:13px;font-weight:900;white-space:nowrap;
}
.btn:hover{background:#e7f1ff}
.btn.upload{position:relative;overflow:hidden}
.btn.upload input{position:absolute;inset:0;opacity:0;cursor:pointer}
.btn.danger{border-color:#ffc9bb;background:#fff3ef;color:#b43a25}
.btn.danger:hover{background:#ffebe6}
.question-list{
  flex:1 1 auto;min-height:0;
  display:flex;flex-direction:column;gap:11px;
  padding-right:5px;overflow-y:auto;
  scrollbar-width:thin;scrollbar-color:#c8d9ec transparent;
}
.question-item{
  padding:12px;
  border:1px solid #e0eaf6;border-radius:15px;
  background:#fbfdff;
}
.q-top{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:9px}
.q-top strong{font-size:14px;font-weight:900;color:var(--ink)}
.delete-q{
  min-height:30px;padding:0 10px;
  border:1px solid #ffd0c6;border-radius:9px;
  background:#fff3ef;color:#ba4029;font-size:12px;font-weight:850;
}
.q-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}
.q-field{
  width:100%;min-width:0;height:39px;padding:0 11px;
  border:1px solid var(--line);border-radius:10px;
  background:#fff;color:var(--ink);outline:none;font-size:13px;
}
.q-field.textarea{height:54px;padding:9px 11px;resize:vertical;line-height:1.4}
.q-span{grid-column:1/-1}
.correct-field{border-color:#9bd7ae;background:#f3fff6;font-weight:750}
.q-field.rtl-input{direction:rtl;text-align:right;font-family:'Noto Naskh Arabic','Amiri','Traditional Arabic',serif;font-size:17px;line-height:1.55}
.question-list.rtl-bank .q-top{direction:rtl}
.question-list.rtl-bank .q-top strong{font-family:'Noto Naskh Arabic',serif}
.detected-language{font-weight:850;color:#1764d7}
/* GAME PREVIEW, builder only */
.game-preview{margin-top:14px;padding:17px;flex:0 0 auto}
.game-preview.hidden{display:none}
.preview-head{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:12px}
.preview-head h2{margin:0 0 3px;font-size:21px}
.preview-head .note{margin:0}
.action-download{
  min-height:45px;padding:0 17px;border:0;border-radius:12px;
  background:linear-gradient(135deg,#14984e,#20bf68);color:#fff;font-weight:900;
}
#gamePreviewFrame{display:block;width:100%;height:min(820px,82vh);min-height:640px;border:1px solid var(--line);border-radius:15px;background:#fff}
body:has(#previewSection:not(.hidden)){height:auto;min-height:100%;overflow:auto}
body:has(#previewSection:not(.hidden)) .builder-wrap{height:auto;min-height:100dvh;overflow:visible}
body:has(#previewSection:not(.hidden)) .builder-grid{min-height:600px}
/* FOOTER: text retained */
.app-footer{
  width:calc(100% + 44px);
  margin:10px -22px 0;
  padding:10px 15px 11px;
  flex:0 0 auto;
  background:#09152a;color:#98a8bf;text-align:center;
  border-top:1px solid rgba(255,255,255,.06);
}
.footer-main{font-size:12px;font-weight:650;letter-spacing:.02em}
.footer-brand{color:#fff;font-weight:850;text-decoration:none}
.footer-brand:hover{text-decoration:underline}
.footer-updated{margin-top:7px;font-size:9px;font-weight:850;letter-spacing:.26em;text-transform:uppercase;color:#64758d}
/* MOBILE / NARROW SCREEN */
@media (max-width:980px){
  html,body{height:auto;min-height:100%;overflow:auto}
  .builder-wrap{height:auto;min-height:100dvh;padding:11px 12px 0;overflow:visible}
  .builder-header{height:auto;width:100%;margin:0 0 12px;display:flex;flex-direction:column;gap:9px}
  .builder-header-main{width:100%;padding:0;display:flex;flex-direction:column;gap:6px}
  .builder-logo-box{width:92px;height:92px;flex-basis:92px}
  .builder-app-logo{width:92px;height:92px}
  .builder-title-box{min-width:0;padding:0;width:100%}
  .builder-header h1{font-size:clamp(29px,9.8vw,42px);letter-spacing:.025em;white-space:normal}
  .builder-header p{margin-top:8px;font-size:12.5px}
  .builder-header-tools{position:static;width:100%;flex-direction:row;justify-content:flex-end;gap:8px}
  .howto-popover{right:0}
  .builder-grid{display:flex;flex-direction:column;gap:12px;min-height:0}
  .settings,.builder-grid>.card:not(.settings){height:auto;overflow:visible;padding:14px}
  .bank-head{display:block}
  .bank-actions{justify-content:flex-start;margin-top:10px}
  .question-list{overflow:visible}
  .q-grid{grid-template-columns:1fr}
  .game-preview{margin-top:12px;padding:14px}
  .preview-head{display:block}
  .action-download{width:100%;margin-top:10px}
  #gamePreviewFrame{height:76vh;min-height:520px}
  .app-footer{width:calc(100% + 24px);margin:12px -12px 0;padding:16px 12px}
  .footer-main{font-size:11.5px;line-height:1.42}
  .footer-updated{font-size:8.5px;letter-spacing:.2em}
}
