/* =========================================================
   توعية مرورية — Responsive Design
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@600;700;800;900&family=Tajawal:wght@400;500;700&display=swap');


/* =========================================================
   DESIGN TOKENS
   ========================================================= */

:root{
  --bg: #F6F4EE;
  --surface: #FFFFFF;
  --surface-2: #FBF9F4;
  --text: #1C2430;
  --muted: #66707F;
  --border: #E4DFD3;

  --accent: #E4972B;
  --accent-ink: #7A4C0C;
  --accent-2: #1F5FA8;

  --danger: #C63F3B;
  --success: #2E9C5B;

  --shadow: 0 10px 30px -12px rgba(28,36,48,0.18);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;

  --lane: repeating-linear-gradient(
    90deg,
    var(--accent) 0 26px,
    transparent 26px 46px
  );

  color-scheme: light;
}


html[data-theme="dark"]{
  --bg: #0D1420;
  --surface: #141C2B;
  --surface-2: #101828;
  --text: #EEF1F6;
  --muted: #93A0B4;
  --border: #263248;

  --accent: #F0AC46;
  --accent-ink: #FCE3B8;
  --accent-2: #5B9AE0;

  --danger: #E76A65;
  --success: #45C57E;

  --shadow: 0 16px 40px -14px rgba(0,0,0,0.55);

  color-scheme: dark;
}


/* =========================================================
   GLOBAL RESET
   ========================================================= */

*,
*::before,
*::after{
  box-sizing: border-box;
}


html,
body{
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
}


body{
  margin: 0;

  background:
    radial-gradient(
      circle at 15% -10%,
      color-mix(
        in srgb,
        var(--accent) 10%,
        transparent
      ),
      transparent 40%
    ),
    var(--bg);

  color: var(--text);

  font-family:
    'Tajawal',
    system-ui,
    sans-serif;

  min-height: 100vh;

  transition:
    background .35s ease,
    color .35s ease;

  -webkit-font-smoothing: antialiased;
}


h1,
h2,
h3,
.brand,
.big-num{
  font-family:
    'Cairo',
    'Tajawal',
    sans-serif;
}


/* =========================================================
   APP CONTAINER
   ========================================================= */

.app{
  width: 100%;
  max-width: 720px;

  margin: 0 auto;

  min-height: 100vh;

  display: flex;
  flex-direction: column;

  padding:
    18px
    18px
    40px;
}


/* =========================================================
   TOP BAR
   ========================================================= */

.topbar{
  display: flex;

  align-items: center;

  justify-content: space-between;

  padding:
    8px
    4px
    22px;
}


.brand{
  display: flex;

  align-items: center;

  gap: 10px;

  font-weight: 800;

  font-size: 1.28rem;

  letter-spacing: -0.5px;
}


.brand-badge{
  width: 38px;
  height: 38px;

  flex: none;

  display: flex;

  align-items: center;
  justify-content: center;

  background: var(--accent);

  clip-path: polygon(
    30% 0,
    70% 0,
    100% 30%,
    100% 70%,
    70% 100%,
    30% 100%,
    0 70%,
    0 30%
  );

  color: #1C2430;

  font-weight: 900;

  box-shadow: var(--shadow);
}


.theme-toggle{
  border: 1px solid var(--border);

  background: var(--surface);

  color: var(--text);

  width: 42px;
  height: 42px;

  border-radius: 50%;

  display: flex;

  align-items: center;
  justify-content: center;

  cursor: pointer;

  transition:
    transform .2s ease,
    background .2s ease;

  font-size: 1.1rem;
}


.theme-toggle:hover{
  transform: translateY(-2px);
}


.theme-toggle:active{
  transform: scale(.94);
}


/* =========================================================
   SCREENS
   ========================================================= */

.screen{
  display: none;

  flex: 1;

  flex-direction: column;

  animation: fadeUp .45s ease;
}


.screen.active{
  display: flex;
}


@keyframes fadeUp{

  from{
    opacity: 0;

    transform:
      translateY(10px);
  }

  to{
    opacity: 1;

    transform:
      translateY(0);
  }

}


