/* u09 text helpers: chat bubbles, inline fill-in blanks, segmented tabs, copy morph. Tokens only, so dark mode works.
   The "me" bubble is the deep Cupie purple in both themes (white text passes contrast on light and dark pages). */
.tool { --tk-me: #7923C0; --tk-me-ink: #fff; }
.tool .tk-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Segmented tabs */
.tool .tk-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 20px; background: rgb(var(--ink) / .06); }
.tool .tk-tabs button {
  min-height: 40px; padding: 0 10px; border-radius: 16px; font-size: 14px; font-weight: 800; color: rgb(var(--ink) / .6);
  background: transparent; transition: background-color .2s ease, color .2s ease, box-shadow .2s ease; -webkit-tap-highlight-color: transparent;
}
.tool .tk-tabs button[aria-selected="true"] { background: var(--surface); color: rgb(var(--ink)); box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 4px 12px rgb(var(--accent) / .12); }
.tool .tk-tabs button:focus-visible { outline: 2px solid rgb(var(--accent)); outline-offset: 2px; }

/* Step labels inside a tool */
.tool .tk-step { font-size: 15px; line-height: 20px; font-weight: 900; color: rgb(var(--ink) / .9); margin: 4px 0 -6px; }
.tool .tool-note, .tool .tool-hint { color: rgb(var(--ink) / .72); }
.tool .tool-label { color: rgb(var(--ink) / .85); }

/* Inline blanks: an input that reads like part of the sentence */
.tool .tk-editable { display: inline; }
.tool input.tk-blank {
  display: inline-block; min-height: 0; min-width: 44px; height: auto; line-height: inherit; padding: 4px .25em; margin: -4px .05em; vertical-align: baseline; text-align: center;
  font: inherit; font-size: 1em; font-weight: inherit; letter-spacing: inherit; color: var(--link);
  background: rgb(var(--accent) / .12); border-radius: 8px; box-shadow: inset 0 -2px 0 rgb(var(--accent) / .55);
  transition: background-color .15s ease, box-shadow .15s ease; max-width: 100%;
}
.tool input.tk-blank::placeholder { color: var(--link); opacity: .62; }
.tool input.tk-blank:focus-visible, .tool input.tk-blank:focus { outline: 0; background: rgb(var(--accent) / .2); box-shadow: inset 0 -2px 0 rgb(var(--accent)), 0 0 0 2px rgb(var(--accent) / .35); }

/* Chat bubbles */
.tool .tk-thread { display: flex; flex-direction: column; gap: 8px; }
.tool .tk-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.tool .tk-row.tk-me { align-items: flex-end; padding-left: 32px; }
.tool .tk-row.tk-them { padding-right: 32px; }
.tool .tk-row .tk-bubble { max-width: min(100%, 460px); }
.tool .tk-under { display: flex; gap: 6px; align-items: center; }
.tool .tk-chipbtn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 20px; position: relative;
  font-size: 14px; font-weight: 800; color: rgb(var(--ink) / .8); background: var(--surface); box-shadow: inset 0 0 0 1px rgb(var(--ink) / .12);
  transition: transform .15s ease, background-color .2s ease; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tool .tk-chipbtn::after { content: ''; position: absolute; inset: -4px; }
