:root {
  --memorize-dark-bg: #181a1b;
  --memorize-dark-panel: #1f2223;
  --memorize-dark-panel-alt: #242728;
  --memorize-dark-border: #3b4043;
  --memorize-dark-text: #bfb8ae;
  --memorize-dark-muted: #9d978f;
  --memorize-dark-primary: #4f84c4;
  --memorize-dark-primary-hover: #6695ce;
  --memorize-dark-info: #46759c;
  --memorize-dark-success: #5f8f6d;
  --memorize-dark-danger: #b86b63;
  --memorize-dark-warning: #b99054;
  --memorize-dark-shadow: rgba(0, 0, 0, 0.45);
}

.memorize-dark {
  background: var(--memorize-dark-bg);
  color: var(--memorize-dark-text);
  min-height: 100vh;
}

.memorize-dark .row {
  margin-top: 0;
}

.memorize-dark-toolbar,
.memorize-dark-search,
.memorize-dark .wrapper-md {
  background: var(--memorize-dark-bg);
  color: var(--memorize-dark-text);
}

.memorize-dark-toolbar {
  border-bottom: 1px solid var(--memorize-dark-border);
}

.memorize-dark .btn-group {
  margin-right: 10px;
  margin-bottom: 6px;
}

.memorize-dark .btn,
.memorize-dark-modal .btn {
  border-color: var(--memorize-dark-border);
  background: var(--memorize-dark-panel-alt);
  color: var(--memorize-dark-text);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.memorize-dark .btn:hover,
.memorize-dark .btn:focus,
.memorize-dark-modal .btn:hover,
.memorize-dark-modal .btn:focus {
  background: #2b2f31;
  border-color: #4a5054;
  color: #d5cfc7;
}

.memorize-dark .btn-primary,
.memorize-dark-modal .btn-primary {
  background: var(--memorize-dark-primary);
  border-color: #456f9f;
  color: #e2ddd5;
}

.memorize-dark .btn-primary:hover,
.memorize-dark .btn-primary:focus,
.memorize-dark-modal .btn-primary:hover,
.memorize-dark-modal .btn-primary:focus {
  background: var(--memorize-dark-primary-hover);
  border-color: var(--memorize-dark-primary-hover);
}

.memorize-dark .btn-info,
.memorize-dark-modal .btn-info {
  background: var(--memorize-dark-info);
  border-color: #406989;
  color: #ddd8d0;
}

.memorize-dark .btn-success,
.memorize-dark-modal .btn-success {
  background: var(--memorize-dark-success);
  border-color: #51795d;
  color: #ddd8d0;
}

.memorize-dark .btn-danger,
.memorize-dark-modal .btn-danger {
  background: var(--memorize-dark-danger);
  border-color: #9e5c55;
  color: #e2ddd5;
}

.memorize-dark .btn[disabled],
.memorize-dark-modal .btn[disabled] {
  background: #2a2d2f;
  border-color: #34393b;
  color: #81878a;
}

.memorize-dark .form-control,
.memorize-dark-modal .form-control,
.memorize-dark-modal textarea,
.memorize-dark-modal input {
  background: #121415;
  border: 1px solid var(--memorize-dark-border);
  color: var(--memorize-dark-text);
  box-shadow: none;
}

.memorize-dark .form-control:focus,
.memorize-dark-modal .form-control:focus {
  border-color: var(--memorize-dark-primary);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.15);
}

.memorize-dark .form-control::placeholder,
.memorize-dark-modal .form-control::placeholder {
  color: #8b9498;
}

.memorize-dark .panel,
.memorize-dark-panel,
.memorize-dark-modal .modal-content {
  background: var(--memorize-dark-panel);
  border: 1px solid var(--memorize-dark-border);
  color: var(--memorize-dark-text);
  box-shadow: 0 18px 40px var(--memorize-dark-shadow);
}

.memorize-dark .panel-heading,
.memorize-dark .panel-body,
.memorize-dark-modal .panel-heading,
.memorize-dark-modal .panel-body,
.memorize-dark-modal .modal-header,
.memorize-dark-modal .modal-body,
.memorize-dark-modal .modal-footer,
.memorize-dark-dialog {
  background: var(--memorize-dark-panel);
  color: var(--memorize-dark-text);
  border-color: var(--memorize-dark-border);
}

.memorize-dark .table,
.memorize-dark .table > thead > tr > th,
.memorize-dark .table > tbody > tr > td {
  color: var(--memorize-dark-text);
  border-color: var(--memorize-dark-border);
}

.memorize-dark .table > thead > tr > th {
  background: #1d2021;
  font-weight: 600;
}

