/* The app borrows the client's palette wholesale: a Mini App with its own colour opinion reads
   as a website bolted onto Telegram. Telegram's variable always wins; the fallback only tracks
   the OS so the page is still legible when it is opened outside a client.
   Radius system: 12px for surfaces and media, 8px for controls. No third size, no pills.
   The accent means exactly one thing: this is the chosen one. Nothing decorative uses it. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #707579);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --line: var(--tg-theme-section-separator-color, #e3e3e7);
  --accent: var(--tg-theme-button-color, #3390ec);
  --link: var(--tg-theme-link-color, #3390ec);
  --danger: var(--tg-theme-destructive-text-color, #df3f40);
  --r: 12px;
  --r-s: 8px;
  --gut: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --fg: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #708499);
    --card: var(--tg-theme-secondary-bg-color, #232e3c);
    --line: var(--tg-theme-section-separator-color, #101921);
    --accent: var(--tg-theme-button-color, #5288c1);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --danger: var(--tg-theme-destructive-text-color, #ec3942);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* an author `display` outranks the UA rule the hidden attribute relies on */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16.5px/1.45 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  /* Bottom room for the keyboard and for Telegram's own buttons, which it draws outside this webview. */
  padding:
    calc(var(--tg-content-safe-area-inset-top, 0px) + 10px)
    calc(var(--tg-content-safe-area-inset-right, 0px) + var(--gut))
    calc(var(--tg-safe-area-inset-bottom, 0px) + 96px)
    calc(var(--tg-content-safe-area-inset-left, 0px) + var(--gut));
}

#bar { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 14px; }
.who { min-width: 0; }
#title {
  margin: 0; font-size: 17px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
#state { margin: 3px 0 0; font-size: 12.5px; color: var(--hint); }

/* Segmented, never two columns: two columns on a 390px phone are two unusable columns. */
#langs {
  flex: 0 0 auto; display: flex; gap: 2px; padding: 2px;
  background: var(--card); border-radius: var(--r-s);
}
#langs button {
  border: 0; margin: 0; padding: 0 12px; height: 30px; border-radius: 6px;
  background: transparent; color: var(--hint); cursor: pointer;
  font-family: inherit; font-size: 12.5px; font-weight: 600; letter-spacing: .02em;
}
#langs button[aria-pressed="true"] {
  background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgb(0 0 0 / .16);
}

#note {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 0 0 16px; padding: 11px 13px; border-radius: var(--r-s);
  background: var(--card); font-size: 14px; line-height: 1.4;
}
#note.bad { padding-left: 16px; box-shadow: inset 3px 0 0 var(--danger); }
#note button {
  border: 0; box-shadow: inset 0 0 0 1.5px var(--accent);
  background: var(--bg); color: var(--fg); cursor: pointer;
  height: 32px; padding: 0 14px; border-radius: var(--r-s);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
}

/* Blocks are separated by space and by their own typography, not by a grid of identical cards.
   Only the focused block gets a surface, because that is the one thing worth elevating. */
.b {
  margin: 0 -10px 16px; padding: 10px; border-radius: var(--r);
  background: transparent; transition: background-color .14s ease;
}
.b:focus-within { background: var(--card); }

