/* ================================================================
   Тихоречинск — интерфейс. Тёмные панели цвета ночного асфальта,
   янтарь натриевых фонарей как акцент, бумага газеты.
   ================================================================ */
:root {
  --ink: #0e1218;
  --ink-2: #171c24;
  --ink-3: #222833;
  --line: rgba(239, 231, 216, 0.1);
  --paper: #efe7d8;
  --muted: #aaa396;
  --amber: #f2a541;
  --amber-2: #ffcf8a;
  --dusk: #8fbcd0;
  --red: #e2553d;
  --green: #8fc486;
  --ui: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Literata', 'PT Serif', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --panel: rgba(14, 18, 24, 0.9);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0e13; color: var(--paper); font: 14px/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- заставка ---------- */
#veil { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 60%, #1d2230 0%, #0b0e13 70%); transition: opacity 0.9s var(--ease); }
#veil.gone { opacity: 0; pointer-events: none; }
.veil-in { text-align: center; }
.veil-name { font: 600 34px/1 var(--ui); letter-spacing: 0.02em; }
.veil-sub { margin-top: 12px; color: var(--muted); font: 13px var(--mono); }
#fail { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: #0b0e13; }
.fail-in { max-width: 420px; padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--ink-2); }
.fail-in h2 { margin: 0 0 8px; font-size: 20px; }
.fail-in p { margin: 0; color: var(--muted); }

/* ---------- шапка ---------- */
#top { position: fixed; top: 16px; left: 16px; z-index: 10; display: flex; align-items: stretch; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.brand { padding: 10px 16px 10px 14px; border-right: 1px solid var(--line); }
.brand h1 { margin: 0; font: 650 19px/1.15 var(--ui); letter-spacing: 0.01em; }
.brand-sub { margin-top: 3px; font-size: 12px; color: var(--muted); }
.clock { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 14px; }
.clock-time { font: 500 22px/1 var(--mono); font-variant-numeric: tabular-nums; min-width: 104px; }
#c-day { color: var(--amber); font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; }
.speed { display: flex; gap: 2px; padding: 3px; background: var(--ink-3); border-radius: 9px; }
.speed button { min-width: 40px; height: 34px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: 500 13px var(--mono); display: grid; place-items: center; transition: background 0.2s var(--ease), color 0.2s var(--ease); }
.speed button svg { width: 15px; height: 15px; fill: currentColor; stroke: none; }
.speed button:hover { color: var(--paper); background: rgba(255, 255, 255, 0.06); }
.speed button.on { background: var(--amber); color: #1a1206; }

#counts { position: fixed; top: 86px; left: 16px; z-index: 9; display: flex; flex-wrap: wrap; gap: 6px; max-width: 520px; pointer-events: none; }
#counts span { padding: 5px 10px; border-radius: 999px; background: rgba(14, 18, 24, 0.78); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#counts b { color: var(--paper); font: 500 12px var(--mono); font-variant-numeric: tabular-nums; margin-right: 2px; }

/* ---------- поиск и газета ---------- */
#tools { position: fixed; top: 16px; right: 16px; z-index: 11; display: grid; grid-template-columns: 1fr auto; gap: 8px; width: min(470px, calc(100vw - 32px)); }
#search { position: relative; display: flex; align-items: center; height: 48px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); transition: border-color 0.2s var(--ease); }
#search:focus-within { border-color: rgba(242, 165, 65, 0.6); }
.s-ico { width: 18px; height: 18px; margin: 0 4px 0 14px; color: var(--muted); flex: none; }
#q { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; padding: 0 8px; font-size: 14px; outline: none; }
#q::placeholder { color: #8d887e; }
#q-go { height: 36px; margin-right: 6px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--amber); color: #1a1206; font-weight: 600; font-size: 13px; transition: transform 0.15s var(--ease), background 0.2s; }
#q-go:hover { background: var(--amber-2); }
#q-go:active { transform: scale(0.97); }
#q-go[disabled] { opacity: 0.6; cursor: progress; }
.paper-btn { height: 48px; padding: 0 14px 0 12px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); font-weight: 500; transition: border-color 0.2s var(--ease), transform 0.15s var(--ease); }
.paper-btn svg { width: 19px; height: 19px; color: var(--amber); }
.paper-btn:hover { border-color: rgba(242, 165, 65, 0.5); }
.paper-btn:active { transform: scale(0.97); }
.paper-btn.fresh::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); margin-left: -2px; }
#search { grid-column: 1; grid-row: 1; }
.paper-btn { grid-column: 2; grid-row: 1; }
#q-tips { grid-row: 2; grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; transition: opacity 0.25s var(--ease); }
body.has-card #q-tips { display: none; }
.tip { height: 30px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; background: rgba(14, 18, 24, 0.78); color: var(--muted); font-size: 12px; transition: color 0.2s, border-color 0.2s; }
.tip:hover { color: var(--paper); border-color: rgba(242, 165, 65, 0.5); }