.memorize-dark .table-striped > tbody > tr:nth-child(odd) > td,
.memorize-dark .table-striped > tbody > tr:nth-child(odd) > th {
  background: #1d2021;
}

.memorize-dark .table-striped > tbody > tr:nth-child(even) > td,
.memorize-dark .table-striped > tbody > tr:nth-child(even) > th {
  background: #202324;
}

.memorize-dark .table-hover > tbody > tr:hover > td,
.memorize-dark .table-hover > tbody > tr:hover > th,
.memorize-dark .table > tbody > tr:hover > td,
.memorize-dark .table > tbody > tr:hover > th {
  background: #262a2c;
}

.memorize-dark a,
.memorize-dark-modal a {
  color: #6d90bb;
}

.memorize-dark a:hover,
.memorize-dark-modal a:hover {
  color: #81a4cd;
}

.memorize-dark .text-danger,
.memorize-dark-modal .text-danger {
  color: #c07b74;
}

.memorize-dark .text-success,
.memorize-dark-modal .text-success {
  color: #7fa187;
}

.memorize-dark .text-primary,
.memorize-dark-modal .text-primary {
  color: #7899bf;
}

.memorize-markdown-block {
  margin-bottom: 18px;
}

.memorize-markdown-preview {
  min-height: 0;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--memorize-dark-text);
  line-height: 1.7;
  word-break: break-word;
  white-space: normal;
}

.memorize-markdown-preview > :first-child {
  margin-top: 0;
}

.memorize-markdown-preview > :last-child {
  margin-bottom: 0;
}

.memorize-markdown-preview p,
.memorize-markdown-preview ul,
.memorize-markdown-preview ol,
.memorize-markdown-preview blockquote,
.memorize-markdown-preview pre {
  margin-bottom: 12px;
}

.memorize-markdown-preview ul,
.memorize-markdown-preview ol {
  padding-left: 22px;
}

.memorize-markdown-preview li + li {
  margin-top: 4px;
}

.memorize-markdown-preview blockquote {
  padding-left: 12px;
  border-left: 3px solid #3f6587;
  color: var(--memorize-dark-muted);
  font-size: inherit;
}

.memorize-markdown-preview code {
  padding: 1px 4px;
  background: #1d2021;
  border-radius: 3px;
  color: #d7d1c8;
}

.memorize-markdown-preview pre {
  padding: 10px 12px;
  background: #1d2021;
  border: 1px solid #2e3335;
  border-radius: 4px;
  overflow-x: auto;
}

.memorize-markdown-preview pre code {
  padding: 0;
  background: transparent;
}

.memorize-markdown-preview .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

.memorize-markdown-preview .katex {
  color: #ddd8d0;
}

.memorize-markdown-preview .mermaid {
  margin-bottom: 12px;
  text-align: center;
  overflow-x: auto;
}

.memorize-markdown-preview .mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Mermaid in-place zoom + pan (no fullscreen button). */
.mermaid-viewer {
  position: relative;
  text-align: center;
}

.mermaid-viewer .mermaid-stage {
  overflow: hidden;
  cursor: grab;
}

.mermaid-viewer .mermaid-stage.dragging {
  cursor: grabbing;
}

.mermaid-viewer .mermaid-stage svg {
  transition: transform 0.08s ease-out;
  transform-origin: center center;
}

.mermaid-viewer .mermaid-zoom-controls {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 10;
  display: flex;
  gap: 6px;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.mermaid-viewer:hover .mermaid-zoom-controls {
  opacity: 1;
}

.mermaid-viewer .mermaid-zoom-controls .btn {
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  line-height: 28px;
  text-align: center;
  border: 1px solid var(--memorize-dark-border);
  border-radius: 4px;
  background: rgba(20, 22, 26, 0.75);
  color: var(--memorize-dark-text);
}

/* Content/answer box web fullscreen (CSS overlay, NOT system fullscreen). */
.memorize-content-box {
  position: relative;
}

.memorize-content-fullscreen-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 20;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--memorize-dark-border);
  border-radius: 4px;
  background: rgba(20, 22, 26, 0.6);
  color: var(--memorize-dark-muted);
  line-height: 28px;
  text-align: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.memorize-content-box:hover .memorize-content-fullscreen-btn,
.memorize-content-fullscreen-btn:hover {
  opacity: 1;
}

.memorize-content-box.memorize-content-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  margin: 0;
  padding: 0;
  overflow: auto;
  background: var(--memorize-dark-bg);
  border: 0;
}

.memorize-content-box.memorize-content-fullscreen .memorize-content-fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  border: 0;
  opacity: 1;
}