.tool .tk-chipbtn:active { transform: scale(.96); }
.tool .tk-chipbtn .tk-ic, .tool .tk-chipbtn .tk-ic svg { width: 16px; height: 16px; }
.tool .tk-chipbtn.is-done { color: var(--link); }
.tool .tk-bubble {
  padding: 10px 14px; border-radius: 20px; font-size: 16px; line-height: 23px; font-weight: 650; max-width: 100%; overflow-wrap: anywhere; text-align: left;
}
.tool .tk-me .tk-bubble { background: var(--tk-me); color: var(--tk-me-ink); border-bottom-right-radius: 6px; }
.tool .tk-them .tk-bubble { background: var(--surface); color: rgb(var(--ink)); border-bottom-left-radius: 6px; box-shadow: inset 0 0 0 1px rgb(var(--ink) / .08); }
.tool .tk-bubble.is-new, .tool .tk-row.is-new .tk-bubble { animation: tk-in .35s var(--ease-out) both; }
.tool .tk-me .tk-bubble input.tk-blank { color: var(--tk-me-ink); background: rgb(255 255 255 / .14); box-shadow: inset 0 -2px 0 rgb(255 255 255 / .85); }
.tool .tk-me .tk-bubble input.tk-blank::placeholder { color: var(--tk-me-ink); opacity: 1; }
.tool .tk-me .tk-bubble input.tk-blank:focus { background: rgb(255 255 255 / .24); box-shadow: inset 0 -2px 0 #fff, 0 0 0 2px rgb(255 255 255 / .5); }
.tool .tk-meta { font-size: 13px; line-height: 18px; font-weight: 750; color: rgb(var(--ink) / .72); text-align: right; margin: -2px 0 0; }
.tool .tk-meta.tk-left { text-align: left; }
@keyframes tk-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

/* Copy button: copy icon cross-fades to a check */
.tool .tk-copy { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.tool .tk-ic { position: relative; width: 20px; height: 20px; flex: 0 0 auto; }
.tool .tk-ic svg { position: absolute; inset: 0; width: 20px; height: 20px; transition: opacity .2s cubic-bezier(.2, 0, 0, 1), transform .2s cubic-bezier(.2, 0, 0, 1), filter .2s cubic-bezier(.2, 0, 0, 1); }
.tool .tk-ic svg + svg { opacity: 0; transform: scale(.25); filter: blur(4px); }
.tool .tk-copy.is-done .tk-ic svg:first-child { opacity: 0; transform: scale(.25); filter: blur(4px); }
.tool .tk-copy.is-done .tk-ic svg + svg { opacity: 1; transform: none; filter: none; }
.tool .tk-copy-sm { min-height: 40px; min-width: 40px; width: 40px; height: 40px; padding: 0; border-radius: 20px; flex: 0 0 auto; }
.tool .btn:active, .tool .tk-tabs button:active { transform: scale(.96); }
.tool .btn { transition: transform .15s ease, background-color .2s ease; touch-action: manipulation; }

/* Toast */
.tool .tk-toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 60; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 18px; min-height: 48px; border-radius: 24px; max-width: calc(100vw - 32px);
  background: rgb(var(--ink)); color: var(--surface); font-size: 15px; font-weight: 750; box-shadow: 0 8px 28px rgb(0 0 0 / .25);
  transition: opacity .2s ease, transform .3s var(--ease-out);
}
.tool .tk-toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.tool .tk-toast button { min-height: 36px; padding: 0 14px; border-radius: 18px; font-size: 14px; font-weight: 850; color: rgb(var(--ink)); background: var(--surface); }

/* Sideways chip rows on phones (one line, fade at the edge) */
@media (max-width: 599px) {
  .tool .tool-chips.tk-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; margin: 0 -16px; padding: 2px 16px 4px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 28px), transparent); }
  .tool .tool-chips.tk-scroll::-webkit-scrollbar { display: none; }
  .tool .tool-chips.tk-scroll button { flex: 0 0 auto; white-space: nowrap; }
}
.tool .tool-chips button { min-height: 44px; }

/* Counter */
.tool .tk-count { font-size: 13px; font-weight: 800; color: rgb(var(--ink) / .7); font-variant-numeric: tabular-nums; }
.tool .tk-count.is-over { color: #C0237A; }

/* Small disclosure */
.tool details.tk-more { border-radius: 20px; background: var(--surface); box-shadow: inset 0 0 0 1px rgb(var(--ink) / .06); }
.tool details.tk-more > summary { list-style: none; cursor: pointer; padding: 14px 16px; font-size: 15px; font-weight: 850; color: rgb(var(--ink)); display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 48px; }
.tool details.tk-more > summary::-webkit-details-marker { display: none; }
.tool details.tk-more > summary::after { content: '+'; font-size: 20px; font-weight: 700; color: rgb(var(--ink) / .45); transition: transform .2s ease; }
.tool details.tk-more[open] > summary::after { transform: rotate(45deg); }
.tool details.tk-more > div { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }

@media (prefers-color-scheme: dark) {
  .tool .tk-tabs { background: rgb(var(--ink) / .08); }
  .tool .tk-tabs button[aria-selected="true"] { background: rgb(var(--accent) / .34); color: #fff; box-shadow: inset 0 0 0 1px rgb(var(--accent) / .5); }
  .tool .tk-tabs button { color: rgb(var(--ink) / .72); }
  .tool .btn-secondary { box-shadow: inset 0 0 0 1px rgb(255 255 255 / .16); }
  .tool input.tk-blank { color: #F3E6FF; background: rgb(var(--accent) / .26); box-shadow: inset 0 -2px 0 #C78BFF; }
  .tool input.tk-blank::placeholder { color: #F3E6FF; opacity: .9; }
  .tool .tk-me .tk-bubble input.tk-blank { background: rgb(255 255 255 / .16); box-shadow: inset 0 -2px 0 rgb(255 255 255 / .9); }
  .tool .tool-chips button { box-shadow: inset 0 0 0 1px rgb(var(--ink) / .2); }
  .tool input[type="text"]:not(.tk-blank), .tool input[type="search"] { box-shadow: inset 0 0 0 1px rgb(var(--ink) / .24); }
  .tool .tk-chipbtn { box-shadow: inset 0 0 0 1px rgb(var(--ink) / .22); }
  .tool details.tk-more { box-shadow: inset 0 0 0 1px rgb(var(--ink) / .14); }
}
@media (hover: hover) and (pointer: fine) {
  .tool .tk-tabs button:not([aria-selected="true"]):hover { color: rgb(var(--ink)); }
}
@media (prefers-reduced-motion: reduce) {
  .tool .tk-toast { transition: opacity .2s ease; }
  .tool .tk-bubble.is-new, .tool .tk-row.is-new .tk-bubble { animation: none; }
  .tool .tk-ic svg { transition: none; }
}
.tool .tk-chipbtn { white-space: nowrap; }