.meta { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.name { font-size: 12.5px; color: var(--hint); }
.nudge { margin-left: auto; display: flex; gap: 4px; flex: 0 0 auto; }
.meta button {
  appearance: none; border: 0; background: transparent; color: var(--fg); cursor: pointer;
  min-width: 36px; height: 36px; padding: 0 4px; border-radius: var(--r-s);
  font-family: inherit; font-size: 15px; line-height: 1; flex: 0 0 auto;
}
.meta button:disabled { opacity: .26; cursor: default; }
.meta button:active:not(:disabled) { background: var(--line); transform: scale(.94); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The formatting controls live in the focused block, never docked to the bottom of the
   viewport: viewportHeight lies while the iOS keyboard is up, and Telegram says so itself. */
.fmt { display: none; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.fmt::-webkit-scrollbar { display: none; }
.b:focus-within .fmt { display: flex; align-items: center; gap: 2px; }
.b:focus-within .name { display: none; }

.host { min-width: 0; }
.b-heading .ql-editor { font-size: 20px; font-weight: 600; line-height: 1.28; }
.b-footer .ql-editor { font-size: 13.5px; }
/* .ql-container wins on source order below, so this has to out-specify it, not just follow it. */
.b-expandable_blockquote .host.ql-container { border-left: 3px solid var(--hint); padding-left: 12px; }
.b-divider hr { border: 0; height: 1px; background: var(--hint); margin: 12px 0; }
.quiet { margin: 6px 0 0; font-size: 12.5px; color: var(--hint); }

/* Candidates only. Free-text entry would make the editor an SSRF trigger against our own
   fetcher, and this list is also the server's allowlist, so anything else is refused anyway. */
.strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }
.pick {
  flex: 0 0 auto; scroll-snap-align: start; padding: 0; border: 0; cursor: pointer;
  background: var(--card); border-radius: var(--r); overflow: hidden; line-height: 0;
  box-shadow: inset 0 0 0 1px var(--line); opacity: .5; transition: opacity .14s ease;
}
.pick[aria-pressed="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--accent); }
.pick:disabled { cursor: default; opacity: 1; }
.pick img { display: block; width: 108px; height: 72px; object-fit: cover; }

.panel { margin: 24px 0; padding: 20px; background: var(--card); border-radius: var(--r); }
.panel h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.panel p { margin: 0; font-size: 14.5px; line-height: 1.5; }

.skel { height: 15px; margin: 0 0 14px; border-radius: 6px; background: var(--card); }
.skel.t { height: 24px; width: 68%; margin-bottom: 20px; }
.skel.s { width: 44%; }

/* --- Quill's own chrome ------------------------------------------------------------------
   snow is desktop-shaped and hardcoded light, so it is retinted to the client's theme and its
   24x28px hit targets are grown for a thumb. Loaded before this file, so equal specificity
   wins on source order; the selector shapes below mirror snow's deliberately. */
.ql-container { font-family: inherit; font-size: inherit; height: auto; }
.ql-container.ql-snow, .ql-toolbar.ql-snow { border: 0; padding: 0; font-family: inherit; }
.ql-editor {
  padding: 0; height: auto; min-height: 1.45em; overflow: visible; line-height: inherit;
}
.ql-editor.ql-blank::before { left: 0; right: 0; color: var(--hint); font-style: normal; }
.ql-snow a { color: var(--link); }
.ql-snow .ql-editor code {
  background: var(--card); color: var(--fg); border-radius: 5px; font-size: .9em; padding: 1px 5px;
}
/* Readable while it is being edited, but visibly covered, the way Telegram draws one. */
.ql-editor tg-spoiler {
  padding: 0 3px; border-radius: 3px;
  background: repeating-linear-gradient(-45deg, var(--hint) 0 1px, transparent 1px 5px);
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}

.ql-snow .ql-stroke, .ql-snow .ql-stroke-miter { stroke: var(--fg); }
.ql-snow .ql-fill, .ql-snow .ql-stroke.ql-fill { fill: var(--fg); }
.ql-snow.ql-toolbar button {
  float: none; width: 36px; height: 36px; padding: 8px; border-radius: var(--r-s);
  font-family: inherit; font-size: 12px; letter-spacing: 1px; color: var(--fg);
}
.ql-snow.ql-toolbar button svg { float: none; width: 100%; height: 100%; }
.ql-snow.ql-toolbar button:active { background: var(--line); }
.ql-snow.ql-toolbar button:hover,
.ql-snow.ql-toolbar button:focus,
.ql-snow.ql-toolbar button.ql-active { color: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-fill,
.ql-snow.ql-toolbar button:focus .ql-fill,
.ql-snow.ql-toolbar button.ql-active .ql-fill,
.ql-snow.ql-toolbar button:hover .ql-stroke.ql-fill,
.ql-snow.ql-toolbar button:focus .ql-stroke.ql-fill,
.ql-snow.ql-toolbar button.ql-active .ql-stroke.ql-fill { fill: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow.ql-toolbar button:focus .ql-stroke,
.ql-snow.ql-toolbar button.ql-active .ql-stroke,
.ql-snow.ql-toolbar button:hover .ql-stroke-miter,
.ql-snow.ql-toolbar button:focus .ql-stroke-miter,
.ql-snow.ql-toolbar button.ql-active .ql-stroke-miter { stroke: var(--accent); }
/* snow resets its own hover to #444 on touch, which is invisible on a dark client. */
@media (pointer: coarse) {
  .ql-snow.ql-toolbar button:hover:not(.ql-active) { color: var(--fg); }
  .ql-snow.ql-toolbar button:hover:not(.ql-active) .ql-fill,
  .ql-snow.ql-toolbar button:hover:not(.ql-active) .ql-stroke.ql-fill { fill: var(--fg); }
  .ql-snow.ql-toolbar button:hover:not(.ql-active) .ql-stroke,
  .ql-snow.ql-toolbar button:hover:not(.ql-active) .ql-stroke-miter { stroke: var(--fg); }
}

.ql-snow .ql-tooltip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; z-index: 1;
  max-width: min(320px, calc(100vw - 44px)); white-space: normal;
  padding: 12px; border: 0; border-radius: var(--r);
  background: var(--card); color: var(--fg); box-shadow: 0 6px 24px rgb(0 0 0 / .24);
}
.ql-snow .ql-tooltip.ql-hidden { display: none; }
.ql-snow .ql-tooltip::before { margin: 0; line-height: 1.3; font-size: 13px; color: var(--hint); }
.ql-snow .ql-tooltip input[type=text] {
  flex: 1 1 100%; width: auto; height: 38px; margin: 0; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg); color: var(--fg);
  font-family: inherit; font-size: 16px;      /* under 16px iOS zooms the whole page on focus */
}
.ql-snow .ql-tooltip a { line-height: 1.3; font-size: 14px; font-weight: 600; color: var(--link); }
.ql-snow .ql-tooltip a.ql-preview { max-width: 100%; flex: 1 1 100%; font-weight: 400; }
.ql-snow .ql-tooltip a.ql-action::after { border: 0; margin-left: 0; padding: 0; }
.ql-snow .ql-tooltip a.ql-remove::before { margin-left: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