.memorize-markdown-preview table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 12px;
  border-collapse: collapse;
  border: 1px solid var(--memorize-dark-border);
  overflow-x: auto;
  display: block;
}

.memorize-markdown-preview table th,
.memorize-markdown-preview table td {
  padding: 6px 10px;
  border: 1px solid var(--memorize-dark-border);
  vertical-align: top;
}

.memorize-markdown-preview table th {
  background: var(--memorize-dark-panel-alt);
  font-weight: 600;
}

.memorize-markdown-preview table thead tr {
  background: var(--memorize-dark-panel-alt);
}

.memorize-markdown-preview table tbody tr:nth-child(even) {
  background: var(--memorize-dark-panel);
}

.memorize-dark .label.bg-primary {
  background: var(--memorize-dark-primary);
}

.memorize-dark .label.bg-danger {
  background: var(--memorize-dark-danger);
}

.memorize-dark .label.bg-success {
  background: var(--memorize-dark-success);
}

.memorize-dark .pagination > li > a,
.memorize-dark .pagination > li > span {
  background: var(--memorize-dark-panel-alt);
  border-color: var(--memorize-dark-border);
  color: var(--memorize-dark-text);
}

.memorize-dark .pagination > .active > a,
.memorize-dark .pagination > .active > span,
.memorize-dark .pagination > .active > a:hover,
.memorize-dark .pagination > .active > span:hover,
.memorize-dark .pagination > .active > a:focus,
.memorize-dark .pagination > .active > span:focus {
  background: var(--memorize-dark-primary);
  border-color: var(--memorize-dark-primary);
  color: #ffffff;
}

.memorize-dark .pagination > li > a:hover,
.memorize-dark .pagination > li > span:hover {
  background: #2b2f31;
  border-color: #4c5356;
}

.memorize-dark-switch.bg-info,
.memorize-dark .i-switch.bg-info {
  background: #2f3436;
}

.memorize-dark .i-switch i:before {
  background-color: #5f6b70;
}

.memorize-dark .i-switch input:checked + i {
  background-color: var(--memorize-dark-primary);
}

/* autoNext switch on the same row as the search input */
.memorize-dark-search .memorize-search-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.memorize-dark-search .memorize-search-row .form-control {
  flex: 1 1 auto;
  width: auto;
  background: var(--memorize-dark-panel-alt);
  border-color: var(--memorize-dark-border);
  color: var(--memorize-dark-text);
}
.memorize-dark-search .memorize-search-row .i-switch {
  flex: 0 0 auto;
  margin: 0;
}

.memorize-dark-modal .modal-dialog {
  color: var(--memorize-dark-text);
}

.memorize-dark-modal .modal-content {
  border-radius: 10px;
}

.memorize-dark-modal .modal-header,
.memorize-dark-modal .modal-footer {
  border-color: var(--memorize-dark-border);
}

.memorize-dark-modal .modal-title,
.memorize-dark-modal label,
.memorize-dark-modal .help-block,
.memorize-dark-modal p,
.memorize-dark-modal strong {
  color: var(--memorize-dark-text);
}

.memorize-dark-modal .help-block {
  color: var(--memorize-dark-muted);
}

.memorize-dark-modal .close {
  color: var(--memorize-dark-text);
  opacity: 0.75;
}

.memorize-dark-modal .close:hover {
  color: #ffffff;
  opacity: 1;
}

.memorize-dark .toast,
.memorize-dark-modal .toast {
  background: var(--memorize-dark-panel);
  color: var(--memorize-dark-text);
  border: 1px solid var(--memorize-dark-border);
  box-shadow: 0 10px 30px var(--memorize-dark-shadow);
}

.memorize-dark .toast-success,
.memorize-dark-modal .toast-success {
  background: #1f3426;
}

.memorize-dark .toast-error,
.memorize-dark-modal .toast-error {
  background: #3a2020;
}

.memorize-dark .toast-warning,
.memorize-dark-modal .toast-warning {
  background: #3d3020;
}

.memorize-dark .toast-info,
.memorize-dark-modal .toast-info {
  background: #1f2f3d;
}

.memorize-dark-modal #compare,
.memorize-dark-modal .mergely-column,
.memorize-dark-modal .mergely-column .CodeMirror,
.memorize-dark-modal .CodeMirror,
.memorize-dark-modal .cm-s-default {
  background: #111314 !important;
  color: var(--memorize-dark-text) !important;
}

.memorize-dark-modal .CodeMirror-gutters,
.memorize-dark-modal .mergely-margin,
.memorize-dark-modal .CodeMirror-scrollbar-filler,
.memorize-dark-modal .CodeMirror-gutter-filler {
  background: #1b1e1f !important;
  border-color: var(--memorize-dark-border) !important;
}

