:root{
  --bg:#f4ede3;          /* بني فاتح / بيج */
  --panel:#f4ede3;
  --card:#fffaf3;        /* أبيض دافئ */
  --text:#2b1b10;        /* بني غامق للنص */
  --muted:#6b5a4a;       /* بني رمادي للنص الثانوي */
  --accent:#b07a4a;      /* بني كراميل */
  --accent2:#d9a873;     /* ذهبي فاتح */
  --border:rgba(43,27,16,.14);
  --shadow: 0 12px 28px rgba(43,27,16,.08);
  --shadow2: 0 8px 16px rgba(43,27,16,.06);
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar{
  position:sticky;
  top:0;
  z-index:10;
  background: rgba(244,237,227,.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display:flex;
  gap:14px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
}

.brand{display:flex; gap:12px; align-items:center;}
.logo{
  width:44px; height:44px;
  border-radius:14px;
  display:grid; place-items:center;
  font-weight:900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color:#fff;
  box-shadow: var(--shadow2);
}
.title{margin:0; font-size:18px; line-height:1.1}
.subtitle{margin:2px 0 0; color:var(--muted); font-size:12px}

.tabs{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}
.tab{
  border:1px solid var(--border);
  background: rgba(255,250,243,.9);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:800;
  transition:.18s;
}
.tab:hover{transform: translateY(-1px); border-color: rgba(176,122,74,.45)}
.tab.is-active{
  background: rgba(176,122,74,.14);
  border-color: rgba(176,122,74,.45);
  color: #2b1b10;
}

.container{
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.hero{
  margin: 10px 0 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow2);
  background: linear-gradient(180deg, var(--card), rgba(255,250,243,.65));
  display:grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 14px;
  align-items:center;
}
.hero h2{margin:0 0 6px}
.hero-actions{display:flex; gap:10px; margin-top:12px; flex-wrap:wrap;}

.hero-stats{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat{
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: var(--card);
  box-shadow: var(--shadow2);
}
.stat-num{font-size:22px; font-weight:900; color: var(--accent)}
.stat-label{color: var(--muted); font-size:12px; margin-top:2px}

.panel{display:none; animation: fade .18s ease-out;}
.panel.is-active{display:block}

@keyframes fade{
  from{opacity:.35; transform: translateY(6px)}
  to{opacity:1; transform: translateY(0)}
}

.panel-header{
  margin: 10px 0 14px;
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.panel-header h2{margin:0; font-size:22px}
.muted{color:var(--muted)}
.small{font-size:12px}

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.mt{margin-top:12px}

.card-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}
.card h3{margin:0}

.pill{
  font-size:12px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  color: var(--muted);
  background: rgba(255,250,243,.9);
}

.btn{
  border:1px solid rgba(176,122,74,.45);
  background: rgba(176,122,74,.12);
  color: var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:900;
  transition:.18s;
}
.btn:hover{transform: translateY(-1px); background: rgba(176,122,74,.18)}
.btn:active{transform: translateY(0px)}

.btn-ghost{
  background: rgba(255,250,243,.95);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover{background: rgba(255,250,243,1)}

.actions{
  margin-top: 12px;
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
}

.split{
  display:grid;
  grid-template-columns: 260px 1fr;
  gap: 14px;
}
.side{
  background: rgba(255,250,243,.95);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  height: fit-content;
  box-shadow: var(--shadow2);
}
.subtab{
  width:100%;
  text-align:left;
  padding:12px;
  border-radius:14px;
  border:1px solid transparent;
  background: transparent;
  color:var(--text);
  cursor:pointer;
  font-weight:900;
  transition:.15s;
}
.subtab:hover{background: rgba(255,250,243,1)}
.subtab.is-active{
  border-color: rgba(176,122,74,.35);
  background: rgba(176,122,74,.10);
  color: var(--text);
}

.content{min-height: 260px;}
.lesson{display:none}
.lesson.is-active{display:block}
.lesson h3{margin-top:0}

.lesson-block{
  margin: 12px 0;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,250,243,.98);
  box-shadow: var(--shadow2);
}
.lesson-block h4{margin:0 0 8px}
.lesson-block p{margin:0}

.grid-2{
  margin-top:12px;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-3{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.gap-lg{gap:14px}

.mini-card{
  border:1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,250,243,.98);
  box-shadow: var(--shadow2);
}

.textarea{
  width:100%;
  min-height: 110px;
  padding: 10px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,250,243,.98);
  color: var(--text);
  resize: vertical;
  outline:none;
}
.textarea:focus{border-color: rgba(176,122,74,.45)}

.input{
  width: 320px;
  max-width: 90vw;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,250,243,.98);
  outline:none;
}
.input:focus{border-color: rgba(176,122,74,.45)}

.answer-key{
  border-top: 1px solid var(--border);
  padding-top: 10px;
  color: var(--text);
}

.footer{
  padding: 18px 16px;
  text-align:center;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: rgba(255,250,243,.9);
}

/* Print */
.print-area{display:none}
@media print{
  body{background:#fff; color:#000}
  .topbar, .footer, .hero, .gallery, .tabs, .panel-header, .side, .actions, .muted.small{display:none !important;}
  .panel{display:none !important;}
  #printArea{display:block !important;}
}

/* Responsive */
@media (max-width: 900px){
  .hero{grid-template-columns: 1fr}
  .split{grid-template-columns: 1fr}
  .grid-2{grid-template-columns: 1fr}
  .grid-3{grid-template-columns: 1fr}
}

/* -------- Gallery -------- */
.gallery{
  margin: 14px 0 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--card), rgba(255,250,243,.6));
  box-shadow: var(--shadow2);
}

.gallery-grid{
  display:grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.g-item{
  margin:0;
  border-radius: 16px;
  overflow:hidden;
  border: 1px solid var(--border);
  background: rgba(255,250,243,.98);
  box-shadow: var(--shadow2);
  cursor: pointer;
}

.g-item img{
  width:100%;
  height: 170px;
  object-fit: cover;
  display:block;
  transition: transform .2s ease;
}

.g-item:hover img{
  transform: scale(1.04);
}

@media (max-width: 900px){
  .gallery-grid{grid-template-columns: repeat(2, 1fr);}
  .g-item img{height: 150px;}
}
@media (max-width: 420px){
  .gallery-grid{grid-template-columns: 1fr;}
  .g-item img{height: 190px;}
}

/* -------- Modal (Lightbox) -------- */
.modal{
  position: fixed;
  inset: 0;
  display: none;
  z-index: 9999;
}
.modal.is-open{display:block;}

.modal-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.55);
}

