:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1c2230;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --accent: #4f8cff;
  --accent2: #ff5a5f;
  --green: #3fb950;
  --border: #2a3340;
  --code: #0b0e13;
  --radius: 14px;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 22px; }

/* --- nav --- */
nav {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(10px);
  background: rgba(14, 17, 22, 0.8);
  border-bottom: 1px solid var(--border);
}
nav .wrap { display: flex; align-items: center; gap: 22px; height: 60px; }
nav .logo { font-weight: 800; font-size: 20px; letter-spacing: .5px; }
nav .logo span { color: var(--accent); }
nav .links { margin-left: auto; display: flex; gap: 20px; }
nav .links a { color: var(--muted); font-weight: 500; }
nav .links a:hover { color: var(--text); text-decoration: none; }

/* --- hero --- */
.hero { text-align: center; padding: 90px 0 60px; }
.hero h1 { font-size: 64px; margin: 0 0 6px; font-weight: 800; letter-spacing: -1px; }
.hero h1 .ru { background: linear-gradient(90deg, var(--accent), #7aa7ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .tagline { font-size: 22px; color: var(--muted); margin: 0 auto 30px; max-width: 620px; }
.flag { display: inline-block; width: 46px; height: 30px; border-radius: 5px; overflow: hidden; vertical-align: middle; margin-left: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.flag div { height: 10px; }
.flag .w { background: #fff; } .flag .b { background: #0039a6; } .flag .r { background: #d52b1e; }

.btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 13px 26px; border-radius: 10px; font-weight: 600; font-size: 16px;
  border: 1px solid var(--border); cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #3d7af0; text-decoration: none; }
.btn.ghost { background: var(--panel); color: var(--text); }
.btn.ghost:hover { background: var(--panel2); text-decoration: none; }

/* --- sections --- */
section { padding: 48px 0; }
section h2 { font-size: 32px; margin: 0 0 10px; }
section .sub { color: var(--muted); margin: 0 0 28px; font-size: 17px; }

/* --- feature grid --- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.card .ico { font-size: 30px; margin-bottom: 8px; }
.card h3 { margin: 0 0 6px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 15px; }

/* --- code blocks --- */
pre, code { font-family: var(--mono); }
pre {
  background: var(--code); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; overflow-x: auto; font-size: 15px; line-height: 1.55;
}
code.inline { background: var(--panel2); padding: 2px 7px; border-radius: 6px; font-size: .9em; color: #ffd9a0; }
.tok-kw { color: #ff7b9c; } .tok-fn { color: #8ad4ff; } .tok-str { color: #a5e075; }
.tok-num { color: #ffd082; } .tok-com { color: #6b7787; font-style: italic; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: stretch; }
.split .label { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 8px; }

/* --- table --- */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
th { background: var(--panel2); font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
td:first-child code { color: #ff7b9c; }
tr:last-child td { border-bottom: none; }

/* --- playground --- */
.pg { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pg .pane { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pg .pane .head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel2); font-size: 14px; }
.pg textarea { flex: 1; min-height: 360px; resize: vertical; border: none; outline: none; background: var(--code); color: var(--text); font-family: var(--mono); font-size: 15px; line-height: 1.55; padding: 16px; tab-size: 4; }
.pg .out { flex: 1; min-height: 360px; margin: 0; border: none; border-radius: 0; white-space: pre-wrap; color: #d6e2ee; }
.pg .out .err { color: var(--accent2); }
.pg .out .note { color: #ffd082; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px; }
.status { color: var(--muted); font-size: 14px; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #d29922; }
.dot.ready { background: var(--green); } .dot.busy { background: var(--accent); }

/* --- steps --- */
.steps { counter-reset: s; display: grid; gap: 14px; }
.step { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px 18px 60px; position: relative; }
.step::before { counter-increment: s; content: counter(s); position: absolute; left: 18px; top: 18px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.step h3 { margin: 0 0 4px; font-size: 17px; }
.step p { margin: 0; color: var(--muted); }

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

@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .split, .pg { grid-template-columns: 1fr; }
}

/* --- Телефоны и планшеты --- */
@media (max-width: 720px) {
  .wrap { padding: 0 16px; }

  /* Шапка: логотип сверху, ссылки прокручиваются вбок */
  nav .wrap { flex-direction: column; height: auto; gap: 8px; padding-top: 10px; padding-bottom: 10px; align-items: stretch; }
  nav .logo { font-size: 18px; text-align: center; }
  nav .links {
    margin-left: 0; gap: 6px; justify-content: flex-start;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap; padding-bottom: 4px;
    scrollbar-width: none;
  }
  nav .links::-webkit-scrollbar { display: none; }
  nav .links a { flex: 0 0 auto; padding: 6px 10px; background: var(--panel); border-radius: 8px; font-size: 14px; }

  .hero { padding: 54px 0 40px; }
  .hero h1 { font-size: 38px; }
  .hero .tagline { font-size: 18px; }
  .flag { width: 36px; height: 24px; }
  .btns { flex-direction: column; }
  .btn { width: 100%; justify-content: center; }

  section { padding: 34px 0; }
  section h2 { font-size: 26px; }
  pre { font-size: 13px; padding: 14px; }

  .toolbar { gap: 8px; }
  .toolbar .btn, .toolbar select { width: 100%; }
  .status { margin-left: 0; width: 100%; }

  table { font-size: 14px; }
  th, td { padding: 9px 10px; }

  .lesson .run-row { grid-template-columns: 1fr !important; }
  .game .body { grid-template-columns: 1fr !important; }
}

@media (max-width: 380px) {
  .hero h1 { font-size: 30px; }
}

/* ===== Полировка ===== */
* { -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(79,140,255,.35); }

a, .btn, .card, .proj, .game, .lesson, .task-card,
nav .links a, .tabs button, input, textarea, select {
  transition: transform .15s ease, border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 28px rgba(0,0,0,.28); }
.proj:hover, .game:hover, .lesson:hover, .task-card:hover { border-color: #3a4a5e; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }

/* Единый стиль пунктов меню (десктоп и телефон) */
nav .links a { padding: 6px 11px; border-radius: 8px; }
nav .links a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
nav .links a.active { background: var(--accent); color: #fff; }

/* Аккуратные полосы прокрутки */
* { scrollbar-width: thin; scrollbar-color: #2a3340 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3340; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a4a5e; }
::-webkit-scrollbar-track { background: transparent; }

/* Кнопки «копировать» на блоках кода */
.copybtn {
  position: absolute; top: 8px; right: 8px;
  background: var(--panel2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--sans); font-size: 12px; padding: 3px 9px;
  cursor: pointer; opacity: 0;
}
pre:hover .copybtn, .copybtn:focus-visible { opacity: 1; }
.copybtn:hover { color: var(--text); background: var(--border); }
@media (max-width: 720px) { .copybtn { opacity: .8; } }

/* Кнопка «наверх» */
#toTop {
  position: fixed; left: 18px; bottom: 18px; width: 46px; height: 46px;
  border-radius: 50%; background: var(--accent); color: #fff; border: none;
  font-size: 22px; cursor: pointer; display: none; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
#toTop.show { display: grid; place-items: center; }
#toTop:hover { background: #3d7af0; transform: translateY(-2px); }

/* ===== Холст черепахи (рисование в браузере) ===== */
.rk-turtle { background: #fff; border: 1px solid var(--border); border-radius: 12px; max-width: 100%; height: auto; display: block; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* ===== Конфетти ===== */
.rk-confetti { position: fixed; top: -14px; height: 14px; z-index: 9999; pointer-events: none; border-radius: 2px; opacity: .95; animation: rkFall linear forwards; }
@keyframes rkFall { to { transform: translateY(106vh) rotate(720deg); opacity: .15; } }

/* ===== Аккаунт в шапке ===== */
#acctCtl { margin-left: 14px; display: flex; align-items: center; }
.acct-login { background: var(--accent); color: #fff !important; padding: 7px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.acct-login:hover { background: #3d7af0; text-decoration: none; }
.acct-av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; color: #fff; text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.35); border: 2px solid rgba(255,255,255,.18); transition: transform .15s; }
.acct-av:hover { transform: scale(1.08); text-decoration: none; }

/* блок аккаунта на главной */
.home-acct { background: linear-gradient(135deg, var(--panel), var(--panel2)); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.home-acct .ha-av { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; font-size: 32px; color: #fff; flex: 0 0 60px; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.home-acct .ha-hi { font-size: 21px; font-weight: 700; margin-bottom: 6px; }
.home-acct .ha-sub { color: var(--muted); margin: 0 0 12px; }
.home-acct .ha-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== ИИ-помощник ===== */
#aiBtn {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, #4f8cff, #a371f7); color: #fff; font-size: 28px;
  box-shadow: 0 8px 24px rgba(79,140,255,.45);
  display: grid; place-items: center;
  transition: transform .18s;
  animation: aiPulse 2.8s ease-in-out infinite;
}
@keyframes aiPulse { 0%,100% { box-shadow: 0 8px 24px rgba(79,140,255,.45); } 50% { box-shadow: 0 8px 34px rgba(163,113,247,.6); } }
#aiBtn:hover { transform: translateY(-3px) scale(1.06); }
#aiBtn.hidden { display: none; }

#aiPanel {
  position: fixed; right: 20px; bottom: 20px; z-index: 61;
  width: 392px; max-width: calc(100vw - 24px); height: 72vh; max-height: 660px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  display: none; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  transform-origin: bottom right;
}
#aiPanel.show { display: flex; animation: aiPop .24s cubic-bezier(.2,.9,.3,1.2); }
@keyframes aiPop { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }

.ai-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: #fff; background: linear-gradient(135deg, #4f8cff, #a371f7); }
.ai-head .ai-ava { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; font-size: 22px; }
.ai-head .ai-ttl { font-weight: 800; line-height: 1.15; }
.ai-head .ai-ttl small { display: block; font-weight: 500; font-size: 12px; opacity: .92; }
.ai-head .ai-ttl small::before { content: '●'; color: #7CFFB0; margin-right: 5px; font-size: 9px; vertical-align: middle; }
.ai-head .ai-close { margin-left: auto; background: rgba(255,255,255,.16); border: none; color: #fff; width: 30px; height: 30px; border-radius: 50%; font-size: 15px; cursor: pointer; display: grid; place-items: center; }
.ai-head .ai-close:hover { background: rgba(255,255,255,.32); }

.ai-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
.ai-msgs::-webkit-scrollbar { width: 8px; }
.ai-msgs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.ai-row { display: flex; gap: 9px; align-items: flex-end; max-width: 100%; }
.ai-row.user { flex-direction: row-reverse; }
.ai-ava-sm { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; background: linear-gradient(135deg, #4f8cff, #a371f7); }
.ai-bubble { padding: 11px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; max-width: calc(100% - 44px); }
.ai-row.bot .ai-bubble { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.ai-row.user .ai-bubble { background: linear-gradient(135deg, #4f8cff, #6f7bff); color: #fff; border-bottom-right-radius: 5px; }
.ai-textseg + .ai-textseg { margin-top: 8px; }

.ai-code { background: var(--code); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; margin: 9px 0 0; font-family: var(--mono); font-size: 13px; overflow-x: auto; white-space: pre; color: #e6edf3; }
.ai-codebar { display: flex; gap: 8px; margin: 7px 0 2px; }
.ai-codebar button { background: var(--panel); color: var(--muted); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; padding: 5px 11px; cursor: pointer; font-family: var(--sans); transition: all .15s; }
.ai-codebar button:hover { color: #fff; background: var(--accent); border-color: var(--accent); }

.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; background: var(--bg); }
.ai-chip { background: var(--panel2); border: 1px solid var(--border); color: var(--text); border-radius: 20px; padding: 7px 13px; font-size: 13px; cursor: pointer; transition: all .15s; }
.ai-chip:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.ai-dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.ai-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: aiBounce 1.2s infinite; }
.ai-dots i:nth-child(2) { animation-delay: .18s; }
.ai-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes aiBounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

.ai-input { display: flex; gap: 9px; padding: 12px; border-top: 1px solid var(--border); background: var(--panel); align-items: flex-end; }
.ai-input textarea { flex: 1; resize: none; background: var(--code); color: var(--text); border: 1px solid var(--border); border-radius: 22px; padding: 11px 16px; font-family: var(--sans); font-size: 14.5px; line-height: 1.4; max-height: 120px; }
.ai-input textarea:focus { border-color: var(--accent); outline: none; }
.ai-input #aiSend { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; padding: 0; font-size: 17px; display: grid; place-items: center; background: linear-gradient(135deg, #4f8cff, #a371f7); color: #fff; border: none; cursor: pointer; transition: transform .15s; }
.ai-input #aiSend:hover { transform: translateY(-1px); }
.ai-input #aiSend:disabled { opacity: .5; cursor: default; transform: none; }

@media (max-width: 480px) {
  #aiPanel { right: 8px; left: 8px; bottom: 8px; width: auto; height: 80vh; }
}
@media (max-width: 720px) {
  #acctCtl { justify-content: center; margin: 4px 0 0; }
}
