/* Base tokens, layout, typography, forms and buttons. Shared by sign-in and cabinet.
   Brand colours follow the Telegram mini app (deep blue #0a3abe, bright blue accent). */
:root {
  color-scheme: light;
  --bg: #f2f5fb;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fd;
  --hover: #eef2fa;
  --text: #0f1a33;
  --muted: #5a6785;
  --line: #e1e7f2;
  --line-strong: #c7d1e3;
  --accent: #1f5eff;
  --accent-hi: #3a74ff;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --danger: #c4291f;
  --ok: #138a55;
  --shadow: 0 1px 2px rgba(15, 26, 51, .05);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #060c1d;
    --sidebar: #091127;
    --surface: #0d1630;
    --surface-2: #111c3b;
    --hover: #14204a;
    --text: #eef3ff;
    --muted: #93a3c8;
    --line: #1b2750;
    --line-strong: #2b3b6e;
    --accent: #4d8dff;
    --accent-hi: #6aa2ff;
    --accent-soft: rgba(77, 141, 255, .15);
    --on-accent: #ffffff;
    --danger: #ff8d93;
    --ok: #5fd7a0;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #060c1d;
  --sidebar: #091127;
  --surface: #0d1630;
  --surface-2: #111c3b;
  --hover: #14204a;
  --text: #eef3ff;
  --muted: #93a3c8;
  --line: #1b2750;
  --line-strong: #2b3b6e;
  --accent: #4d8dff;
  --accent-hi: #6aa2ff;
  --accent-soft: rgba(77, 141, 255, .15);
  --on-accent: #ffffff;
  --danger: #ff8d93;
  --ok: #5fd7a0;
  --shadow: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; min-height: 100vh; background: var(--bg); color: var(--text); }
h1, h2, h3, p, dl, ol, ul, fieldset { margin: 0; }
h1 { font-size: 1.625rem; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; line-height: 1.3; font-weight: 700; }
h3 { font-size: 1rem; line-height: 1.4; font-weight: 650; }
p, h1, h2, h3, button, a, dd { overflow-wrap: anywhere; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; top: -5rem; left: 16px; z-index: 30; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); }
.skip:focus { top: 16px; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; color: var(--text); text-decoration: none; font-size: 1.1875rem; font-weight: 750; letter-spacing: -.01em; }
.brand-mark { display: inline-grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; }
.brand-mark img { width: 100%; height: 100%; display: block; }
.brand-mark-lg { width: 76px; height: 76px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; font-size: 1.25rem; font-weight: 750; text-align: center; }
.signed-in .auth-brand { display: none; }

/* Layout: sidebar + main column. Signed out there is no sidebar, only the card. */
.app { display: flex; min-height: 100vh; }
.main-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 12px 32px; }
.signed-in .topbar { border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.brand-compact { display: none; font-size: 1.0625rem; }
.brand-compact .brand-mark { width: 34px; height: 34px; }
.theme-switch { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.theme-switch button { min-height: 36px; width: 38px; padding: 0; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.theme-switch .icon { width: 18px; height: 18px; }
.shell { width: min(100% - 32px, 440px); margin: 0 auto; padding: 4vh 0 40px; }
.signed-in .shell { width: min(100% - 64px, 960px); padding: 32px 0 48px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
body:not(.signed-in) #profile { padding: 36px 32px; }
body:not(.signed-in) #title, body:not(.signed-in) #intro { text-align: center; }
.panel > * + *, #authCard > * + *, #emailBlock > * + *, #mergeCard > * + *, #magic > * + *, .stack > * + *, .block > * + * { margin-top: 16px; }
.block { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.footer { color: var(--muted); text-align: center; font-size: .8125rem; margin-top: 32px; }

label { display: block; font-size: .875rem; font-weight: 600; }
label + input, label + textarea, label + .inline-form { margin-top: 8px; }
input, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-2); color: var(--text); font: inherit; }
input:focus, textarea:focus { border-color: var(--accent); outline: 0; }
#code { font-size: 1.375rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--muted); }
.consent { color: var(--muted); font-size: .8125rem; }

button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; text-align: center; text-decoration: none; cursor: pointer; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.ghost { background: transparent; }
.quiet { border-color: transparent; background: transparent; color: var(--accent); padding-inline: 8px; }
.quiet:hover { border-color: transparent; text-decoration: underline; }
.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
a.button:not([href]) { opacity: .55; pointer-events: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.notice { padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: var(--radius); background: var(--accent-soft); font-size: .9375rem; }
.notice:empty { display: none; }
.divider { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: .875rem; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.comparison-code { display: inline-block; font-size: 1.5rem; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 8px 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Sign-in: one narrow column, full-width controls. */
body:not(.signed-in) #profile .stack > button, body:not(.signed-in) #profile .stack > .button,
body:not(.signed-in) #emailForm .actions > button, body:not(.signed-in) #magic > button { width: 100%; }
@media (max-width: 480px) {
  .panel, body:not(.signed-in) #profile { padding: 20px 16px; }
  .topbar { padding: 10px 16px; min-height: 60px; }
  .shell { padding-top: 8px; }
}
.consent a + a { margin-left: 8px; }
