/* Base theme */
:root {
  --bg: #0b0c10;
  --panel: #111317;
  --text: #e8ecf1;
  --muted: #a5adba;
  --brand: #4f8cff;
  --brand-2: #7ad1ff;
  --border: #1b1f27;
  --shadow: 0 10px 30px rgba(0,0,0,0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f9fc;
    --panel: #ffffff;
    --text: #0b1220;
    --muted: #52607a;
    --brand: #2457ff;
    --brand-2: #0077ff;
    --border: #e7edf5;
    --shadow: 0 8px 24px rgba(3,27,78,0.08);
  }
}

/* Manual theme override */
html.theme-dark {
  --bg: #0b0c10;
  --panel: #111317;
  --text: #e8ecf1;
  --muted: #a5adba;
  --brand: #4f8cff;
  --brand-2: #7ad1ff;
  --border: #1b1f27;
  --shadow: 0 10px 30px rgba(0,0,0,0.25);
}

html.theme-light {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --text: #0b1220;
  --muted: #52607a;
  --brand: #2457ff;
  --brand-2: #0077ff;
  --border: #e7edf5;
  --shadow: 0 8px 24px rgba(3,27,78,0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 10% -10%, rgba(79,140,255,0.08), transparent 60%),
              radial-gradient(1000px 800px at 90% 10%, rgba(122,209,255,0.10), transparent 50%),
              var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Top navigation */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1100;
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(0,0,0,0.65), rgba(0,0,0,0.25));
  border-bottom: 1px solid var(--border);
}
html.theme-light .top-nav { background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(255,255,255,0.55)); }
.nav-inner { display: flex; justify-content: space-between; align-items: center; height: 56px; gap: 28px; }
.nav-links { display: flex; gap: 20px; align-items: center; flex-wrap: nowrap; overflow-x: auto; }
.nav-actions { display: flex; align-items: center; gap: 10px; }
.theme-label { font-size: 13px; font-weight: 500; color: var(--muted); user-select: none; }
html.theme-light .theme-label { color: var(--muted); }
.top-nav a { position: relative; font-size: 14px; font-weight: 500; text-decoration: none; color: var(--muted); padding: 4px 2px; white-space: nowrap; }
.top-nav a:hover { color: var(--text); }
.top-nav a.active { color: var(--text); }
.top-nav a.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
@media (max-width: 640px) { .nav-links { gap: 14px; } }

body { padding-top: 56px; }

/* Theme toggle when placed in nav */
.theme-toggle.in-nav { position: static; top: auto; right: auto; transform: none; }
.theme-toggle.in-nav .switch { box-shadow: none; border-color: var(--border); background: var(--panel); }
.theme-toggle.in-nav input:checked + .switch { box-shadow: none; }

/* Dark theme: deep blue -> black center -> deep blue right */
html.theme-dark body {
  background: linear-gradient(90deg, #123c8a 0%, #07090e 50%, #123c8a 100%);
  background-size: 200% 100%;
  animation: bg-breathe 18s ease-in-out infinite;
}

@keyframes bg-breathe {
  0% { background-position: 0% 0; }
  50% { background-position: 100% 0; }
  100% { background-position: 0% 0; }
}

@media (prefers-reduced-motion: reduce) {
  html.theme-dark body { animation: none; }
}

/* Light theme: subtle grey -> white -> grey breathing */
html.theme-light body {
  background: linear-gradient(90deg, #d6dde8 0%, #ffffff 50%, #d6dde8 100%);
  background-size: 200% 100%;
  animation: bg-breathe-light 18s ease-in-out infinite;
}

@keyframes bg-breathe-light {
  0% { background-position: 0% 0; }
  50% { background-position: 100% 0; }
  100% { background-position: 0% 0; }
}

@media (prefers-reduced-motion: reduce) {
  html.theme-light body { animation: none; }
}

/* iOS-like theme switch (fixed top-right) */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
}
.theme-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-toggle .switch {
  display: inline-block;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  transition: background .2s ease, border-color .2s ease;
}
.theme-toggle .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform .2s ease;
}
.theme-toggle input:checked + .switch {
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  border-color: transparent;
}
.theme-toggle input:checked + .switch::after {
  transform: translateX(24px);
}
.theme-toggle input:focus-visible + .switch {
  outline: 2px solid var(--brand-2);
  outline-offset: 3px;
}

.container {
  width: min(100%, 1050px);
  padding: 0 20px;
  margin: 0 auto;
}

.site-header {
  position: relative;
  padding: 48px 0 24px;
}
.header-inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

.id-block {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)) , var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.name { font-size: 36px; line-height: 1.15; margin: 0 0 4px; letter-spacing: 0.2px; }
.title { margin: 0 0 14px; color: var(--muted); font-weight: 500; }