.memorize-dark-modal .CodeMirror-linenumber {
  color: #8b9498 !important;
}

.memorize-dark-modal .mergely-column {
  border-color: var(--memorize-dark-border) !important;
}

.memorize-dark-modal .mergely-column textarea {
  background: #111314 !important;
  color: var(--memorize-dark-text) !important;
  caret-color: var(--memorize-dark-text) !important;
}

.memorize-dark-modal .CodeMirror-code {
  color: var(--memorize-dark-text) !important;
}

.memorize-dark-modal .CodeMirror-cursor {
  border-left-color: var(--memorize-dark-text) !important;
}

.memorize-dark-modal .mergely.a,
.memorize-dark-modal .mergely.d,
.memorize-dark-modal .mergely.c {
  color: var(--memorize-dark-text) !important;
}

.memorize-dark-modal .mergely.c.lhs,
.memorize-dark-modal .mergely.c.rhs {
  background-color: #1d2021 !important;
}

.memorize-dark-modal .mergely.a.rhs,
.memorize-dark-modal .mergely.ch.a.rhs {
  background-color: #1d3147 !important;
}

.memorize-dark-modal .mergely.d.lhs,
.memorize-dark-modal .mergely.ch.d.lhs {
  background-color: #3a2523 !important;
  color: #c07b74 !important;
}

.memorize-dark-modal .mergely.a.rhs.start,
.memorize-dark-modal .mergely.a.lhs.start.end,
.memorize-dark-modal .mergely.a.rhs.end {
  border-color: #4f6f91 !important;
}

.memorize-dark-modal .mergely.d.lhs.end,
.memorize-dark-modal .mergely.d.rhs.start.end,
.memorize-dark-modal .mergely.d.rhs.start.end.first,
.memorize-dark-modal .mergely.d.lhs.start {
  border-color: #6d4d4a !important;
}

.memorize-dark-modal .mergely.c.lhs.start,
.memorize-dark-modal .mergely.c.rhs.start,
.memorize-dark-modal .mergely.c.lhs.end,
.memorize-dark-modal .mergely.c.rhs.end {
  border-color: #4a5054 !important;
}

@media (max-width: 767px) {
  .memorize-dark-search .col-md-3 {
    margin-bottom: 12px;
  }

  /* Stack category groups vertically so wrapped rows never overlap or get clipped */
  .memorize-dark-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  /* Each button group wraps naturally; buttons stay connected (bootstrap -1px margin) */
  .memorize-dark-toolbar .btn-group {
    display: block;
    margin-right: 0;
    margin-bottom: 0;
  }

  /* Compact touch sizing on mobile */
  .memorize-dark-toolbar .btn {
    min-height: 26px;
    padding: 2px 7px;
    font-size: 11px;
    line-height: 1.2;
  }

  /* Level-2 sub-category buttons: even smaller */
  .memorize-dark-toolbar .btn-group .btn-xs {
    min-height: 22px;
    padding: 1px 5px;
    font-size: 10px;
    line-height: 1.1;
  }

  .memorize-dark-toolbar .memorize-dark-switch {
    align-self: flex-start;
    margin-top: 2px;
  }

  .memorize-dark-modal.modal-full-screen .modal-header,
  .memorize-dark-modal.modal-full-screen .modal-footer {
    background: var(--memorize-dark-panel);
    border-color: var(--memorize-dark-border);
  }
}

/* ===== Standalone full-screen test page (Anki-like) ===== */
.memorize-test-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  background: var(--memorize-dark-bg);
  color: var(--memorize-dark-text);
}

.memorize-test-page .test-page-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--memorize-dark-panel);
  border-bottom: 1px solid var(--memorize-dark-border);
}

.memorize-test-page .test-page-back {
  color: var(--memorize-dark-text);
  text-decoration: none;
}

.memorize-test-page .test-page-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.memorize-test-page .test-page-successive {
  flex: 0 0 auto;
}

.memorize-test-page .test-page-nexttime {
  font-size: 13px;
  color: var(--memorize-dark-muted);
  white-space: nowrap;
}

.memorize-test-page .test-page-divider {
  border: 0;
  border-top: 1px dashed var(--memorize-dark-border);
  margin: 16px 0;
}

.memorize-test-page .test-page-content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.memorize-test-page .test-page-content .memorize-markdown-preview {
  background: var(--memorize-dark-panel);
  border: 1px solid var(--memorize-dark-border);
  border-radius: 4px;
  padding: 12px;
  width: 100%;
  box-sizing: border-box;
}