/* =========================================================
   CARD
   ========================================================= */

.card{
  background: var(--surface);

  border: 1px solid var(--border);

  border-radius: var(--radius-lg);

  box-shadow: var(--shadow);

  padding: 26px;
}


/* =========================================================
   HOME
   ========================================================= */

.hero{
  text-align: center;

  padding:
    18px
    8px
    8px;
}


.hero .lane-strip{
  height: 6px;

  width: 120px;

  margin:
    0
    auto
    22px;

  background: var(--lane);

  border-radius: 4px;

  opacity: .85;
}


.hero h1{
  font-size: 1.9rem;

  font-weight: 900;

  margin:
    0
    0
    10px;

  line-height: 1.35;
}


.hero p{
  color: var(--muted);

  font-size: 1rem;

  max-width: 460px;

  margin:
    0
    auto
    28px;

  line-height: 1.9;
}


.stat-row{
  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  gap: 12px;

  margin:
    26px
    0
    30px;
}


.stat{
  background: var(--surface-2);

  border: 1px solid var(--border);

  border-radius: var(--radius-md);

  padding:
    16px
    8px;

  text-align: center;
}


.stat .big-num{
  font-size: 1.4rem;

  font-weight: 800;

  color: var(--accent-2);
}


html[data-theme="dark"]
.stat .big-num{
  color: var(--accent);
}


.stat .lbl{
  font-size: .8rem;

  color: var(--muted);

  margin-top: 4px;
}


/* =========================================================
   BUTTONS
   ========================================================= */

.btn{
  appearance: none;

  border: none;

  cursor: pointer;

  font-family:
    'Cairo',
    'Tajawal',
    sans-serif;

  font-weight: 800;

  font-size: 1.02rem;

  border-radius: 999px;

  padding:
    16px
    28px;

  display: inline-flex;

  align-items: center;
  justify-content: center;

  gap: 8px;

  transition:
    transform .15s ease,
    box-shadow .15s ease,
    opacity .15s ease;
}


.btn:active{
  transform: scale(.97);
}


.btn-primary{
  background:
    linear-gradient(
      135deg,
      var(--accent),
      color-mix(
        in srgb,
        var(--accent) 70%,
        #ff8a00
      )
    );

  color: #20140a;

  box-shadow:
    0 12px
    24px
    -10px
    color-mix(
      in srgb,
      var(--accent) 70%,
      transparent
    );

  width: 100%;
}


.btn-primary:hover{
  transform: translateY(-2px);
}


.btn-outline{
  background: transparent;

  border:
    1.5px
    solid
    var(--border);

  color: var(--text);
}


.btn-outline:hover{
  border-color: var(--accent-2);
}


.btn-ghost{
  background: var(--surface-2);

  color: var(--text);

  border:
    1px
    solid
    var(--border);
}


.btn-block{
  width: 100%;
}


.btn:disabled{
  opacity: .45;

  cursor: not-allowed;
}


/* =========================================================
   RULES
   ========================================================= */

.rules{
  margin-top: 6px;

  text-align: right;

  color: var(--muted);

  font-size: .92rem;

  line-height: 2;
}


.rules b{
  color: var(--text);
}


/* =========================================================
   EXAM HEADER
   ========================================================= */

.exam-head{
  display: flex;

  align-items: center;

  justify-content: space-between;

  gap: 16px;

  margin-bottom: 18px;
}


.progress-wrap{
  flex: 1;

  min-width: 0;
}


.progress-label{
  display: flex;

  justify-content: space-between;

  gap: 10px;

  font-size: .85rem;

  color: var(--muted);

  margin-bottom: 6px;
}


.progress-track{
  height: 8px;

  border-radius: 6px;

  background: var(--surface-2);

  border:
    1px
    solid
    var(--border);

  overflow: hidden;
}


.progress-fill{
  height: 100%;

  width: 0%;

  background:
    linear-gradient(
      90deg,
      var(--accent-2),
      var(--accent)
    );

  border-radius: 6px;

  transition:
    width .35s ease;
}


/* =========================================================
   TIMER
   ========================================================= */

