/* A single, quiet surface. All rules stay scoped to the injected trex panel. */
#trex-overlay {
  --trex-paper: #fbfaf7;
  --trex-ink: #262723;
  --trex-muted: #6c6e65;
  --trex-rule: #e2e1db;
  position: fixed;
  width: 320px;
  min-width: min(260px, calc(100vw - 16px));
  min-height: min(320px, calc(100vh - 16px));
  z-index: 9999999;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.45;
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
  color: var(--trex-ink);
  color-scheme: light;
  transition: opacity 120ms, transform 120ms;
}
#trex-overlay, #trex-overlay * { box-sizing: border-box; }
#trex-overlay [hidden] { display: none !important; }
#trex-overlay svg { display: block; width: 16px; height: 16px; flex: none; }
:where(#trex-overlay) button, #trex-toggle-hint {
  appearance: none;
  margin: 0;
  font: inherit;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  -webkit-tap-highlight-color: transparent;
}
#trex-overlay button:focus-visible, #trex-overlay a:focus-visible, #trex-toggle-hint:focus-visible {
  outline: 2px solid #646d57;
  outline-offset: 3px;
}
#trex-overlay button:disabled { cursor: default; }
#trex-overlay.trex-hidden { opacity: 0; transform: translateY(4px); pointer-events: none; }
#trex-panel {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #26272340;
  border-radius: 8px;
  background: var(--trex-paper);
  box-shadow: 0 10px 30px #20282124, 0 2px 6px #20282112;
}
#trex-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px 0 20px;
  border-bottom: 1px solid var(--trex-rule);
  cursor: grab;
  user-select: none;
}
#trex-header:active { cursor: grabbing; }
#trex-header, #trex-resize-handle { touch-action:none; }
#trex-logo-text {
  color: var(--trex-ink);
  font: italic 700 25px/1 Georgia, 'Times New Roman', serif;
  letter-spacing: -1.5px;
}
#trex-logo-text > span { color: #7c8667; }
#trex-overlay .trex-window-tools { display: flex; align-items: center; gap: 8px; }
#trex-overlay .trex-key-hint {
  padding: 1px 4px;
  border: 1px solid var(--trex-rule);
  border-radius: 3px;
  color: #888981;
  font: 10px/15px 'SFMono-Regular', Consolas, monospace;
}
#trex-overlay .trex-icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--trex-muted);
  transition: background 120ms, color 120ms;
}
#trex-overlay .trex-icon-btn:hover { background: #eeede7; color: var(--trex-ink); }
#trex-overlay .trex-icon-btn:disabled { opacity: .4; }
#trex-lesson-settings {
  padding: 10px 20px;
  border-bottom: 1px solid var(--trex-rule);
  background: #f4f2ed;
}
#trex-lesson-settings button, #trex-score-reset-dialog button {
  padding: 7px 11px;
  border: 1px solid #cdcabf;
  border-radius: 4px;
  background: var(--trex-paper);
  color: var(--trex-ink);
  font-size: 12px;
}
#trex-open-score-reset, #trex-stop-score-reset { color: #873623 !important; }
#trex-score-reset-status { margin: 6px 0 0; font-size: 11px; }
#trex-score-reset-status:empty { display: none; }
#trex-repeat-settings {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--trex-rule);
  font-size: 12px;
}
#trex-repeat-count {
  box-sizing: border-box;
  width: 58px;
  padding: 5px;
  border: 1px solid var(--trex-rule);
  border-radius: 4px;
  font: inherit;
}
#trex-repeat-help, #trex-repeat-status { grid-column: 1 / -1; margin: 0; font-size: 11px; }
#trex-repeat-help { color: var(--trex-muted); }
#trex-repeat-status:empty { display: none; }
#trex-score-reset-dialog {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 20px;
  border: 1px solid #cdcabf;
  border-radius: 8px;
  background: var(--trex-paper);
  color: var(--trex-ink);
}
#trex-score-reset-dialog::backdrop { background: #26272375; }
#trex-score-reset-dialog h2 { margin: 0 0 8px; font-size: 17px; }
#trex-score-reset-dialog p { margin: 0 0 16px; }
#trex-score-reset-dialog input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid #cdcabf;
  border-radius: 4px;
  font: inherit;
}
#trex-score-reset-dialog .trex-reset-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#trex-score-reset-dialog #trex-confirm-score-reset { background: #873623; color: white; border-color: #873623; }
#trex-score-reset-dialog #trex-confirm-score-reset:disabled { opacity: .48; }
#trex-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: #c7c8bd transparent;
}
#trex-answer-card {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 148px;
  overflow: hidden;
  color: var(--trex-ink);
}
#trex-answer-toolbar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 30px;
  margin-top: 4px;
  padding: 0 14px 0 20px;
}
#trex-answer-label { color: var(--trex-muted); font-size: 11px; font-weight: 500; }
#trex-overlay .trex-answer-tools { display: flex; align-items: center; gap: 4px; }
#trex-copy-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 28px;
  padding: 4px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--trex-muted);
  font-size: 11px;
  font-weight: 400;
}
#trex-copy-answer:hover { color: var(--trex-ink); background: #eeede7; }
#trex-copy-answer svg { width: 12px; height: 12px; }
#trex-answer-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 20px 8px;
  color: var(--trex-muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: #c7c8bd transparent;
}
#trex-answer-card[data-state='idle'] #trex-answer-area { max-width: 260px; padding-top: 14px; color: #707267; }
#trex-answer-area.has-answer {
  color: var(--trex-ink);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 21px;
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: -.6px;
  font-variant-numeric: tabular-nums;
}
#trex-overlay .trex-answer-line { display: block; padding: 0; line-height: 32px; white-space: pre-wrap; }
#trex-answer-area.has-answer.trex-prose-answer { font-family:inherit; font-size:15px; line-height:1.65; letter-spacing:normal; }
#trex-overlay .trex-ordered-answer { margin: 0; padding-inline-start: 1.35em; white-space: normal; }
#trex-overlay .trex-ordered-answer li + li { margin-top: 0.6em; }
#trex-overlay .trex-vertex-label {
  display: inline-block;
  min-width: 27px;
  color: #5a6550;
  font: italic 23px/32px Georgia, 'Times New Roman', serif;
  letter-spacing: -.8px;
}
#trex-overlay .trex-coordinate-value { color: var(--trex-ink); }
#trex-answer-area.loading { padding-top: 14px; color: var(--trex-muted); }
#trex-cooldown-countdown {
  padding: 4px 20px 0;
  color: #5a6550;
  font: 500 29px/1.2 'SFMono-Regular', Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