.memorize-test-page .test-page-compare,
.memorize-test-page .test-page-compare #compare {
  height: 100%;
  min-height: 320px;
}

/* Floating one-handed action button: bottom-right, low-opacity, large tap target. */
.memorize-test-page .test-page-fab {
  position: fixed;
  right: 16px;
  bottom: 88px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--memorize-dark-border);
  background: var(--memorize-dark-panel);
  color: var(--memorize-dark-text);
  opacity: 0.5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  z-index: 3001;
  cursor: pointer;
}
.memorize-test-page .test-page-fab:active {
  opacity: 0.8;
}

/* Dark theme for the mergely/CodeMirror compare editor (mirrors .memorize-dark-modal). */
.memorize-test-page #compare,
.memorize-test-page .mergely-column,
.memorize-test-page .mergely-column .CodeMirror,
.memorize-test-page .CodeMirror,
.memorize-test-page .cm-s-default {
  background: #111314 !important;
  color: var(--memorize-dark-text) !important;
}
.memorize-test-page .CodeMirror-gutters,
.memorize-test-page .mergely-margin,
.memorize-test-page .CodeMirror-scrollbar-filler,
.memorize-test-page .CodeMirror-gutter-filler {
  background: #1b1e1f !important;
  border-color: var(--memorize-dark-border) !important;
}
.memorize-test-page .CodeMirror-linenumber {
  color: #8b9498 !important;
}
.memorize-test-page .mergely-column {
  border-color: var(--memorize-dark-border) !important;
}
.memorize-test-page .mergely-column textarea {
  background: #111314 !important;
  color: var(--memorize-dark-text) !important;
  caret-color: var(--memorize-dark-text) !important;
}
.memorize-test-page .CodeMirror-code {
  color: var(--memorize-dark-text) !important;
}
.memorize-test-page .CodeMirror-cursor {
  border-left-color: var(--memorize-dark-text) !important;
}
.memorize-test-page .mergely.a,
.memorize-test-page .mergely.d,
.memorize-test-page .mergely.c {
  color: var(--memorize-dark-text) !important;
}
.memorize-test-page .mergely.c.lhs,
.memorize-test-page .mergely.c.rhs {
  background-color: #1d2021 !important;
}
.memorize-test-page .mergely.a.rhs,
.memorize-test-page .mergely.ch.a.rhs {
  background-color: #1d3147 !important;
}
.memorize-test-page .mergely.d.lhs,
.memorize-test-page .mergely.ch.d.lhs {
  background-color: #3a2523 !important;
  color: #c07b74 !important;
}
.memorize-test-page .mergely.a.rhs.start,
.memorize-test-page .mergely.a.lhs.start.end,
.memorize-test-page .mergely.a.rhs.end {
  border-color: #4f6f91 !important;
}
.memorize-test-page .mergely.d.lhs.end,
.memorize-test-page .mergely.d.rhs.start.end,
.memorize-test-page .mergely.d.rhs.start.end.first,
.memorize-test-page .mergely.d.lhs.start {
  border-color: #6d4d4a !important;
}
.memorize-test-page .mergely.c.lhs.start,
.memorize-test-page .mergely.c.rhs.start,
.memorize-test-page .mergely.c.lhs.end,
.memorize-test-page .mergely.c.rhs.end {
  border-color: #4a5054 !important;
}

.memorize-test-page .test-page-footer {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  padding: 8px 12px;
  background: var(--memorize-dark-panel);
  border-top: 1px solid var(--memorize-dark-border);
}

/* Action button groups: a single non-wrapping row that always fits,
   even when a view shows up to 5 buttons (Start/Pass/Reject/Back/Cancel). */
.memorize-test-page .test-page-footer > div > div {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.memorize-test-page .test-page-footer .btn {
  flex: 1 1 0;
  width: auto;
  margin: 0;
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile: true full-screen, no rounded corners, larger touch targets */
@media (max-width: 767px) {
  .memorize-test-page {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100vw;
    border-radius: 0;
  }
  .memorize-test-page .test-page-header,
  .memorize-test-page .test-page-footer {
    padding: 8px;
  }
  /* Mobile: content/answer boxes span the full screen width. */
  .memorize-test-page .test-page-content {
    padding: 12px 0;
  }
  .memorize-test-page .test-page-footer .btn {
    min-height: 40px;
    line-height: 1.4;
  }
}

/* PC: center the readable column, full-width sticky footer */
@media (min-width: 768px) {
  .memorize-test-page .test-page-content > div {
    max-width: 860px;
    margin: 0 auto;
  }
}