.timer{
  position: relative;

  width: 64px;
  height: 64px;

  flex: none;
}


.timer svg{
  width: 100%;
  height: 100%;

  transform: rotate(-90deg);
}


.timer circle{
  fill: none;

  stroke-width: 6;
}


.timer .track{
  stroke: var(--border);
}


.timer .fill{
  stroke: var(--success);

  stroke-linecap: round;

  transition:
    stroke-dashoffset 1s linear,
    stroke .4s ease;
}


.timer .time{
  position: absolute;

  inset: 0;

  display: flex;

  align-items: center;
  justify-content: center;

  font-weight: 800;

  font-size: .82rem;

  font-family:
    'Cairo',
    sans-serif;
}


/* =========================================================
   QUESTION CARD
   ========================================================= */

/*
   DEFAULT / MOBILE LAYOUT

   Image
      ↓
   Question
      ↓
   Answers

   Desktop layout is overridden below.
*/

.q-card{
  width: 100%;

  display: flex;

  flex-direction: column;

  padding: 22px;
}


/* =========================================================
   QUESTION IMAGE
   ========================================================= */

.q-img-wrap{
  width: 100%;

  max-height: 260px;

  border-radius: var(--radius-md);

  overflow: hidden;

  border:
    1px
    solid
    var(--border);

  margin-bottom: 18px;

  background: var(--surface-2);

  display: none;

  flex-shrink: 0;
}


.q-img-wrap img{
  width: 100%;

  height: 260px;

  max-width: 100%;

  display: block;

  /*
     Keep the whole image visible.
     It will not be cropped.
  */

  object-fit: contain;

  object-position: center;
}


/* =========================================================
   QUESTION TEXT
   ========================================================= */

.q-text{
  width: 100%;

  font-size: 1.18rem;

  font-weight: 700;

  line-height: 1.8;

  margin:
    0
    0
    20px;
}


/* =========================================================
   ANSWERS
   ========================================================= */

.answers{
  width: 100%;

  display: flex;

  flex-direction: column;

  gap: 10px;
}


.answer{
  width: 100%;

  display: flex;

  align-items: center;

  gap: 12px;

  text-align: right;

  padding:
    14px
    16px;

  border-radius: var(--radius-md);

  border:
    1.5px
    solid
    var(--border);

  background: var(--surface-2);

  cursor: pointer;

  font-size: 1rem;

  color: var(--text);

  transition:
    border-color .15s ease,
    background .15s ease,
    transform .1s ease;
}


.answer:hover{
  border-color: var(--accent-2);
}


.answer .mark{
  flex: none;

  width: 28px;
  height: 28px;

  border-radius: 50%;

  border:
    1.5px
    solid
    var(--border);

  display: flex;

  align-items: center;
  justify-content: center;

  font-size: .8rem;

  font-weight: 800;

  color: var(--muted);

  background: var(--surface);
}


.answer.selected{
  border-color: var(--accent-2);

  background:
    color-mix(
      in srgb,
      var(--accent-2) 10%,
      var(--surface-2)
    );
}


.answer.selected .mark{
  background: var(--accent-2);

  color: #fff;

  border-color: var(--accent-2);
}


.answer.correct{
  border-color: var(--success);

  background:
    color-mix(
      in srgb,
      var(--success) 14%,
      var(--surface-2)
    );
}


.answer.correct .mark{
  background: var(--success);

  color: #fff;

  border-color: var(--success);
}


.answer.wrong{
  border-color: var(--danger);

  background:
    color-mix(
      in srgb,
      var(--danger) 14%,
      var(--surface-2)
    );
}


.answer.wrong .mark{
  background: var(--danger);

  color: #fff;

  border-color: var(--danger);
}


.answer.disabled{
  pointer-events: none;
}


/* =========================================================
   EXAM NAVIGATION
   ========================================================= */

.exam-nav{
  display: flex;

  justify-content: space-between;

  gap: 12px;

  margin-top: 20px;
}


.exam-nav .btn{
  flex: 1;
}


