:root {
  --bg: #f6f3ec;
  --panel: #fffdf9;
  --panel2: #efebe2;
  --line: #ddd7ca;
  --line2: #c9c2b2;
  --ink: #1d1c1a;
  --soft: #4d4a44;
  --muted: #78756d;
  --dim: #9a968c;
  --accent: #b5700b;
  --accent-ink: #fff;
  --accent-line: #dcc392;
  --tint: #f8eed9;
  --red: #c0432c;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; }
button { cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- sidebar ---------- */
aside {
  position: fixed; inset: 0 auto 0 0; width: 272px;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 28px 20px; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand > span { font-family: var(--serif); font-size: 21px; font-weight: 700; letter-spacing: -.3px; line-height: 1.15; }
.brand-mark { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: 50% 28%; border: 1px solid var(--accent-line); flex: none; }
.beta { display: block; font: 500 9px/1.4 var(--mono); letter-spacing: 1px; margin-top: 5px; color: var(--muted); }
.new {
  margin: 34px 0 30px; width: 100%; text-align: left; border: 1px solid var(--line);
  border-radius: 10px; padding: 13px 14px; background: transparent; font-weight: 600; color: var(--ink);
}
.new:hover { border-color: var(--accent); color: var(--accent); }
.section-label { font: 500 10px var(--mono); color: var(--dim); letter-spacing: 1.6px; }
.history { margin-top: 14px; color: var(--muted); font-size: 13px; line-height: 1.9; }
.history div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); }
.aside-bottom { margin-top: auto; }
.upgrade { padding: 16px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--panel2); }
.upgrade:hover { border-color: var(--accent-line); }
.upgrade > span { font-size: 20px; display: block; margin-bottom: 8px; color: var(--accent); }
.upgrade strong { font-size: 13px; }
.upgrade small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.profile { display: flex; align-items: center; gap: 10px; margin-top: 20px; font-size: 12px; }
.profile small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.avatar { background: var(--panel2); border: 1px solid var(--line); border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-size: 10px; flex: none; }