#trex-answer-card[data-state='error'] #trex-answer-label { color: #a25139; }
#trex-answer-card[data-state='error'] #trex-answer-area { padding-top: 14px; color: #a25139; }
#trex-answer-card[data-state='changed'] #trex-answer-area { padding-top: 14px; }
#trex-overlay .trex-progress { display: none; position: absolute; bottom: 0; left: 20px; width: calc(100% - 40px); height: 1px; overflow: hidden; background: var(--trex-rule); }
#trex-answer-card[aria-busy='true'] .trex-progress { display: block; }
#trex-overlay .trex-progress span { display: block; width: 40%; height: 100%; background: #7c8667; animation: trex-progress 1.6s ease-in-out infinite; }
#trex-controls { flex: none; padding: 12px 20px; }
#trex-get-answer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  width: 100%;
  height: 40px;
  padding: 0 13px;
  border: 1px solid #262723;
  border-radius: 4px;
  background: #262723;
  color: #fbfaf7;
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms;
}
#trex-get-answer:hover:not(:disabled) { background: #42453a; border-color: #42453a; }
#trex-get-answer:active:not(:disabled) { background: #171813; }
#trex-get-answer.loading { background: #54574d; border-color: #54574d; }
#trex-overlay .trex-action-arrow { display: grid; place-items: center; }
#trex-overlay .trex-spinner { display: none; width: 14px; height: 14px; border: 1.5px solid #fbfaf74d; border-top-color: #fbfaf7; border-radius: 50%; animation: trex-spin 800ms linear infinite; }
#trex-get-answer.loading .trex-action-arrow svg { display: none; }
#trex-get-answer.loading .trex-spinner { display: block; }
#trex-auto-answer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 20px; margin-top: 12px; }
#trex-overlay .trex-auto-label { margin: 0; color: var(--trex-muted); font-size: 11px; font-weight: 400; cursor: pointer; }
#trex-overlay .trex-switch { position: relative; display: inline-block; width: 28px; height: 16px; flex: none; margin: 0; padding: 0; }
#trex-auto-answer-toggle { position: absolute; inset: -4px 0; width: 100%; height: 24px; padding: 0; margin: 0; opacity: 0; cursor: pointer; }
#trex-overlay .trex-slider { position: absolute; inset: 0; border: 1px solid #c8c9bf; border-radius: 99px; background: #e0e1d9; pointer-events: none; transition: background 120ms, border-color 120ms; }
#trex-overlay .trex-slider::before { content: ''; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: #fbfaf7; box-shadow: 0 1px 2px #0002; transition: transform 120ms; }
#trex-auto-answer-toggle:checked + .trex-slider { background: #68765a; border-color: #68765a; }
#trex-auto-answer-toggle:checked + .trex-slider::before { transform: translateX(12px); }
#trex-auto-answer-toggle:focus-visible + .trex-slider { outline: 2px solid #646d57; outline-offset: 3px; }
#trex-footer { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 10px; height: 30px; padding: 0 20px; border-top: 1px solid var(--trex-rule); }
#trex-status-text { color: #707267; font-size: 10px; }
#trex-panel[data-state='error'] #trex-status-text { color: #a25139; }
#trex-overlay .trex-link { display: inline-flex; align-items: center; gap: 4px; color: var(--trex-muted); font-size: 10px; line-height: 1.4; text-decoration: none; }
#trex-overlay .trex-link:hover { color: var(--trex-ink); text-decoration: underline; }
#trex-overlay .trex-link svg { width: 10px; height: 10px; }
#trex-resize-handle { position: absolute; right: 3px; bottom: 3px; width: 12px; height: 12px; cursor: nwse-resize; opacity: .4; background: repeating-linear-gradient(135deg, transparent 0 3px, #87897c 3px 4px, transparent 4px 6px); clip-path: polygon(100% 0, 100% 100%, 0 100%); }
#trex-resize-handle:focus-visible { width:20px; height:20px; clip-path:none; outline-offset:0; opacity:1; }
#trex-toggle-hint {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10000000;
  padding: 8px 12px;
  border: 1px solid #26272340;
  border-radius: 4px;
  background: #fbfaf7;
  color: #50534a;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  box-shadow: 0 2px 6px #20282112;
}
#trex-toggle-hint:hover { background: #eeede7; }
#trex-lesson-ad {
  box-sizing: border-box;
  position: static;
  clear: both;
  width: min(760px, calc(100% - 32px));
  margin: 24px auto 32px;
  padding: 10px 12px;
  border: 1px solid #d9dbd5;
  border-radius: 6px;
  background: #fafaf8;
  color: #50534a;
  font: 12px/1.3 system-ui, sans-serif;
  text-align: center;
}
#trex-lesson-ad iframe {
  display: block;
  width: 100%;
  height: 100px;
  margin-top: 5px;
  border: 0;
}
@keyframes trex-spin { to { transform: rotate(360deg); } }
@media(prefers-reduced-motion:reduce) { #trex-overlay, #trex-overlay *, #trex-overlay *::before { animation:none!important; transition:none!important; } }
@media(pointer:coarse) { #trex-resize-handle { width:24px; height:24px; } }
@keyframes trex-progress { from { transform: translateX(-100%); } to { transform: translateX(350%); } }
@media (prefers-reduced-motion: reduce) {
  #trex-overlay, #trex-overlay * { transition: none !important; animation: none !important; }
}
