/* TeoMath Math Comments v1.0.0 */
.tmmc-comment-form-comment {
  --tmmc-border: #d7dce4;
  --tmmc-border-strong: #aab4c2;
  --tmmc-bg: #ffffff;
  --tmmc-bg-soft: #f7f9fc;
  --tmmc-text: #172033;
  --tmmc-muted: #667085;
  --tmmc-accent: #1769e0;
  --tmmc-accent-soft: #eaf2ff;
  --tmmc-danger: #b42318;
  --tmmc-radius: 12px;
}

.tmmc-source-textarea {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.tmmc-shell {
  width: 100%;
  max-width: 100%;
  color: var(--tmmc-text);
  color-scheme: light;
  font: inherit;
}

.tmmc-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 6px;
  border: 1px solid var(--tmmc-border);
  border-bottom: 0;
  border-radius: var(--tmmc-radius) var(--tmmc-radius) 0 0;
  background: var(--tmmc-bg-soft);
}

.tmmc-toolbar-btn,
.tmmc-emoji-btn,
.tmmc-symbol-btn,
.tmmc-tab-btn,
.tmmc-mode-btn,
.tmmc-secondary-btn,
.tmmc-danger-btn,
.tmmc-insert-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  text-transform: none;
}

.tmmc-toolbar-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 32px;
  font-size: 17px;
}

.tmmc-toolbar-btn:hover,
.tmmc-toolbar-btn:focus-visible,
.tmmc-emoji-btn:hover,
.tmmc-emoji-btn:focus-visible,
.tmmc-symbol-btn:hover,
.tmmc-symbol-btn:focus-visible,
.tmmc-tab-btn:hover,
.tmmc-tab-btn:focus-visible,
.tmmc-mode-btn:hover,
.tmmc-mode-btn:focus-visible {
  border-color: var(--tmmc-border);
  background: #fff;
  outline: none;
}

.tmmc-comment-editor {
  min-height: 150px;
  padding: 14px 15px;
  border: 1px solid var(--tmmc-border);
  border-radius: 0 0 var(--tmmc-radius) var(--tmmc-radius);
  background: var(--tmmc-bg);
  color: var(--tmmc-text);
  line-height: 1.65;
  overflow-wrap: anywhere;
  cursor: text;
}

.tmmc-comment-editor:focus {
  border-color: var(--tmmc-accent);
  outline: 3px solid color-mix(in srgb, var(--tmmc-accent) 18%, transparent);
  outline-offset: -1px;
}

.tmmc-comment-editor:empty::before {
  content: attr(data-placeholder);
  color: #98a2b3;
  pointer-events: none;
}

.tmmc-emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--tmmc-border);
  border-bottom: 0;
  background: #fff;
}

.tmmc-emoji-panel[hidden] { display: none !important; }

.tmmc-emoji-btn {
  width: 34px;
  height: 34px;
  font-size: 20px;
}

.tmmc-status {
  min-height: 1.2em;
  margin: 7px 2px 0;
  font-size: 13px;
  color: var(--tmmc-muted);
}

.tmmc-status.is-error { color: var(--tmmc-danger); }
.tmmc-status.is-ok { color: #067647; }

.tmmc-math-panel {
  margin-top: 12px;
  border: 1px solid var(--tmmc-border);
  border-radius: var(--tmmc-radius);
  background: #fff;
  overflow: visible;
}

.tmmc-math-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px 9px;
  border-bottom: 1px solid var(--tmmc-border);
  background: var(--tmmc-bg-soft);
  border-radius: var(--tmmc-radius) var(--tmmc-radius) 0 0;
}

.tmmc-math-title {
  font-weight: 700;
  font-size: 15px;
}

.tmmc-math-help {
  margin-top: 3px;
  color: var(--tmmc-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.tmmc-math-field-wrap {
  padding: 12px;
}

.tmmc-math-field {
  display: block;
  width: 100%;
  min-height: 68px;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid var(--tmmc-border-strong);
  border-radius: 10px;
  background: #fff;
  font-size: clamp(20px, 3vw, 28px);
  --caret-color: var(--tmmc-accent);
  --selection-background-color: #cfe1ff;
}

.tmmc-math-field:focus-within {
  border-color: var(--tmmc-accent);
  outline: 3px solid color-mix(in srgb, var(--tmmc-accent) 18%, transparent);
}

.tmmc-math-field::part(menu-toggle) {
  display: none;
}

.tmmc-math-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 0 12px 9px;
  scrollbar-width: thin;
}

.tmmc-tab-btn {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-color: var(--tmmc-border);
  color: var(--tmmc-muted);
  background: #fff;
  font-size: 12.5px;
}

.tmmc-tab-btn.is-active {
  border-color: #b8d0f6;
  background: var(--tmmc-accent-soft);
  color: #134f9e;
  font-weight: 700;
}

.tmmc-math-palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 6px;
  padding: 0 12px 12px;
}

.tmmc-symbol-btn {
  min-height: 40px;
  padding: 7px 8px;
  border-color: var(--tmmc-border);
  background: #fff;
  font-size: 15px;
}

.tmmc-math-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--tmmc-border);
  background: var(--tmmc-bg-soft);
  border-radius: 0 0 var(--tmmc-radius) var(--tmmc-radius);
}

.tmmc-mode-group,
.tmmc-action-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.tmmc-mode-btn,
.tmmc-secondary-btn,
.tmmc-danger-btn,
.tmmc-insert-btn {
  min-height: 36px;
  padding: 9px 12px;
  border-color: var(--tmmc-border);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
}