/* =========================================================
   DESKTOP EXAM LAYOUT
   =========================================================

   At 800px and above:

   ┌──────────────────────┬───────────────────────┐
   │                      │                       │
   │      ANSWERS         │      IMAGE             │
   │                      │                       │
   │   ○ Answer 1         │      ┌───────────┐    │
   │   ○ Answer 2         │      │           │    │
   │   ○ Answer 3         │      │   IMAGE   │    │
   │   ○ Answer 4         │      │           │    │
   │                      │      └───────────┘    │
   │                      │                       │
   │                      │      QUESTION         │
   │                      │                       │
   └──────────────────────┴───────────────────────┘

   RTL:
   RIGHT  = Question + Image
   LEFT   = Answers
   ========================================================= */

@media (min-width: 800px){

  /*
     Increase app width on desktop.

     This gives enough room for both columns.
  */

  .app{
    max-width: 900px;
  }


  /*
     Two-column grid.

     Column 1 = LEFT = Answers
     Column 2 = RIGHT = Question/Image
  */

  .q-card{
    display: grid;

    grid-template-columns:
      minmax(280px, .85fr)
      minmax(0, 1.15fr);

    grid-template-rows:
      auto
      auto;

    column-gap: 28px;

    row-gap: 16px;

    align-items: start;

    padding: 26px;
  }


  /*
     IMAGE
     RIGHT COLUMN
  */

  .q-img-wrap{
    grid-column: 2;

    grid-row: 1;

    width: 100%;

    max-height: 260px;

    margin: 0;

    border-radius: var(--radius-md);

    overflow: hidden;
  }


  .q-img-wrap img{
    width: 100%;

    height: 260px;

    display: block;

    object-fit: contain;

    object-position: center;
  }


  /*
     QUESTION
     RIGHT COLUMN
  */

  .q-text{
    grid-column: 2;

    grid-row: 2;

    width: 100%;

    margin: 0;

    font-size: 1.15rem;

    line-height: 1.8;
  }


  /*
     ANSWERS
     LEFT COLUMN

     Answers span both rows so they stay
     beside image + question.
  */

  .answers{
    grid-column: 1;

    grid-row:
      1
      /
      span 2;

    width: 100%;

    display: flex;

    flex-direction: column;

    gap: 10px;

    align-self: start;
  }


  .answer{
    width: 100%;

    padding:
      13px
      15px;

    font-size: .95rem;

    line-height: 1.5;
  }


  .answer .mark{
    width: 28px;

    height: 28px;
  }


  /*
     EXAM NAVIGATION

     Buttons stay underneath the two-column
     question area.
  */

  .exam-nav{
    display: flex;

    flex-direction: row;

    gap: 14px;

    margin-top: 16px;
  }


  .exam-nav .btn{
    flex: 1;

    min-height: 50px;
  }

}


/* =========================================================
   LARGE DESKTOP
   ========================================================= */

@media (min-width: 1100px){

  .app{
    max-width: 1000px;
  }


  .q-card{
    grid-template-columns:
      minmax(320px, .85fr)
      minmax(0, 1.15fr);

    column-gap: 34px;

    padding: 30px;
  }


  .q-img-wrap{
    max-height: 300px;
  }


  .q-img-wrap img{
    height: 300px;
  }


  .q-text{
    font-size: 1.2rem;
  }


  .answer{
    padding:
      14px
      16px;

    font-size: 1rem;
  }

}


/* =========================================================
   RESULT
   ========================================================= */

.result-icon{
  width: 88px;
  height: 88px;

  margin:
    0
    auto
    18px;

  border-radius: 50%;

  display: flex;

  align-items: center;
  justify-content: center;

  font-size: 2.2rem;

  box-shadow: var(--shadow);
}


.result-icon.pass{
  background:
    color-mix(
      in srgb,
      var(--success) 20%,
      var(--surface)
    );

  color: var(--success);
}


.result-icon.fail{
  background:
    color-mix(
      in srgb,
      var(--danger) 20%,
      var(--surface)
    );

  color: var(--danger);
}


.result-score{
  font-size: 2.6rem;

  font-weight: 900;

  text-align: center;

  margin:
    4px
    0
    2px;
}