.modal-content{
  position: relative;
  width: min(920px, 92vw);
  margin: 6vh auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.modal-close{
  position:absolute;
  top:10px;
  right:10px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,250,243,.98);
  cursor:pointer;
  font-size: 22px;
  font-weight: 900;
  color: var(--text);
}

/* NEW: Modal arrows for Gallery */
.modal-nav{
  position:absolute;
  top:50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,250,243,.98);
  cursor: pointer;
  font-size: 28px;
  font-weight: 900;
  color: var(--text);
  display:grid;
  place-items:center;
  box-shadow: var(--shadow2);
  user-select:none;
}
.modal-prev{ left: 10px; }
.modal-next{ right: 10px; }

.modal-nav:hover{
  transform: translateY(calc(-50% - 1px));
  border-color: rgba(176,122,74,.45);
}
.modal-nav:active{
  transform: translateY(-50%);
}

@media (max-width: 480px){
  .modal-nav{
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 26px;
  }
}

#modalImg{
  width:100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 14px;
  background: rgba(255,250,243,.98);
  border: 1px solid var(--border);
}

.modal-caption{
  margin: 10px 4px 2px;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

a.btn{ text-decoration:none; display:inline-block; }

/* Game preview iframe wrapper */
.embed-wrap{
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255,250,243,.98);
}
.embed-wrap iframe{
  width: 100%;
  height: min(70vh, 680px);
  border: 0;
  display:block;
}
