/* ============================================================
   MathFlux — единая система дизайна
   Математический сайт (основной) + скрытый игровой раздел
   ============================================================ */

:root {
  --bg: #0f1220;
  --bg-soft: #171a2e;
  --bg-card: #1d2138;
  --bg-elev: #242a47;
  --line: #2c3354;
  --line-soft: #23284150;
  --text: #e7eaf6;
  --text-dim: #9aa3c7;
  --text-faint: #6b7399;
  --brand: #6ea8fe;
  --brand-2: #8b7dff;
  --accent: #36d9b9;
  --warn: #ffcf6b;
  --danger: #ff6b8b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px -12px rgba(0,0,0,.55);
  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(900px 500px at 12% -8%, rgba(110,168,254,.10), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(139,125,255,.10), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 22px; }

.site-header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(12px);
  background: rgba(15,18,32,.72);
  border-bottom: 1px solid var(--line-soft);
}
.site-header .inner {
  display: flex; align-items: center; gap: 18px;
  height: 62px;
}
.brand-link {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.12rem; color: var(--text);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; color: #0c0f1c;
  box-shadow: 0 4px 14px -4px var(--brand);
}
.nav { display: flex; gap: 6px; margin-left: 8px; flex-wrap: wrap; }
.nav a {
  color: var(--text-dim); font-size: .92rem; font-weight: 500;
  padding: 7px 13px; border-radius: 8px; transition: .15s;
}
.nav a:hover { background: var(--bg-elev); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--bg-elev); }
.spacer { flex: 1; }

/* ---------- Hero ---------- */
.hero { padding: 58px 0 26px; text-align: center; }
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  margin: 0 0 14px; font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(120deg, #fff, var(--brand) 60%, var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--text-dim); font-size: 1.08rem; max-width: 620px; margin: 0 auto; }

/* ---------- Grid of tools ---------- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin: 30px 0 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px; transition: .18s;
  display: flex; flex-direction: column; gap: 8px;
  text-decoration: none; color: var(--text);
}
.card:hover { transform: translateY(-3px); border-color: var(--brand); text-decoration: none; box-shadow: var(--shadow); }
.card .ico { font-size: 1.5rem; }
.card h3 { margin: 0; font-size: 1.05rem; }
.card p { margin: 0; color: var(--text-dim); font-size: .85rem; }

/* ---------- Panel ---------- */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px; margin: 14px 0;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 1.35rem; }
.panel .sub { color: var(--text-dim); margin: 0 0 20px; font-size: .9rem; }

.section-title {
  display: flex; align-items: center; gap: 10px;
  margin: 40px 0 6px; font-size: 1.25rem; font-weight: 700;
}
.section-title .bar { width: 4px; height: 20px; border-radius: 3px; background: linear-gradient(var(--brand), var(--brand-2)); }

/* ---------- Forms / inputs ---------- */
label.fld { display: block; margin-bottom: 14px; }
label.fld > span { display: block; font-size: .82rem; color: var(--text-dim); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 11px 13px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: .95rem; transition: .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(110,168,254,.18);
}
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #0c0f1c; font-weight: 700; font-size: .95rem;
  border-radius: var(--radius-sm); transition: .15s; font-family: var(--sans);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px -8px var(--brand); }
.btn.ghost { background: var(--bg-elev); color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { box-shadow: none; border-color: var(--brand); }
.btn.sm { padding: 7px 13px; font-size: .85rem; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Result display ---------- */
.result {
  margin-top: 18px; padding: 18px;
  background: var(--bg-soft); border: 1px dashed var(--line);
  border-radius: var(--radius-sm); min-height: 24px;
  font-family: var(--mono); font-size: 1rem; word-break: break-word;
}
.result .lbl { display:block; color: var(--text-faint); font-size: .75rem; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
.result.big { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.result.empty::before { content: "— результат появится здесь —"; color: var(--text-faint); font-style: italic; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .9rem; }
table.tbl th, table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.tbl th { background: var(--bg-elev); color: var(--text-dim); font-weight: 600; position: sticky; top: 0; }
table.tbl tr:nth-child(even) td { background: rgba(255,255,255,.015); }
table.tbl td .frac { color: var(--accent); }

/* ---------- Calc keys ---------- */
.calc {
  max-width: 340px; margin: 0 auto;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.calc .screen {
  background: #0b0e1a; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; text-align: right; font-family: var(--mono);
  min-height: 86px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
}
.calc .expr { color: var(--text-faint); font-size: .85rem; min-height: 16px; word-break: break-all; }
.calc .out { font-size: 1.9rem; font-weight: 700; word-break: break-all; }
.calc .keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.calc .key {
  padding: 14px 0; font-size: 1.05rem; cursor: pointer;
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; font-family: var(--mono); transition: .12s;
}
.calc .key:hover { filter: brightness(1.2); }
.calc .key:active { transform: scale(.96); }
.calc .key.op { background: #2a3157; color: var(--brand); }
.calc .key.eq { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #0c0f1c; font-weight: 700; }
.calc .key.fn { color: var(--accent); }
.calc .key.span2 { grid-column: span 2; }

/* ---------- Game cards (portal) ---------- */
.gamelist {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  margin-top: 22px;
}
.gamecard {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; transition: .18s;
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
}
.gamecard:hover { transform: translateY(-4px); border-color: var(--brand); box-shadow: var(--shadow); text-decoration: none; }
.gamecard .cover {
  aspect-ratio: 4 / 3; width: 100%; object-fit: cover;
  background: var(--bg-soft); display: block; border-bottom: 1px solid var(--line);
}
.gamecard .meta { padding: 14px 16px; }
.gamecard .meta h3 { margin: 0 0 4px; font-size: 1.02rem; }
.gamecard .meta .tag { font-size: .76rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.gameframe-wrap {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: none;
}
.gameframe-wrap.show { display: block; }
.gameframe-wrap iframe { width: 100%; height: 100%; border: 0; }
.gameframe-close {
  position: fixed; top: 14px; right: 16px; z-index: 101;
  background: rgba(0,0,0,.6); color: #fff; border: 1px solid #fff4;
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.gameframe-close:hover { background: rgba(255,255,255,.15); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 70vh; display: grid; place-items: center; padding: 40px 0; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 34px 30px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; text-align: center; }
.auth-card .hint { text-align: center; color: var(--text-faint); font-size: .85rem; margin-bottom: 24px; }
.auth-err {
  background: rgba(255,107,139,.12); border: 1px solid var(--danger);
  color: var(--danger); padding: 10px 13px; border-radius: var(--radius-sm);
  font-size: .85rem; margin-bottom: 14px; display: none;
}
.auth-err.show { display: block; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line-soft); margin-top: 60px; padding: 26px 0;
  color: var(--text-faint); font-size: .82rem; text-align: center;
}

/* ---------- Utilities ---------- */
.muted { color: var(--text-dim); }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.hide { display: none !important; }
.badge {
  display: inline-block; font-size: .72rem; padding: 3px 9px; border-radius: 20px;
  background: var(--bg-elev); color: var(--text-dim); border: 1px solid var(--line);
}
.kbd {
  font-family: var(--mono); font-size: .82rem; padding: 2px 7px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 6px;
}
.note {
  border-left: 3px solid var(--brand); background: rgba(110,168,254,.07);
  padding: 12px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-dim); font-size: .9rem; margin: 14px 0;
}

@media (max-width: 640px) {
  .nav { display: none; }
  .hero { padding: 36px 0 16px; }
}