.result-sub{
  text-align: center;

  color: var(--muted);

  margin-bottom: 24px;
}


.result-actions{
  display: flex;

  flex-direction: column;

  gap: 10px;
}


/* =========================================================
   NAME FORM
   ========================================================= */

.field{
  margin-bottom: 18px;
}


.field label{
  display: block;

  margin-bottom: 8px;

  font-weight: 700;

  font-size: .95rem;
}


.field input{
  width: 100%;

  padding:
    14px
    16px;

  border-radius: var(--radius-md);

  border:
    1.5px
    solid
    var(--border);

  background: var(--surface-2);

  color: var(--text);

  font-family:
    'Tajawal',
    sans-serif;

  font-size: 1rem;

  text-align: right;
}


.field input:focus{
  outline: none;

  border-color: var(--accent-2);
}


/* =========================================================
   CERTIFICATE
   ========================================================= */

.cert-wrap{
  width: 100%;

  margin-bottom: 18px;

  overflow: hidden;
}


#certCanvas{
  width: 100%;

  max-width: 100%;

  height: auto;

  border-radius: var(--radius-md);

  border:
    1px
    solid
    var(--border);

  box-shadow: var(--shadow);

  display: block;
}


.share-row{
  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  gap: 10px;

  margin:
    16px
    0;
}


.share-btn{
  display: flex;

  flex-direction: column;

  align-items: center;

  gap: 6px;

  padding:
    14px
    6px;

  border-radius: var(--radius-md);

  border:
    1px
    solid
    var(--border);

  background: var(--surface-2);

  color: var(--text);

  cursor: pointer;

  font-size: .82rem;

  font-weight: 700;

  transition:
    transform .15s ease;
}


.share-btn:hover{
  transform: translateY(-2px);
}


.share-btn .ico{
  font-size: 1.3rem;
}


/* =========================================================
   FOOTER
   ========================================================= */

.footer-note{
  text-align: center;

  color: var(--muted);

  font-size: .78rem;

  margin-top: auto;

  padding-top: 30px;
}


/* =========================================================
   TOAST
   ========================================================= */

.toast{
  position: fixed;

  bottom: 22px;

  left: 50%;

  transform:
    translateX(-50%)
    translateY(20px);

  background: var(--text);

  color: var(--bg);

  padding:
    12px
    20px;

  border-radius: 999px;

  font-size: .9rem;

  font-weight: 700;

  opacity: 0;

  pointer-events: none;

  transition:
    all .3s ease;

  z-index: 50;

  box-shadow: var(--shadow);
}


.toast.show{
  opacity: 1;

  transform:
    translateX(-50%)
    translateY(0);
}


/* =========================================================
   TABLET
   ========================================================= */