.contact { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px 18px; color: var(--muted); }
.contact a { color: inherit; text-decoration: none; border-bottom: 1px dashed rgba(122,209,255,0.5); }
.contact a:hover { color: var(--text); border-bottom-color: var(--brand-2); }
.contact .copy-btn { margin-left: 6px; padding: 2px; background: transparent; border: none; color: var(--muted); cursor: pointer; line-height: 1; border-radius: 6px; }
.contact .copy-btn:hover { color: var(--text); }
.contact .copy-btn.copied { color: var(--brand-2); }
.contact .copy-btn:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

.cta-row { margin-top: 16px; display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 10px 14px; border-radius: 10px; text-decoration: none; font-weight: 600; cursor: pointer;
  transition: transform .06s ease, border-color .2s ease, background .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(180deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }

/* Animated attention variant (for Ask AI Sergei) */
.btn.attention {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, var(--brand), var(--brand-2), var(--brand));
  background-size: 200% 100%;
  animation: aiGlow 3.5s ease-in-out infinite;
}
.btn.attention:hover { transform: translateY(-1px) scale(1.01); }
@keyframes aiGlow {
  0% { background-position: 0% 0; box-shadow: 0 0 0 rgba(0,0,0,0); }
  50% { background-position: 100% 0; box-shadow: 0 6px 20px rgba(79,140,255,0.28); }
  100% { background-position: 0% 0; box-shadow: 0 0 0 rgba(0,0,0,0); }
}

main { display: grid; gap: 18px; padding-bottom: 56px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 22px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 22px; }

.skills-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 12px;
}
.skill h3 { margin: 0 0 4px; font-size: 16px; }
.skill p { margin: 0; color: var(--muted); }

@media (min-width: 640px) {
  .skills-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 920px) {
  .skills-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.role { position: relative; padding-left: 0; }
.role-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.role-title { margin: 0; font-size: 18px; }
.role-meta { margin: 0; color: var(--muted); white-space: nowrap; }
.bullets { margin: 8px 0 0; padding-left: 20px; }
.bullets li { margin: 6px 0; }

.site-footer { border-top: 1px solid var(--border); padding: 18px 0 30px; color: var(--muted); }
.site-footer p { margin: 0; font-size: 14px; text-align: center; }

/* Subtle motion */
@media (prefers-reduced-motion: no-preference) {
  :root { scroll-behavior: smooth; }
}

/* Chat UI */
.chat-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 1140;
  transition: transform .08s ease;
}

.chat-launcher:active { transform: scale(0.96); }
.chat-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand-2);
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}
.chat-launcher.pulse::after { animation: ring 450ms ease-out 1; }
@keyframes ring { from { opacity: .35; transform: scale(1); } to { opacity: 0; transform: scale(1.6); } }