/* ---------- main shell ---------- */
main { margin-left: 272px; min-height: 100dvh; display: flex; flex-direction: column; }
header { padding: 22px 40px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.m-brand, .m-new { display: none; }
.model { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.model b { font: 600 10px var(--mono); letter-spacing: .6px; background: var(--panel2); color: var(--accent); border: 1px solid var(--line); padding: 3px 7px; border-radius: 5px; margin-left: 8px; vertical-align: 2px; }
.head-right { display: flex; align-items: center; gap: 14px; }
.indep { font: 500 11px var(--mono); color: var(--muted); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.indep b { color: var(--red); font-weight: 600; }
.ticker {
  margin: 0 40px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font: 500 11px var(--mono); letter-spacing: .3px; color: var(--muted);
  display: flex; align-items: center; gap: 10px; min-height: 40px;
}
.ticker i { width: 6px; height: 6px; border-radius: 50%; background: var(--red); flex: none; animation: pulse 1.8s ease-in-out infinite; }
.workspace { width: 100%; max-width: 840px; margin: 0 auto; padding: 34px 32px 40px; flex: 1; display: flex; flex-direction: column; }

/* ---------- intro ---------- */
.intro { text-align: center; }
.hero { height: 230px; margin: 0; position: relative; overflow: hidden; border-radius: 18px; }
.hero img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 45%; display: block; }
.mascot { position: relative; width: 92px; height: 92px; margin: -46px auto 20px; border-radius: 50%; padding: 3px; background: linear-gradient(145deg, var(--accent), var(--accent-line)); box-shadow: 0 10px 30px rgba(60,45,20,.25); }
.mascot img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; object-position: 50% 26%; display: block; border: 3px solid var(--bg); }
.eyebrow { font: 500 11px var(--mono); letter-spacing: 2px; color: var(--accent); }
h1 { font-family: var(--serif); font-size: 54px; line-height: 1.08; letter-spacing: -1.5px; font-weight: 700; margin: 18px 0 16px; }
h1 em { font-style: italic; font-weight: 500; color: var(--accent); }
.intro > p { color: var(--soft); font-size: 16px; line-height: 1.7; margin: 0; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 34px 0 30px; text-align: left; }
.suggestions button { padding: 18px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; text-align: left; transition: .2s; }
.suggestions button:hover { border-color: var(--accent); transform: translateY(-3px); background: var(--panel2); }
.suggestions span { display: block; color: var(--accent); font-size: 21px; margin-bottom: 14px; }
.suggestions strong { display: block; font-size: 14px; }
.suggestions small { display: block; font-size: 12px; line-height: 1.45; color: var(--muted); margin-top: 6px; }

/* ---------- chat + composer ---------- */
.chat:empty { display: none; }
.chat { padding: 12px 0 28px; display: flex; flex-direction: column; gap: 22px; flex: 1; }
.msg, .cert { scroll-margin-bottom: 230px; }
.msg { max-width: 92%; font-size: 15px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--panel2); border: 1px solid var(--line); border-radius: 16px 16px 3px 16px; padding: 13px 18px; }
.msg.bot { color: var(--soft); }
.msg.bot::before { content: "✳ ИЗВИНИGPT"; display: block; color: var(--accent); font: 600 11px var(--mono); letter-spacing: 1.2px; margin-bottom: 9px; }
.composer-wrap { margin-top: auto; position: sticky; bottom: 0; background: linear-gradient(to bottom, transparent, var(--bg) 22px); padding: 22px 0 max(14px, env(safe-area-inset-bottom)); }
.intro:not([hidden]) ~ .composer-wrap { position: static; background: none; }
.session-stats { display: flex; justify-content: space-between; gap: 10px; font: 500 11px var(--mono); color: var(--muted); margin-bottom: 10px; padding: 0 4px; }
.session-stats b { font-weight: 600; color: var(--red); }
form { padding: 16px 18px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
form:focus-within { border-color: var(--accent-line); }
textarea { border: 0; resize: none; outline: none; width: 100%; font-size: 16px; line-height: 1.6; background: transparent; color: var(--ink); }
textarea::placeholder { color: var(--dim); }
.composer-bottom { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.composer-bottom small { font: 500 11px var(--mono); letter-spacing: .3px; }
.composer-bottom button { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; font-size: 22px; font-weight: 700; width: 42px; height: 42px; }
.composer-bottom button:disabled { opacity: .5; }
.disclaimer { text-align: center; color: var(--dim); font-size: 12px; margin-top: 12px; line-height: 1.6; }
.disclaimer span { display: block; font-size: 11px; }

/* ---------- certificate (finale) ---------- */
.cert { align-self: stretch; display: flex; gap: 18px; align-items: center; padding: 22px; border: 1px solid var(--accent-line); border-radius: 14px; background: linear-gradient(135deg, var(--tint), var(--panel)); }
.cert img { width: 92px; height: 92px; border-radius: 50%; object-fit: cover; flex: none; box-shadow: 0 0 0 3px var(--tint), 0 0 0 4px var(--accent-line); }
.cert small { display: block; font: 500 10px var(--mono); letter-spacing: 1.4px; color: var(--accent); }
.cert strong { display: block; font-family: var(--serif); font-size: 22px; line-height: 1.25; margin: 6px 0 8px; }
.cert p { margin: 0 0 8px; font-size: 13px; line-height: 1.6; color: var(--soft); overflow-wrap: anywhere; }

/* ---------- dialog ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(48,40,26,.45); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; padding: 16px; }
.overlay[hidden] { display: none; }
.dialog { position: relative; width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 96px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 90px rgba(60,45,20,.28); animation: appear .22s ease-out; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 12px 8px 12px 20px; font: 500 10px var(--mono); letter-spacing: 1.4px; color: var(--muted); gap: 8px; }
.dialog-top button { border: 0; background: transparent; font-size: 24px; color: var(--muted); width: 44px; height: 36px; flex: none; }
.dialog-content { text-align: center; padding: 28px 32px 24px; }
.dialog-icon { border: 1px solid var(--accent-line); background: var(--tint); border-radius: 14px; width: 54px; height: 54px; margin: 0 auto 20px; display: grid; place-items: center; font-size: 26px; color: var(--accent); }
.step { font: 500 11px var(--mono); letter-spacing: 1.6px; color: var(--accent); }
h2 { font-family: var(--serif); font-size: 29px; line-height: 1.2; letter-spacing: -.5px; margin: 12px 0 16px; overflow-wrap: anywhere; }
.dialog p { margin: 0; font-size: 15px; line-height: 1.7; color: var(--soft); white-space: pre-line; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; margin-top: 24px; }
.actions button { flex: 1; min-height: 46px; border: 1px solid var(--line2); background: transparent; border-radius: 10px; padding: 11px 12px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.4; }
.actions button:first-child { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions button:hover { filter: brightness(1.12); }
.dialog-note { font-size: 12px; line-height: 1.6; color: var(--dim); margin-top: 16px; }
.stamp { display: inline-block; margin-top: 20px; padding: 6px 18px; border: 3px solid var(--red); color: var(--red); border-radius: 6px; font: 800 22px var(--mono); letter-spacing: 4px; transform: rotate(-6deg); animation: stamp .45s cubic-bezier(.2, 1.6, .4, 1) both; }
.escape { position: fixed; bottom: max(22px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); border: 1px solid var(--line2); border-radius: 30px; padding: 11px 20px; min-height: 44px; color: var(--soft); background: rgba(255,253,249,.94); font-size: 13px; white-space: nowrap; }
.toast { position: fixed; z-index: 30; bottom: 24px; left: 50%; transform: translate(-50%, 20px); width: max-content; max-width: calc(100vw - 32px); text-align: center; background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 12px 20px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .3s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.meter { height: 6px; border-radius: 8px; background: var(--line); margin: 22px 0 12px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.receipt { text-align: left; border: 1px dashed var(--line2); border-radius: 10px; padding: 14px 16px; line-height: 2; color: var(--muted); font: 12px/2 var(--mono); }
.receipt > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.receipt strong { text-align: right; color: var(--ink); font-weight: 600; }
.price-card { background: linear-gradient(135deg, #fbf0d8, #f6e7c4); border: 1px solid var(--accent-line); color: var(--accent); border-radius: 14px; padding: 20px 14px; margin-top: 20px; }
.price-card span { display: block; font: 500 10px var(--mono); letter-spacing: 2px; opacity: .75; }
.price-card strong { display: block; font-family: var(--serif); font-size: 46px; letter-spacing: -1px; line-height: 1.4; }
.price-card small { display: block; font-size: 12px; color: var(--muted); }
.council-chat { text-align: left; display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.council-chat > div { padding: 11px 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; }
.council-chat > div:last-child { border-color: var(--accent-line); background: var(--tint); }
.council-chat strong { display: block; font: 600 10px var(--mono); letter-spacing: .6px; color: var(--accent); margin-bottom: 4px; }
.council-chat span { display: block; font-size: 13px; line-height: 1.55; color: var(--soft); }
.run-count { font: 500 11px/1.6 var(--mono); color: var(--muted); margin-top: 18px; }

/* the runaway window */
.dialog.compact .dialog-icon, .dialog.compact .dialog-note { display: none; }
.dialog.compact .dialog-content { padding: 20px 24px 20px; }
.dialog.compact h2 { font-size: 24px; margin: 8px 0 10px; }
.dialog.runner { position: fixed; margin: 0; transition: left .2s cubic-bezier(.3, 1.4, .5, 1), top .2s cubic-bezier(.3, 1.4, .5, 1); animation: none; }

@keyframes appear { from { opacity: 0; transform: translateY(15px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes stamp { from { opacity: 0; transform: rotate(-6deg) scale(2.4); } to { opacity: 1; transform: rotate(-6deg) scale(1); } }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- tablet ---------- */
@media (max-width: 950px) {
  aside { width: 224px; padding: 24px 16px; }
  main { margin-left: 224px; }
  header { padding: 20px 28px; }
  .ticker { margin: 0 28px; }
  .workspace { padding: 28px 24px 36px; }
  .hero { margin: 0; }
  h1 { font-size: 44px; }
  .suggestions { gap: 8px; }
  .suggestions button { padding: 14px 12px; }
}

/* ---------- phone ---------- */
@media (max-width: 700px) {
  aside { display: none; }
  main { margin-left: 0; }
  header { position: sticky; top: 0; z-index: 5; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: rgba(246,243,236,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
  .m-brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 18px; }
  .m-brand .brand-mark { width: 34px; height: 34px; }
  .model { display: none; }
  .head-right { gap: 8px; }
  .indep span { display: none; }
  .indep::before { content: "Самост."; }
  .m-new { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: transparent; font-size: 20px; color: var(--accent); }
  .ticker { margin: 0; padding: 8px 16px; font-size: 10.5px; line-height: 1.45; border-top: 0; }
  .workspace { padding: 18px 16px 0; }
  .hero { height: 130px; margin: 0; border-radius: 14px; }
  .mascot { width: 78px; height: 78px; margin-top: -44px; }
  .eyebrow { font-size: 9.5px; letter-spacing: 1.2px; line-height: 1.5; }
  h1 { font-size: 36px; letter-spacing: -1px; margin: 14px 0 12px; }
  .intro > p { font-size: 15px; }
  .suggestions { grid-template-columns: 1fr; gap: 8px; margin: 24px 0 18px; }
  .suggestions button { display: grid; grid-template-columns: 30px 1fr; column-gap: 12px; align-items: center; padding: 13px 14px; }
  .suggestions span { grid-row: 1 / 3; margin: 0; }
  .suggestions small { margin-top: 2px; }
  .session-stats { font-size: 10px; }
  .session-stats > span:first-child { max-width: 74%; }
  .composer-wrap { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .disclaimer { font-size: 11px; margin-top: 8px; }
  .msg { max-width: 100%; font-size: 15px; }
  .msg.user { max-width: 92%; }
  .cert { flex-direction: column; text-align: center; padding: 20px 16px; }
  .cert strong { font-size: 20px; }

  /* bottom sheet for ordinary steps, floating card while it runs away */
  .overlay { padding: 0 0 calc(64px + env(safe-area-inset-bottom)); place-items: end center; }
  .dialog { width: 100%; max-height: calc(100dvh - 90px); border-radius: 20px 20px 0 0; border-bottom: 1px solid var(--line); animation: sheet .25s ease-out; }
  .dialog.compact { width: calc(100vw - 32px); align-self: center; max-height: calc(100dvh - 90px); border-radius: 18px; border-bottom: 1px solid var(--line); padding-bottom: 0; animation: appear .22s ease-out; }
  .dialog.runner { animation: none; }
  .stamp { font-size: 18px; letter-spacing: 3px; }
  .dialog-content { padding: 22px 20px 18px; }
  h2 { font-size: 25px; }
  .dialog p { font-size: 14.5px; }
  .actions { flex-direction: column; gap: 8px; }
  .escape { bottom: max(10px, env(safe-area-inset-bottom)); padding: 9px 18px; font-size: 12px; }
  .toast { bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 58px); transform: translate(-50%, -20px); }
  .toast.visible { transform: translate(-50%, 0); }
  .council-chat span { font-size: 12.5px; }
  .price-card strong { font-size: 40px; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (hover: none) { .esc-hint { display: none; } }
@media (max-width: 380px) { h1 { font-size: 32px; } .actions button { font-size: 13px; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