/* ---------- подсказка, статус ---------- */
#hint { position: fixed; left: 50%; bottom: 22px; z-index: 8; transform: translateX(-50%); padding: 9px 16px; border-radius: 999px; background: rgba(14, 18, 24, 0.82); border: 1px solid var(--line); font-size: 13px; color: var(--paper); white-space: nowrap; transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); pointer-events: none; }
#hint.gone { opacity: 0; transform: translate(-50%, 8px); }
#ai-bar { position: fixed; left: 16px; bottom: 16px; z-index: 8; display: flex; gap: 8px; align-items: center; font-size: 12px; }
#ai-mode { padding: 5px 10px; border-radius: 999px; background: rgba(14, 18, 24, 0.82); border: 1px solid var(--line); color: var(--muted); }
#ai-mode.demo { color: var(--amber-2); }
#ai-mode button { margin-left: 6px; padding: 0; border: 0; background: none; color: var(--amber); text-decoration: underline; text-underline-offset: 2px; font-size: 12px; }
#ai-cost { font: 12px var(--mono); color: var(--muted); }

/* ---------- карточка жителя ---------- */
#card { position: fixed; top: 16px; right: 16px; bottom: 16px; z-index: 12; width: 400px; display: flex; flex-direction: column; background: rgba(13, 17, 23, 0.94); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: cardIn 0.45s var(--ease); }
body.has-card #tools { right: 432px; width: min(420px, calc(100vw - 480px)); }
body.has-card #tools #q-tips { display: none; }
@keyframes cardIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.grab { display: none; }
.card-x { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: grid; place-items: center; transition: background 0.2s, color 0.2s; z-index: 2; }
.card-x:hover { background: rgba(255, 255, 255, 0.07); color: var(--paper); }
.card-x svg { width: 16px; height: 16px; }
.card-scroll { overflow-y: auto; padding: 18px 18px 16px; scrollbar-width: thin; scrollbar-color: #333a46 transparent; }
.who-name { font: 650 22px/1.2 var(--ui); padding-right: 40px; }
.who-meta { margin-top: 4px; color: var(--muted); font-size: 13px; }
.now { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--ink-3); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.now .dot { flex: none; width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--green); }
.now.in .dot { background: var(--dusk); }
.now.late .dot { background: var(--red); }
.now .late-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: rgba(226, 85, 61, 0.16); color: #ff9a86; font-size: 12px; }
.why { margin-top: 10px; padding: 10px 12px; border-radius: 10px; border: 1px dashed rgba(242, 165, 65, 0.45); color: var(--amber-2); font-size: 13.5px; }
#card h2 { margin: 18px 0 8px; font: 600 12px/1 var(--ui); letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.bio-text { font: 15px/1.6 var(--serif); color: #ece4d4; min-height: 48px; }
.bio-text p { margin: 0 0 10px; }
.bio-text .cur { display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px; background: var(--amber); animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--muted); font: italic 14px var(--serif); }
.thinking i { display: inline-block; width: 5px; height: 5px; margin: 0 2px; border-radius: 50%; background: var(--amber); animation: dots 1.2s var(--ease) infinite; }
.thinking i:nth-child(2) { animation-delay: 0.15s; } .thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dots { 0%, 80%, 100% { opacity: 0.2; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
dl { margin: 0; display: grid; grid-template-columns: 104px 1fr; gap: 6px 12px; font-size: 13.5px; }
dt { color: var(--muted); }
dd { margin: 0; }
.agenda { position: relative; }
.ag-bar { position: relative; height: 26px; border-radius: 6px; background: var(--ink-3); overflow: hidden; }
.ag-seg { position: absolute; top: 0; bottom: 0; }
.ag-now { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--paper); border-radius: 2px; }
.ag-hours { display: flex; justify-content: space-between; margin-top: 4px; font: 11px var(--mono); color: #8d887e; }
.ag-list { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13px; }
.ag-list li { display: grid; grid-template-columns: 94px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.04); color: #d9d2c4; }
.ag-list li.cur { color: var(--amber-2); }
.ag-list .t { font: 12px var(--mono); color: var(--muted); padding-top: 1px; }
.ag-list li.cur .t { color: var(--amber); }
.rel { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 7px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 9px; background: transparent; text-align: left; transition: border-color 0.2s, background 0.2s; }
.rel:hover { border-color: rgba(242, 165, 65, 0.45); background: rgba(242, 165, 65, 0.05); }
.rel .rn { font-size: 13.5px; }
.rel .rt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.rel .rs { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.msg { max-width: 88%; padding: 8px 11px; border-radius: 12px; font-size: 14px; line-height: 1.45; }
.msg.me { align-self: flex-end; background: var(--ink-3); border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: rgba(242, 165, 65, 0.12); border: 1px solid rgba(242, 165, 65, 0.22); border-bottom-left-radius: 4px; font-family: var(--serif); }
#say { display: flex; gap: 6px; }
#say-in { flex: 1; min-width: 0; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--ink-2); outline: none; transition: border-color 0.2s; }
#say-in:focus { border-color: rgba(242, 165, 65, 0.6); }
#say button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--amber); color: #1a1206; display: grid; place-items: center; transition: transform 0.15s var(--ease); }
#say button:active { transform: scale(0.95); }
#say button svg { width: 18px; height: 18px; stroke-width: 2; }

/* ---------- газета ---------- */
#paper { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(6, 8, 11, 0.62); animation: fadeIn 0.3s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.paper-sheet { position: relative; width: min(860px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 30px 36px 28px; background: #f1ead9; color: #1d1a15; border-radius: 4px; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6); font-family: var(--serif); animation: sheetIn 0.5s var(--ease); }
@keyframes sheetIn { from { opacity: 0; transform: translateY(18px) rotate(-0.6deg); } to { opacity: 1; transform: none; } }
.paper-x { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: #4a443a; display: grid; place-items: center; }
.paper-x:hover { background: rgba(0, 0, 0, 0.06); }
.paper-x svg { width: 16px; height: 16px; }
.mast { text-align: center; border-bottom: 3px double #1d1a15; padding-bottom: 10px; }
.mast .mt { font: 700 clamp(28px, 5vw, 44px)/1 var(--serif); letter-spacing: 0.01em; }
.mast .ms { margin-top: 8px; display: flex; justify-content: space-between; font: 12px var(--mono); color: #5b5448; text-transform: uppercase; letter-spacing: 0.04em; }
.lead { padding: 16px 0 12px; border-bottom: 1px solid #b9ae98; }
.lead h2 { margin: 0 0 8px; font: 700 26px/1.2 var(--serif); }
.lead p { margin: 0; font-size: 16px; line-height: 1.55; }
.cols { columns: 2 260px; column-gap: 28px; column-rule: 1px solid #cfc5b0; padding-top: 14px; }
.art { break-inside: avoid; margin-bottom: 16px; }
.art h3 { margin: 0 0 5px; font: 700 17px/1.25 var(--serif); }
.art p { margin: 0; font-size: 14.5px; line-height: 1.55; }
.pname { padding: 0; border: 0; background: none; font: inherit; color: #8a2f1c; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; cursor: pointer; }
.pname:hover { color: #b33d24; }
.briefs { margin-top: 6px; padding-top: 12px; border-top: 1px solid #b9ae98; font-size: 13.5px; }
.briefs b { font-family: var(--ui); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.briefs ul { margin: 6px 0 0; padding-left: 18px; }
.briefs li { margin: 3px 0; }
.paper-foot { margin-top: 14px; font: 12px var(--ui); color: #6a6255; }
.paper-wait { padding: 50px 0; text-align: center; color: #5b5448; font-style: italic; }

/* ---------- тост ---------- */
#toast { position: fixed; left: 50%; bottom: 70px; z-index: 40; transform: translate(-50%, 12px); opacity: 0; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink-2); border: 1px solid var(--line); font-size: 13.5px; pointer-events: none; transition: opacity 0.35s var(--ease), transform 0.35s var(--ease); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- телефон ---------- */
@media (max-width: 720px) {
  #top { top: 8px; left: 8px; right: 8px; border-radius: 12px; justify-content: space-between; }
  .brand { padding: 8px 10px; border: 0; }
  .brand h1 { font-size: 16px; }
  .brand-sub { display: none; }
  .clock { gap: 8px; padding: 6px 6px 6px 0; }
  .clock-time { font-size: 17px; min-width: 0; }
  #c-day { font-size: 12px; }
  .speed button { min-width: 40px; height: 40px; padding: 0 6px; font-size: 12px; }
  #counts { top: 66px; left: 8px; right: 8px; max-width: none; gap: 4px; flex-wrap: nowrap; }
  #counts span { padding: 3px 8px; white-space: nowrap; }
  #counts span:last-child { display: none; }
  #tools { top: auto; bottom: 12px; left: 8px; right: 8px; width: auto; grid-template-columns: 1fr auto; }
  #q-tips { display: none; }
  .paper-btn span { display: none; }
  .paper-btn { width: 48px; justify-content: center; padding: 0; }
  #hint { bottom: 72px; font-size: 12px; white-space: normal; text-align: center; width: calc(100vw - 32px); border-radius: 12px; }
  #ai-bar { left: 8px; bottom: auto; top: 96px; }
  #card { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 62vh; border-radius: 16px 16px 0 0; border-bottom: 0; animation: sheetUp 0.45s var(--ease); transition: height 0.35s var(--ease); }
  #card.tall { height: 90vh; }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .grab { display: block; width: 100%; height: 22px; flex: none; cursor: grab; position: relative; }
  .grab::after { content: ''; position: absolute; left: 50%; top: 9px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: #3a414d; }
  .card-scroll { padding: 2px 16px 20px; }
  body.has-card #tools { display: none; }
  body.has-card #hint { display: none; }
  body.has-card #ai-bar { display: none; }
  .paper-sheet { padding: 22px 18px; }
  .mast .ms { flex-direction: column; gap: 2px; align-items: center; }
  dl { grid-template-columns: 92px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* съёмка обложки на программном рендере: без анимаций, иначе кадр «застывает» на нулевой прозрачности */
body.shot *, body.shot *::before, body.shot *::after { animation: none !important; transition: none !important; }