.chat-window {
  position: fixed;
  bottom: 88px;
  right: 20px;
  width: min(420px, calc(100% - 40px));
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02)) , var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.45), 0 0 0 1px rgba(122,209,255,0.25);
  backdrop-filter: blur(8px);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition: transform .2s ease, opacity .2s ease;
  z-index: 1150;
}
.chat-window[hidden] {
  display: grid; /* keep layout metrics but hide via opacity/transform for smoothness */
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

/* Chat fancy open/close animations */
.chat-window.chat-opening { animation: chatIn 360ms cubic-bezier(.2,.8,.2,1) both; }
.chat-window.chat-closing { animation: chatOut 220ms ease both; }
@keyframes chatIn {
  0% { opacity: 0; transform: translateY(16px) scale(.96); filter: blur(6px); }
  60% { opacity: 1; transform: translateY(-2px) scale(1.02); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes chatOut {
  0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translateY(8px) scale(.98); filter: blur(4px); }
}

/* Subtle stagger of inner parts on open */
.chat-window.chat-opening .chat-header { animation: fadeUp 280ms ease both; animation-delay: 80ms; }
.chat-window.chat-opening .chat-messages { animation: fadeUp 300ms ease both; animation-delay: 120ms; }
.chat-window.chat-opening .chat-input { animation: fadeUp 320ms ease both; animation-delay: 160ms; }
.chat-window.chat-opening .chat-note { animation: fadeUp 340ms ease both; animation-delay: 200ms; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

/* Dim background when chat is open (visual only) */
body.chat-open::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity .2s ease;
  z-index: 1020;
}
body:not(.chat-open)::before { content: none; }

@media (prefers-reduced-motion: reduce) {
  .chat-window { transition: none; }
  .chat-window.chat-opening, .chat-window.chat-closing { animation: none !important; }
  .chat-window .chat-header, .chat-window .chat-messages, .chat-window .chat-input, .chat-window .chat-note { animation: none !important; }
}
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-close { background: transparent; border: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.chat-messages { padding: 12px; display: grid; gap: 10px; max-height: 50vh; overflow: auto; }
.msg { display: inline-block; padding: 10px 12px; border-radius: 12px; max-width: 85%; }
.msg.user { background: linear-gradient(180deg, var(--brand), var(--brand-2)); color: #fff; justify-self: end; }
.msg.bot { background: #0f1116; border: 1px solid var(--border); color: var(--text); }
html.theme-light .msg.bot { background: #f5f7fb; }

.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.chat-note { font-size: 12px; color: var(--muted); padding: 6px 12px 12px; }
.chat-typing { padding: 0 12px 6px; font-size: 12px; color: var(--brand-2); opacity: 0.85; }
.chat-note .linklike { background: none; border: none; padding: 0 0 0 8px; color: var(--brand-2); cursor: pointer; text-decoration: underline; }

/* Map modal */
.map-modal { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; }
.map-modal[hidden] { display: grid; opacity: 0; pointer-events: none; }
.map-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.map-dialog { position: relative; width: min(900px, calc(100% - 40px)); height: min(70vh, 600px); background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.map-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.map-close { background: transparent; border: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.map-body { position: relative; }
.map-body iframe { width: 100%; height: 100%; border: 0; display: block; background: #eaeef6; }

/* Projects */
.projects-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 680px) { .projects-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .projects-grid { grid-template-columns: 1fr 1fr 1fr; } }
.project-card { border: 1px solid var(--border); background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)); border-radius: 12px; padding: 14px; cursor: pointer; transition: transform .06s ease, border-color .2s ease; }
.project-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.project-card h3 { margin: 0 0 6px; font-size: 18px; }
.project-card .meta { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.project-card .desc { margin: 6px 0 8px; color: var(--text); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); background: var(--panel); }
.kpis { margin: 8px 0 0; padding-left: 18px; }
.kpis li { margin: 4px 0; }


/* Project modal */
.proj-modal { position: fixed; inset: 0; z-index: 1250; display: grid; place-items: center; }
.proj-modal[hidden] { display: grid; opacity: 0; pointer-events: none; }
.proj-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.proj-dialog { position: relative; width: min(980px, calc(100% - 40px)); max-height: 80vh; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.proj-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.proj-close { background: transparent; border: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.proj-body { padding: 12px; overflow: auto; display: grid; gap: 10px; }
.proj-body h4 { margin: 8px 0 4px; }
.proj-links { display: flex; gap: 10px; flex-wrap: wrap; }

/* Inline contact form */
.inline-contact { display: grid; gap: 10px; }
.inline-contact .row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.inline-contact label { display: grid; gap: 4px; color: var(--muted); font-size: 14px; }
.inline-contact input, .inline-contact textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.inline-contact .full { display: grid; }
.inline-contact .actions { display: flex; justify-content: flex-end; }
@media (min-width: 640px) { .inline-contact .row { grid-template-columns: 1fr 1fr; } }

/* Contact modal */
.contact-modal { position: fixed; inset: 0; z-index: 1260; display: grid; place-items: center; }
.contact-modal[hidden] { display: grid; opacity: 0; pointer-events: none; }
.contact-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.contact-dialog { position: relative; width: min(560px, calc(100% - 40px)); background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.contact-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.contact-close { background: transparent; border: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.contact-body { padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.contact-body label { display: grid; gap: 4px; color: var(--muted); font-size: 14px; }
.contact-body input, .contact-body textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.contact-body .full { grid-column: 1 / -1; }
.contact-actions { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: flex-end; }
.contact-hint { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }

/* Boot loader console */
.boot-loader { position: fixed; inset: 0; background: #0b0c10; color: #c8facc; z-index: 1400; display: grid; place-items: center; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.boot-panel { width: min(860px, calc(100% - 40px)); background: #0b0c10; border: 1px solid #132018; border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-rows: auto 1fr auto; }
.boot-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: #0f1712; border-bottom: 1px solid #132018; color: #98e5a7; }
.boot-skip { background: transparent; border: 1px solid #244b37; color: #98e5a7; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.boot-log { margin: 0; padding: 12px; max-height: 60vh; overflow: auto; white-space: pre-wrap; }
.boot-progress { height: 8px; background: #0f1712; border-top: 1px solid #132018; }
.boot-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #22c55e, #84cc16); transition: width .18s ease; }

/* Section line-by-line reveal */
.line-hidden { opacity: 0; transform: translateY(6px); }
@keyframes lineIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }
.line-reveal { animation: lineIn .22s ease forwards; }

/* Green scan-to-text effect */
.scan-bar { display: inline-block; height: 0.95em; width: 0; vertical-align: baseline; border-radius: 2px; background: linear-gradient(90deg, #0ea95b, #86efac); box-shadow: 0 0 0 1px rgba(16,185,129,0.25), 0 2px 10px rgba(16,185,129,0.25); animation: scanGrow .35s ease forwards; }
@keyframes scanGrow { to { width: 100%; } }
.scan-fadein { opacity: 0; animation: textIn .18s ease forwards; }
@keyframes textIn { to { opacity: 1; } }

/* Overlay variant for complex nodes */
.scan-line { position: relative; overflow: hidden; }
.scan-overlay { position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 0.95em; width: 0; border-radius: 2px; background: linear-gradient(90deg, #0ea95b, #86efac); box-shadow: 0 0 0 1px rgba(16,185,129,0.25), 0 2px 10px rgba(16,185,129,0.25); animation: scanGrow .35s ease forwards; pointer-events: none; }
