/* RAM Review: layout and look follow the original Shiny app
   (Bootstrap 3 sidebar layout, same custom rules). */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.43;
  color: #333;
  background: #fff;
}

.container { max-width: 1170px; margin: 0 auto; padding: 0 15px; }
.title { font-size: 36px; font-weight: 500; margin: 20px 0 10px; }

.layout { display: flex; gap: 30px; align-items: flex-start; }
.sidebar {
  flex: 0 0 33%;
  background: #f5f5f5;
  border: 1px solid #e3e3e3;
  border-radius: 4px;
  padding: 19px;
  min-height: 20px;
}
.main { flex: 1 1 auto; min-width: 0; }

.sidebar-buttons { margin-top: 0.5em; }
.sidebar-buttons .btn { margin-bottom: 1em; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: bold; padding: 0; margin-bottom: 5px; font-size: 14px; }

.check { display: block; margin: 5px 0; }
.check label {
  display: inline-block;
  padding-left: 20px;
  text-indent: -20px;
  cursor: pointer;
  font-weight: normal;
}
.check input { margin: 0 4px 0 0; vertical-align: middle; }

/* Buttons (Bootstrap 3 colors) */
.btn {
  display: inline-block;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.43;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #333;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: #e6e6e6; }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn-primary { background: #337ab7; border-color: #2e6da4; color: #fff; }
.btn-primary:hover { background: #286090; }
.btn-success { background: #5cb85c; border-color: #4cae4c; color: #fff; }
.btn-success:hover { background: #449d44; }
.btn-warning { background: #f0ad4e; border-color: #eea236; color: #fff; }
.btn-warning:hover { background: #ec971f; }
.btn-info { background: #5bc0de; border-color: #46b8da; color: #fff; }
.btn-info:hover { background: #31b0d5; }
.btn-secondary { background: #fff; }

/* Same rules as the Shiny app's custom CSS */
#feedback, #question { margin-top: 2em; }
.question { margin-bottom: 1em; font-size: 1.2em; font-weight: bold; }
.options { width: 100%; }
#feedback { margin-bottom: 1em; min-height: 1.4em; }
#submit, #show_answer { margin-bottom: 0.5em; }
.report { margin-bottom: 1em; }
.report a { color: #337ab7; }
#mobile_next_ui { margin-bottom: 1em; }

.feedback-correct { color: green; font-weight: bolder; opacity: 0; transition: opacity 0.3s; }
.feedback-incorrect { color: red; font-weight: bolder; opacity: 0; transition: opacity 0.3s; }
.feedback-visible { opacity: 1 !important; }

#explanation_ui { margin-bottom: 10em; }
#explanation_ui p { margin-top: 0.5em; }
#explanation_ui .refs-head { margin-top: 3em; }

/* Cheat view */
.opt-correct { color: green; font-weight: bolder; }
.opt-wrong { color: lightgray; font-weight: lighter; }

.mobile-next-button { display: none; }
.load-error { color: #a94442; }

/* Phone-only pieces: hidden on wide screens, so the desktop layout is unchanged */
.topbar-score, .menu-button, .drawer-head, .drawer-backdrop, .empty-hint { display: none; }

/* Phones and small tablets: the topics list moves into a slide-out drawer
   opened from the Topics button, and text and buttons are sized for thumbs. */
@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { font-size: 16px; line-height: 1.45; }
  legend { font-size: 16px; }
  .container { padding: 0 12px; }

  /* Sticky top bar: title, score, Topics button */
  .topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 8px;
    margin: 0 -12px; padding: 8px 12px;
    background: #fff; border-bottom: 1px solid #e3e3e3;
  }
  .title {
    font-size: 19px; margin: 0; flex: 1 1 auto; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-score { display: flex; gap: 8px; flex: 0 0 auto; font-weight: bold; white-space: nowrap; }
  .score-right { color: #3c763d; }
  .score-wrong { color: #a94442; }
  .menu-button {
    display: inline-flex; align-items: center; gap: 8px;
    flex: 0 0 auto; min-height: 44px; padding: 0 10px;
    font: inherit; font-weight: 500; white-space: nowrap; color: #333;
    background: #f5f5f5; border: 1px solid #ccc; border-radius: 6px;
    cursor: pointer; touch-action: manipulation;
  }
  .menu-icon, .menu-icon::before, .menu-icon::after {
    display: block; width: 18px; height: 2px; background: #333; border-radius: 1px;
  }
  .menu-icon { position: relative; }
  .menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
  .menu-icon::before { top: -6px; }
  .menu-icon::after { top: 6px; }

  .layout { display: block; }

  /* The sidebar becomes a drawer from the left */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    width: 85%; max-width: 340px;
    margin: 0; padding: 0 16px 24px;
    border: 0; border-radius: 0; border-right: 1px solid #e3e3e3;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  body.topics-open .sidebar {
    transform: none; visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
  }
  body.topics-open { overflow: hidden; }
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0, 0, 0, 0.35);
  }
  .drawer-backdrop[hidden] { display: none; }
  .drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1;
    margin: 0 -16px 8px; padding: 8px 16px;
    background: #f5f5f5; border-bottom: 1px solid #e3e3e3;
  }
  .drawer-title { font-size: 18px; font-weight: bold; }
  .drawer-done { min-height: 40px; padding: 0 16px; }
  .sidebar #correct_count, .sidebar #incorrect_count { display: none; }
  .sidebar-buttons { display: flex; gap: 8px; margin: 4px 0 12px; }
  .sidebar-buttons .btn { flex: 1 1 0; margin: 0; }
  .topics legend { display: none; }

  .empty-hint { display: block; margin-top: 2em; color: #666; }
  .empty-hint[hidden] { display: none; }

  /* Buttons: thumb-sized, no giant margins */
  .btn { min-height: 44px; font-size: 16px; line-height: 1.2; padding: 10px 12px; }
  .nav-buttons, .answer-buttons { display: flex; gap: 10px; }
  .nav-buttons .btn, .answer-buttons .btn { flex: 1 1 0; margin: 0; }
  .nav-buttons { margin-top: 0.75em; }
  .answer-buttons { margin-bottom: 1em; }
  .mobile-next-button { display: block; width: 100%; margin-top: 1em; }

  /* Question and choices */
  .main { padding-top: 12px; scroll-margin-top: 64px; }
  #question_counter, #current_topic { color: #666; font-size: 14px; }
  #current_topic + br { display: none; }
  #question { margin-top: 1em; }
  .question { font-size: 18px; line-height: 1.4; }
  #feedback { margin-top: 1em; }

  /* Each choice (and each topic) is a full-width tap target */
  .check { margin: 0; }
  .check label {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 4px; text-indent: 0;
    border-bottom: 1px solid #eee;
  }
  .options .check label {
    padding: 12px; margin-bottom: 8px;
    border: 1px solid #ddd; border-radius: 6px; background: #fff;
  }
  .check input[type="checkbox"] {
    flex: 0 0 auto; width: 22px; height: 22px; margin: 1px 0 0;
  }

  #explanation_ui { margin-bottom: 4em; }
  #explanation_ui .refs-head { margin-top: 1.5em; }
  #explanation_ui ul { padding-left: 1.2em; overflow-wrap: anywhere; }
  .report { font-size: 14px; }
}
