/* UNI TWIN · design system (mobile first, dark by default, light by system preference or [data-theme]).
   Components used by every screen: .card (.solid confirmed | .hyp hypothesis | .muted), .btn (.primary .ghost .danger .small), .chip (.known .exploring .unknown),
   .field, .switch, .seg, .bar, .sheet, .toast, .msg, .composer, .row, .stack, .h1 .h2 .muted .small. Facts and hypotheses never look alike:
   solid ink + check for confirmed, dotted outline + the word "гипотеза" for hypotheses. */
:root {
  --bg: #0f1020; --surface: #181a30; --surface2: #20233f; --ink: #eef0ff; --muted: #a2a8c8; --line: rgba(255, 255, 255, .09);
  --accent: #e6a23c; --accent-ink: #231806; --teal: #3bb3a6; --slate: #8a92ad; --coral: #e0645c; --ok: #67c587;
  --radius: 20px; --radius-s: 12px; --tab-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f3ee; --surface: #ffffff; --surface2: #efe9e1; --ink: #1d1e2e; --muted: #5d627c; --line: rgba(20, 20, 40, .12);
    --accent: #c9821a; --accent-ink: #ffffff; --teal: #168a7d; --slate: #6b7390; --coral: #c8473f; --ok: #2f8f55; --shadow: 0 8px 30px rgba(40, 30, 10, .14);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f7f3ee; --surface: #ffffff; --surface2: #efe9e1; --ink: #1d1e2e; --muted: #5d627c; --line: rgba(20, 20, 40, .12);
  --accent: #c9821a; --accent-ink: #ffffff; --teal: #168a7d; --slate: #6b7390; --coral: #c8473f; --ok: #2f8f55; --shadow: 0 8px 30px rgba(40, 30, 10, .14);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; }
body { overscroll-behavior: none; }
#app { height: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- shell ---------------------------------------------------------------------------------------------------------------- */
.app { height: 100%; display: grid; grid-template-rows: auto 1fr auto; max-width: 560px; margin: 0 auto; position: relative; }
.header { padding: calc(var(--safe-t) + 10px) 16px 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; }
.header .title { font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.header .sub { font-size: 13px; color: var(--muted); }
.main { overflow-y: auto; overflow-x: hidden; padding: 6px 16px 24px; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.tabbar { display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface);
  border-top: 1px solid var(--line); }
.tab { background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted);
  min-height: 44px; font-size: 11px; cursor: pointer; position: relative; }
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.tab .dot { position: absolute; top: 8px; right: calc(50% - 20px); width: 9px; height: 9px; border-radius: 50%; background: var(--coral); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.h1 { font-size: 24px; font-weight: 700; line-height: 1.25; }
.h2 { font-size: 18px; font-weight: 650; line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad-top { padding-top: 12px; }

/* ---- cards ---------------------------------------------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: relative; }
.card.solid { border-left: 4px solid var(--accent); }
.card.hyp { border: 2px dotted var(--teal); background: transparent; }
.card.muted { opacity: .72; }
.card.warn { border-color: var(--coral); }
.card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 4px; }
.quote { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; color: var(--muted); font-size: 14px; font-style: italic; margin: 6px 0; overflow-wrap: anywhere; }
.tick { color: var(--ok); font-weight: 700; }

/* ---- buttons, chips, forms -------------------------------------------------------------------------------------------------- */
.btn { min-height: 44px; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface2); cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--coral); border-color: var(--coral); }
.btn.small { min-height: 44px; padding: 6px 14px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 13px; border: 1px solid var(--line);
  background: var(--surface2); max-width: 100%; }
.chip.known { border-color: var(--accent); }
.chip.exploring { border: 1px dotted var(--teal); color: var(--teal); }
.chip.unknown { color: var(--slate); border-style: dashed; }
.chip button { background: none; border: 0; padding: 0 2px; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; color: var(--muted); }
input[type="text"], input[type="password"], textarea, select { width: 100%; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 12px 14px; min-height: 44px; }
textarea { resize: vertical; min-height: 88px; }
.err { color: var(--coral); font-size: 14px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch input { appearance: none; width: 52px; height: 30px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); position: relative; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(22px); background: var(--accent-ink); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; border-radius: 999px; min-height: 40px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.bar { height: 10px; border-radius: 999px; background: var(--surface2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--accent)); border-radius: 999px; transition: width .6s ease; }

/* ---- sheets, toast -------------------------------------------------------------------------------------------------------------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 6, 18, .6); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet { width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  box-shadow: var(--shadow); animation: rise .25s ease; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.toast { position: fixed; left: 16px; right: 16px; top: calc(var(--safe-t) + 72px); z-index: 60;   /* at the top: never over the composer or the tab bar */ max-width: 528px; margin: 0 auto; background: var(--surface2);
  border: 1px solid var(--accent); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); animation: rise .25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---- chat ------------------------------------------------------------------------------------------------------------------------- */
.presence { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0 8px; }
.presence .state { font-size: 13px; color: var(--muted); min-height: 20px; }
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.person { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.twin { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: 0; padding: 10px 0 6px; background: var(--bg); border-top: 1px solid var(--line); }
.composer textarea { min-height: 48px; max-height: 120px; border-radius: 24px; padding: 12px 16px; }
.composer .btn { min-width: 48px; height: 48px; padding: 0; }

/* ---- ring ----------------------------------------------------------------------------------------------------------------------------- */
.ring-wrap { display: flex; justify-content: center; }
.ring-wrap svg { width: min(100%, 340px); height: auto; }
.ring-wrap .sector { cursor: pointer; }
.ring-wrap .sector:focus-visible path { stroke: var(--accent); stroke-width: 3; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--surface2); border-radius: var(--radius-s); padding: 10px 12px; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.welcome { min-height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: calc(var(--safe-t) + 24px) 20px calc(var(--safe-b) + 24px); max-width: 480px; margin: 0 auto; }
.tile { text-align: left; width: 100%; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: block; }
.tile:hover, .tile:focus-visible { border-color: var(--accent); }
.tile .h2 { margin-bottom: 4px; }