@media (min-width: 560px) and (max-width: 799px){

  .hero h1{
    font-size: 2.2rem;
  }


  .card{
    padding: 30px;
  }


  .q-img-wrap{
    max-height: 240px;
  }


  .q-img-wrap img{
    height: 240px;
  }

}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 799px){

  /*
     Keep mobile layout vertical.

     IMAGE
       ↓
     QUESTION
       ↓
     ANSWERS
  */

  .app{
    width: 100%;

    max-width: 100%;

    padding:
      10px
      12px
      24px;
  }


  .topbar{
    padding:
      6px
      2px
      14px;
  }


  .brand{
    font-size: 1.05rem;
  }


  .brand-badge{
    width: 34px;
    height: 34px;
  }


  .theme-toggle{
    width: 38px;
    height: 38px;
  }


  .hero{
    padding:
      10px
      4px
      4px;
  }


  .hero .lane-strip{
    margin-bottom: 14px;
  }


  .hero h1{
    font-size: 1.45rem;

    line-height: 1.5;
  }


  .hero p{
    font-size: .9rem;

    line-height: 1.8;

    margin-bottom: 20px;
  }


  .stat-row{
    gap: 7px;

    margin:
      18px
      0
      20px;
  }


  .stat{
    padding:
      11px
      5px;
  }


  .stat .big-num{
    font-size: 1.15rem;
  }


  .stat .lbl{
    font-size: .7rem;
  }


  .btn{
    font-size: .92rem;

    padding:
      13px
      18px;
  }


  .rules{
    font-size: .82rem;

    line-height: 1.8;
  }


  /* =====================================================
     MOBILE EXAM HEADER
     ===================================================== */

  .exam-head{
    gap: 10px;

    margin-bottom: 10px;
  }


  .progress-label{
    font-size: .72rem;
  }


  .timer{
    width: 54px;

    height: 54px;
  }


  .timer .time{
    font-size: .7rem;
  }


  /* =====================================================
     MOBILE QUESTION CARD
     ===================================================== */

  .q-card{
    display: flex;

    flex-direction: column;

    width: 100%;

    padding: 14px;

    border-radius: 16px;

    gap: 0;
  }


  /*
     Small image on mobile
  */

  .q-img-wrap{
    width: 100%;

    max-width: 100%;

    max-height: 170px;

    margin-bottom: 12px;

    border-radius: 10px;
  }


  .q-img-wrap img{
    width: 100%;

    height: 170px;

    object-fit: contain;

    object-position: center;
  }


  /* =====================================================
     MOBILE QUESTION
     ===================================================== */

  .q-text{
    width: 100%;

    font-size: 1rem;

    line-height: 1.65;

    margin:
      0
      0
      14px;
  }


  /* =====================================================
     MOBILE ANSWERS
     ===================================================== */

  .answers{
    width: 100%;

    display: flex;

    flex-direction: column;

    gap: 7px;
  }


  .answer{
    width: 100%;

    padding:
      10px
      11px;

    gap: 9px;

    font-size: .9rem;

    line-height: 1.5;

    border-radius: 10px;
  }


  .answer .mark{
    width: 25px;

    height: 25px;

    font-size: .72rem;
  }


  /* =====================================================
     MOBILE NAVIGATION
     ===================================================== */

  .exam-nav{
    display: flex;

    flex-direction: row;

    gap: 8px;

    margin-top: 10px;
  }


  .exam-nav .btn{
    flex: 1;

    min-width: 0;

    padding:
      11px
      10px;

    font-size: .82rem;
  }


  /* =====================================================
     MOBILE CARD
     ===================================================== */

  .card{
    padding: 18px;

    border-radius: 16px;
  }


  /* =====================================================
     MOBILE RESULT
     ===================================================== */

  .result-score{
    font-size: 2.1rem;
  }


  /* =====================================================
     MOBILE CERTIFICATE
     ===================================================== */

  .share-row{
    gap: 6px;
  }


  .share-btn{
    padding:
      10px
      4px;

    font-size: .72rem;
  }


  .share-btn .ico{
    font-size: 1.1rem;
  }


  .footer-note{
    padding-top: 20px;
  }

}


/* =========================================================
   VERY SMALL PHONES
   ========================================================= */

@media (max-width: 380px){

  .app{
    padding-left: 8px;

    padding-right: 8px;
  }


  .q-img-wrap{
    max-height: 140px;
  }


  .q-img-wrap img{
    height: 140px;
  }


  .q-text{
    font-size: .94rem;
  }


  .answer{
    font-size: .84rem;

    padding: 9px;
  }


  .exam-nav .btn{
    font-size: .76rem;
  }

}


/* =========================================================
   MOBILE LANDSCAPE
   =========================================================

   Useful for phones in landscape orientation
   where vertical space is very limited.
   ========================================================= */

@media
  (max-height: 600px)
  and (orientation: landscape){

  .app{
    padding-top: 6px;
  }


  .topbar{
    padding-bottom: 8px;
  }


  .exam-head{
    margin-bottom: 8px;
  }


  .q-card{
    padding: 12px;
  }


  .q-img-wrap{
    max-height: 120px;
  }


  .q-img-wrap img{
    height: 120px;
  }


  .q-text{
    font-size: .95rem;

    line-height: 1.5;

    margin-bottom: 10px;
  }


  .answer{
    padding:
      8px
      10px;
  }


  .exam-nav{
    margin-top: 8px;
  }

}