:root {
  --accent: #1565c0;
  --accent-light: #e3f2fd;
  --border: #ccc;
  --muted: #666;
  --hl-bg: #e8f5e9;
  --hl-line: #81c784;
}

body {
  font-family: system-ui, sans-serif;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  color: #222;
  background: #fff;
}
[hidden] { display: none !important; }

header {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1rem;
}
header h1 { font-size: 1.2rem; margin: 0.75rem 0; }
.tabs { display: flex; gap: 0.25rem; }
.tabs button {
  font: inherit;
  border: none;
  background: none;
  padding: 0.6rem 0.9rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  color: #555;
  cursor: pointer;
}
.tabs button:hover { color: #222; }
.tabs button[aria-selected=true] { color: #222; font-weight: 600; border-bottom-color: var(--accent); }
header .engine { margin: 0 0 0.6rem auto; font-size: 0.85rem; }

label { display: block; font-weight: 600; margin: 0.75rem 0 0.35rem; }
label.inline { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: normal; margin: 0 1.25rem 0 0; }
.label { font-weight: 600; }
.hint { font-size: 0.85rem; color: var(--muted); font-weight: normal; }
.controls { margin-top: 0.5rem; font-size: 0.9rem; }
.message { color: #555; font-style: italic; margin-top: 0.5rem; }
.status { font-size: 0.8rem; color: #888; min-height: 1.2em; margin-top: 0.4rem; }
.warning { font-size: 0.8rem; color: #b00020; }
footer { margin-top: 3rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid #eee; }
kbd { font-family: inherit; font-size: 0.7rem; color: #888; border: 1px solid #ddd; border-radius: 3px; padding: 0 3px; }

/* ── Prompt picker ── */

#prompt-picker { position: relative; }
#prompt-picker summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
#prompt-picker summary::-webkit-details-marker { display: none; }
#prompt-picker summary:hover, #prompt-picker[open] summary { border-color: var(--accent); }
#prompt-picker summary .change { margin-left: auto; color: var(--accent); }
#prompt-picker .panel {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 0.75rem;
}
#prompt-picker .panel > .label, #prompt-picker .panel .predict-only > .label { margin: 0.25rem 0 0.4rem; font-size: 0.9rem; }
#prompt-picker .chips { margin-bottom: 0.75rem; }
#prompt-picker textarea { width: 100%; box-sizing: border-box; font: inherit; padding: 0.4rem; }
body:not(.mode-predict) .predict-only { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips button {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f7f7f7;
  padding: 0.2rem 0.75rem;
  cursor: pointer;
}
.chips button:hover { border-color: var(--accent); }
.chips button[aria-pressed=true] { background: var(--accent-light); border-color: var(--accent); }

/* ── Editors ── */

.editor {
  display: block;
  width: 100%;
  min-height: 7rem;
  box-sizing: border-box;
  margin: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  overflow: hidden;  /* they grow to fit instead */
}
.editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }

/* The highlighted document: a backdrop with the same text and box as the textarea, behind it.
   Everything that affects where text wraps must match between the two. */
.overlay-editor { position: relative; background: #fff; border-radius: 6px; }
.overlay-editor .editor { position: relative; background: transparent; }
.overlay-editor .editor, .overlay-editor .backdrop {
  line-height: 2.2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  letter-spacing: normal;
  tab-size: 8;
}
.overlay-editor.plain .editor { line-height: 1.6; }
.overlay-editor.plain .backdrop { display: none; }
.backdrop {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border: 1px solid transparent;
  font: inherit;
  font-size: 1rem;
  color: transparent;
  overflow: hidden;
  pointer-events: none;
}
/* No horizontal padding or borders on marks: they'd shift the text. */
.backdrop mark {
  position: relative;
  color: transparent;
  background: var(--hl-bg);
  box-shadow: inset 0 -2px var(--hl-line);
  border-radius: 2px;
}
.backdrop mark.whitespace { background: none; box-shadow: none; }
.backdrop .marker {
  position: absolute;
  top: 0;
  left: 0;
  height: 1.3em;  /* not bottom: 0, which spans every line a multi-newline token covers */
  width: 0.6em;
  background: var(--hl-bg);
  box-shadow: inset 2px 0 var(--hl-line);
}
.backdrop .alt {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  font-size: 0.75rem;
  line-height: 1;
  white-space: pre;
  color: var(--accent);
  background: #fff;
  padding-right: 3px;
  border-right: 1px solid #ccc;
}.backdrop.show-alts .alt { display: block; }

#tooltip {
  position: fixed;
  z-index: 20;
  transform: translate(-50%, calc(-100% - 4px));
  max-width: 24rem;
  padding: 3px 8px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  font-size: 0.85rem;
  text-align: center;
  pointer-events: none;
}
#tooltip .alt { color: var(--accent); font-weight: 600; white-space: pre; }
#tooltip .detail { color: var(--muted); margin-left: 0.5em; }

/* ── Predictive text ── */

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 720px) { .columns { grid-template-columns: 1fr; } }

/* Fixed-size slots, so they don't jump around as they update */
#suggestions { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.4rem; margin-top: 0.5rem; }
#suggestions button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  height: 2.2rem;
  padding: 0 0.5rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
  cursor: pointer;
}
#suggestions button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-light); }
#suggestions button:disabled { cursor: default; color: #999; }
#suggestions button span { flex: 1; text-align: left; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
#suggestions button small { flex-shrink: 0; color: #888; font-size: 0.75rem; }
#suggestions button kbd { flex-shrink: 0; }

/* ── Conversation ── */

.chat-head { display: flex; justify-content: space-between; align-items: center; }
.bubble { border: 1px solid #e0e0e0; border-radius: 10px; padding: 0.5rem 0.75rem; margin: 0.6rem 0; max-width: 85%; }
.bubble.user { background: #f5f5f5; margin-left: auto; }
.bubble.in-progress { max-width: none; border-color: #bbb; }
.bubble .role { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 0.3rem; }
.bubble .content { white-space: pre-wrap; }
.bubble .editor { background: #fff; }
#chat-send { margin-top: 0.6rem; font: inherit; padding: 0.3rem 0.9rem; cursor: pointer; }
button.link { border: none; background: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