.tmmc-mode-btn.is-active {
  border-color: #b8d0f6;
  background: var(--tmmc-accent-soft);
  color: #134f9e;
}

.tmmc-insert-btn {
  border-color: var(--tmmc-accent);
  background: var(--tmmc-accent);
  color: #fff;
}

.tmmc-insert-btn:hover,
.tmmc-insert-btn:focus-visible {
  filter: brightness(.94);
}

.tmmc-danger-btn {
  border-color: #f3b7b2;
  color: var(--tmmc-danger);
}

.tmmc-math-unavailable {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--tmmc-border-strong);
  border-radius: 9px;
  color: var(--tmmc-muted);
  font-size: 13px;
}

.tmmc-math-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  margin: 0 3px;
  padding: 2px 5px;
  border: 1px solid transparent;
  border-radius: 7px;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  background: transparent;
}

.tmmc-math-chip:hover,
.tmmc-math-chip:focus,
.tmmc-math-chip.is-editing {
  border-color: #b8d0f6;
  background: var(--tmmc-accent-soft);
  outline: none;
}

.tmmc-math-chip.is-display {
  display: flex;
  width: 100%;
  justify-content: center;
  margin: 8px 0;
  padding: 7px 8px;
  overflow-x: auto;
}

.tmmc-math-preview {
  pointer-events: none;
  border: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  min-width: 0;
  font-size: 1.05em;
}

.tmmc-math-preview::part(menu-toggle),
.tmmc-math-preview::part(virtual-keyboard-toggle) {
  display: none;
}

@media (max-width: 720px) {
  .tmmc-comment-editor {
    min-height: 130px;
    padding: 12px;
  }

  .tmmc-math-head {
    padding: 10px 11px 8px;
  }

  .tmmc-math-field-wrap {
    padding: 10px;
  }

  .tmmc-math-tabs {
    padding: 0 10px 8px;
  }

  .tmmc-math-palette {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 0 10px 10px;
  }

  .tmmc-symbol-btn {
    min-height: 42px;
    padding: 6px 4px;
  }

  .tmmc-math-controls {
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }

  .tmmc-mode-group,
  .tmmc-action-group {
    width: 100%;
  }

  .tmmc-mode-btn {
    flex: 1 1 0;
  }

  .tmmc-insert-btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 420px) {
  .tmmc-math-palette {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tmmc-action-group > button {
    flex: 1 1 100%;
  }
}

/* v1.0.1: matrix n×m builder and stable light appearance. */
.tmmc-matrix-builder {
  margin: 0 12px 12px;
  padding: 10px;
  border: 1px dashed var(--tmmc-border-strong);
  border-radius: 10px;
  background: var(--tmmc-bg-soft);
}

.tmmc-matrix-builder[hidden] { display: none !important; }

.tmmc-matrix-builder-title {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tmmc-text);
}

.tmmc-matrix-builder-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr)) auto;
  gap: 8px;
  align-items: end;
}

.tmmc-matrix-control-label {
  display: grid;
  gap: 4px;
  margin: 0;
  color: var(--tmmc-muted);
  font-size: 11.5px;
  font-weight: 600;
}

.tmmc-matrix-number,
.tmmc-matrix-select {
  width: 100%;
  min-height: 38px;
  box-sizing: border-box;
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--tmmc-border);
  border-radius: 8px;
  background: #fff;
  color: var(--tmmc-text);
  color-scheme: light;
  font: inherit;
  font-size: 14px;
  box-shadow: none;
}

.tmmc-matrix-insert-btn {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--tmmc-accent);
  border-radius: 8px;
  background: #fff;
  color: var(--tmmc-accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  text-transform: none;
}

.tmmc-matrix-insert-btn:hover,
.tmmc-matrix-insert-btn:focus-visible {
  background: var(--tmmc-accent-soft);
  outline: none;
}

.tmmc-clear-btn {
  white-space: nowrap;
}

/* Never switch this plugin to a dark palette merely because the OS/browser
   prefers dark mode. TeoMath controls its own visual theme. */
.tmmc-shell,
.tmmc-toolbar,
.tmmc-comment-editor,
.tmmc-math-panel,
.tmmc-math-head,
.tmmc-math-field,
.tmmc-math-controls,
.tmmc-emoji-panel,
.tmmc-tab-btn,
.tmmc-symbol-btn,
.tmmc-mode-btn,
.tmmc-secondary-btn,
.tmmc-danger-btn {
  color-scheme: light;
}

@media (max-width: 782px) {
  html.tmmc-math-interaction-active .tmmc-mobile-float-suspend,
  html.tmmc-math-interaction-active .teomath-back-to-top,
  html.tmmc-math-interaction-active .tm-back-to-top,
  html.tmmc-math-interaction-active .back-to-top,
  html.tmmc-math-interaction-active .backtotop,
  html.tmmc-math-interaction-active .scroll-to-top,
  html.tmmc-math-interaction-active .scroll-top,
  html.tmmc-math-interaction-active .to-top,
  html.tmmc-math-interaction-active #back-to-top,
  html.tmmc-math-interaction-active #scroll-to-top,
  html.tmmc-math-interaction-active [data-back-to-top],
  html.tmmc-math-interaction-active [data-scroll-top] {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .tmmc-matrix-builder {
    margin: 0 10px 10px;
  }

  .tmmc-matrix-builder-controls {
    grid-template-columns: 1fr 1fr;
  }

  .tmmc-matrix-insert-btn {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 420px) {
  .tmmc-matrix-builder-controls {
    grid-template-columns: 1fr 1fr;
  }

  .tmmc-matrix-control-label:nth-of-type(3) {
    grid-column: 1 / -1;
  }
}

