* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px 16px 80px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #111;
  background: #fff;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.subtitle {
  margin: 0 0 18px;
  color: #555;
  font-size: 14px;
}

/* Username input + dropdown */
.search-box {
  position: relative;
}

.input-row {
  display: flex;
  gap: 8px;
}

#username-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid #bbb;
  border-radius: 4px;
  outline: none;
}

#username-input:focus {
  border-color: #333;
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn-primary,
.btn-secondary {
  padding: 8px 14px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #f5f5f5;
  color: #111;
}

.btn-primary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled) {
  background: #e9e9e9;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 50;
}

.dropdown-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 260px;
  overflow-y: auto;
}

.dropdown-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  cursor: pointer;
}

.dropdown-option:hover,
.dropdown-option.is-highlighted {
  background: #f0f0f0;
}

.dropdown-option-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.dropdown-option-name {
  flex: 1;
  font-size: 14px;
}

.dropdown-match {
  font-weight: 700;
  text-decoration: underline;
}

.dropdown-option-meta {
  font-size: 12px;
  color: #666;
}

.status-text {
  margin: 8px 0 18px;
  min-height: 20px;
  font-size: 13px;
  color: #555;
}

.status-text.is-error {
  color: #b91c1c;
}

/* Results */
.results-header {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 13px;
  color: #555;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  background: #fafafa;
}

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-username {
  font-weight: 700;
  font-size: 14.5px;
  color: #111;
}

.msg-num {
  font-size: 12px;
  color: #777;
}

.msg-content {
  font-size: 15px;
  word-wrap: break-word;
}

/* Clickable words */
.markov-word {
  display: inline;
  padding: 1px 2px;
  margin: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font-size: inherit;
  line-height: inherit;
  cursor: pointer;
}

.markov-word:hover {
  background: #e5e7eb;
}

.markov-word.is-same-source {
  text-decoration: underline;
  text-decoration-color: #999;
  text-underline-offset: 2px;
}

.markov-word.is-active {
  background: #fef08a;
  color: #111;
}

/* Original Message Popup */
.og-popup {
  position: fixed;
  z-index: 100;
  width: min(440px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.og-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid #e5e5e5;
  background: #f7f7f7;
  border-radius: 6px 6px 0 0;
  font-size: 13px;
}

.og-close-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  color: #555;
}

.og-close-btn:hover {
  color: #000;
}

.og-popup-body {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
}

.og-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.og-content {
  flex: 1;
  min-width: 0;
}

.og-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 13.5px;
}

.og-line {
  font-size: 12px;
  color: #666;
}

.og-text {
  font-size: 14.5px;
  word-wrap: break-word;
  max-height: 170px;
  overflow-y: auto;
}

.og-word-highlight {
  background: #fef08a;
  color: #111;
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 700;
}

.og-popup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid #e5e5e5;
  background: #fafafa;
  border-radius: 0 0 6px 6px;
  font-size: 12.5px;
  color: #555;
}

.og-nav {
  display: flex;
  gap: 6px;
}

.og-nav button {
  padding: 3px 9px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #111;
}

.og-nav button:hover:not(:disabled) {
  background: #f0f0f0;
}

.og-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}
