:root {
  --bg: #f3f7f6;
  --bg-deep: #e8f0ee;
  --surface: #ffffff;
  --ink: #10231f;
  --muted: #5b736d;
  --line: #d5e3df;
  --primary: #0d9488;
  --primary-deep: #0f766e;
  --primary-soft: #ccfbf1;
  --accent: #f59e0b;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --shadow: 0 12px 40px rgba(16, 35, 31, 0.08);
  --radius: 20px;
  --font: "Manrope", sans-serif;
  --display: "Unbounded", sans-serif;
  --container: 1120px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 0% -10%, rgba(13, 148, 136, 0.14), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(245, 158, 11, 0.08), transparent 45%),
    linear-gradient(180deg, #f7fbfa 0%, var(--bg) 40%, var(--bg-deep) 100%);
}
a { color: var(--primary-deep); text-decoration: none; }
a:hover { color: var(--primary); }
h1, h2, h3, .brand, .display {
  font-family: var(--display);
  letter-spacing: -0.02em;
  font-weight: 600;
}
img { max-width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(213, 227, 223, 0.9);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); font-size: 1.05rem;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(145deg, #14b8a6, #0f766e);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 9px 8px 8px 9px;
  border: 2px solid #ecfeff; border-radius: 4px 4px 7px 7px;
  border-top: 0;
}
.topbar .site-nav {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
}
.nav-link {
  padding: 8px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 0.92rem;
  min-height: 36px; display: inline-flex; align-items: center;
}
.nav-link:hover, .nav-link.is-active {
  background: var(--primary-soft); color: var(--primary-deep);
}
.user-chip {
  margin-left: 4px; padding: 7px 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; font-weight: 600;
  text-decoration: none; display: inline-flex; align-items: center; min-height: 36px;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}
a.user-chip:hover {
  border-color: #99f6e4; background: var(--primary-soft); color: var(--primary-deep);
}
.container {
  width: min(100% - 32px, var(--container));
  margin: 0 auto;
  padding: 28px 0 72px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-sizing: border-box;
  height: 40px; min-height: 40px; max-height: 40px;
  padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-family: var(--font); font-weight: 700; font-size: 0.92rem; line-height: 1;
  cursor: pointer; text-decoration: none; white-space: nowrap; vertical-align: middle;
  transition: transform .22s cubic-bezier(.22,1,.36,1), box-shadow .22s ease, background .22s ease, border-color .22s ease;
}
a.btn { color: inherit; }
a.btn:hover { color: inherit; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; box-shadow: 0 10px 24px rgba(15, 118, 110, 0.28);
}
.btn.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.soft { background: var(--primary-soft); color: var(--primary-deep); border-color: transparent; }
.btn.sm {
  height: 36px; min-height: 36px; max-height: 36px;
  padding: 0 12px; font-size: 0.86rem; border-radius: 10px;
}
.btn.block {
  width: 100%;
  max-width: 100%;
}
.form-stack {
  display: grid;
  gap: 14px;
  align-content: start;
}
.form-stack h2 { margin: 0; }
.form-stack .field { margin: 0; }
.invite-input {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.invite-input::placeholder {
  text-transform: none;
  letter-spacing: normal;
}
.inline { display: inline-flex; align-items: center; margin: 0; }
.inline > .btn { margin: 0; }
.row-actions {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0;
}

.hero {
  position: relative; overflow: hidden;
  border-radius: 32px; padding: clamp(28px, 5vw, 48px);
  color: #ecfeff;
  background:
    linear-gradient(135deg, rgba(4, 47, 46, 0.92), rgba(15, 118, 110, 0.88)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  box-shadow: var(--shadow);
}
.hero h1 { margin: 8px 0 12px; font-size: clamp(2rem, 5vw, 3.2rem); color: #fff; }
.eyebrow {
  margin: 0; text-transform: uppercase; letter-spacing: 0.12em;
  font-size: 0.75rem; font-weight: 700; color: #99f6e4;
}
.lead { margin: 0; max-width: 34rem; color: #ccfbf1; font-size: 1.05rem; line-height: 1.55; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.hero .btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.45);
  color: #fff;
}
.hero .btn.ghost:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.65);
  color: #fff;
}
.hero .demo { margin-top: 18px; color: #99f6e4; font-size: 0.88rem; }

.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 6px 0 8px; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.page-head .muted, .muted { color: var(--muted); }
.crumb { color: var(--muted); font-weight: 600; font-size: 0.9rem; }

.tabs {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 28px; padding: 6px; width: fit-content; max-width: 100%;
  background: rgba(255,255,255,0.8); border: 1px solid var(--line); border-radius: 16px;
}
.tab {
  padding: 10px 16px; border-radius: 12px; font-weight: 700; color: var(--muted);
}
.tab.is-active {
  background: var(--primary-deep); color: #fff;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.section-block { margin-bottom: 36px; }
.section-block > header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.section-block h2 { margin: 0; font-size: 1.15rem; }
.section-label {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: #fff7ed; color: #b45309; font-size: 0.78rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.catalog-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 168px; padding: 20px;
  border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); color: inherit; box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease;
}
.catalog-card:hover {
  transform: translateY(-3px);
  border-color: #99f6e4;
  color: inherit;
}
.catalog-card .tag {
  align-self: flex-start; padding: 4px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-deep);
  font-size: 0.75rem; font-weight: 800;
}
.catalog-card .icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.4rem;
  background: linear-gradient(145deg, #f0fdfa, #ccfbf1);
}
.catalog-card h3 { margin: 0; font-size: 1.05rem; font-family: var(--display); }
.catalog-card p { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.4; flex: 1; }
.catalog-card .foot {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem; font-weight: 700; color: var(--primary-deep);
}
.progress-mini {
  height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; margin-top: 8px;
}
.progress-mini i { display: block; height: 100%; background: linear-gradient(90deg, #14b8a6, #0f766e); }

.panel, .question-card, .auth-card, .solution-card, .task-row, .stat-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.task-list { display: grid; gap: 12px; }
.task-row {
  display: block; color: inherit; padding: 16px 18px;
  transition: border-color .15s ease, transform .15s ease;
}
.task-row:hover { border-color: #99f6e4; transform: translateY(-1px); color: inherit; }
.task-row.solved { background: var(--ok-bg); border-color: #a7f3d0; }
.task-row .meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.chip {
  border-radius: 999px; padding: 5px 11px; font-size: 0.8rem; font-weight: 800;
  background: var(--primary-soft); color: var(--primary-deep);
}
.chip.ok { background: #d1fae5; color: var(--ok); }

.formula { text-align: center; overflow-x: auto; padding: 10px 0; }
.matrix-box {
  background: linear-gradient(135deg, #0f766e, #0e7490 50%, #134e4a);
  color: #fff; border-radius: 18px; padding: 18px;
}
.banner {
  border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; font-weight: 700;
}
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.hint {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 14px;
  background: #fffbeb; color: #92400e; font-weight: 600;
}

.answer-form { margin-top: 18px; display: grid; gap: 14px; }
.answer-form .label { margin: 0; font-weight: 800; }
.answer-single, input, textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff;
  font: inherit; color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: #5eead4; box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.12);
}
.fraction-input { width: min(200px, 100%); margin: 0 auto; text-align: center; }
.fraction-input hr { border: none; height: 3px; background: var(--primary); margin: 8px 0; border-radius: 2px; }
.roots, .matrix-input { display: grid; gap: 8px; }
.matrix-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.matrix-row input { width: 68px; text-align: center; }

.auth-card { max-width: 440px; margin: 36px auto; display: grid; gap: 14px; }
.auth-card form, .panel form { display: grid; gap: 12px; }
.auth-card label, .panel label, .field { display: grid; gap: 6px; font-weight: 700; font-size: 0.92rem; }
.error { color: var(--bad); font-weight: 700; margin: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.simple-list { padding-left: 18px; }

.groups-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}
.invite-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary-deep);
}
.stats-list { display: grid; gap: 12px; }
.bar { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #14b8a6, #0f766e); }
.kv { display: grid; gap: 10px; margin: 0; }
.kv > div { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: baseline; }
.kv dt { margin: 0; color: var(--muted); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; }
.field select { font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); }

/* Battles / Triviador */
.battle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .battle-layout { grid-template-columns: 1fr; }
}
.battle-map-panel { overflow: hidden; }
.battle-map {
  width: 100%;
  height: auto;
  display: block;
  background: linear-gradient(165deg, #ecfeff 0%, #f0fdfa 40%, #e0f2fe 100%);
  border-radius: 16px;
  border: 1px solid var(--line);
}
.battle-map .terr {
  stroke: #0f766e;
  stroke-width: 2;
  transition: fill .15s ease, filter .15s ease;
}
.battle-map .terr.mine { fill: #5eead4; }
.battle-map .terr.foe { fill: #fda4af; }
.battle-map .terr.target { stroke: #0f172a; stroke-width: 3; filter: brightness(1.05); }
.battle-map .terr.attackable { cursor: pointer; }
.battle-map .terr.attackable:hover { fill: #fb7185; filter: drop-shadow(0 0 4px rgba(15,118,110,.35)); }
.battle-score {
  display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; font-weight: 700;
}
.battle-score .me { color: var(--primary-deep); }
.battle-score .foe { color: #be123c; }
.battle-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 0.9rem; font-weight: 600;
}
.battle-legend .swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 6px;
  vertical-align: -2px; border: 1px solid #0f766e;
}
.battle-legend .swatch.mine { background: #5eead4; }
.battle-legend .swatch.foe { background: #fda4af; }
.map-pick input { margin-right: 8px; width: auto; }
.map-pick small { display: block; color: var(--muted); font-weight: 600; margin-top: 4px; }
.math-block { line-height: 1.5; }

/* Constructor */
.wizard-steps {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 22px;
}
.wizard-step {
  padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); background: #fff;
  color: var(--muted); font-weight: 700;
}
.wizard-step.is-active {
  border-color: #99f6e4; background: var(--primary-soft); color: var(--primary-deep);
}
.wizard-step small { display: block; font-weight: 600; opacity: 0.8; margin-top: 4px; }
.type-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px;
}
.type-card {
  cursor: pointer; border: 1.5px solid var(--line); border-radius: 18px; padding: 16px;
  background: #fff; text-align: left; font: inherit; color: inherit;
  transition: border-color .15s ease, transform .15s ease;
}
.type-card:hover { transform: translateY(-2px); border-color: #99f6e4; }
.type-card.is-selected {
  border-color: var(--primary); background: var(--primary-soft);
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.12);
}
.type-card strong { display: block; font-family: var(--display); margin-bottom: 6px; }
.type-card span { color: var(--muted); font-size: 0.88rem; line-height: 1.35; }
.constructor-layout {
  display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 18px; align-items: start;
}
@media (max-width: 900px) {
  .constructor-layout { grid-template-columns: 1fr; }
  .wizard-steps { grid-template-columns: 1fr; }
}
.preview-card {
  position: sticky; top: 88px;
  background: #042f2e; color: #ecfeff; border-radius: 22px; padding: 20px;
  min-height: 220px;
}
.preview-card h3 { margin: 0 0 12px; color: #fff; }
.preview-card .muted { color: #99f6e4; }
.matrix-builder {
  display: grid; gap: 12px; padding: 14px; border-radius: 16px; background: #f8fafc; border: 1px dashed var(--line);
}
.matrix-builder .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.matrix-builder input.cell { width: 56px; text-align: center; }
.hidden { display: none !important; }
.home-features {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 18px;
}
.home-features article {
  background: rgba(255,255,255,0.88); border: 1px solid var(--line); border-radius: 20px;
  padding: 18px; box-shadow: var(--shadow);
}
.home-features h3 { margin: 0 0 8px; font-size: 1rem; }
.home-features p { margin: 0; color: var(--muted); line-height: 1.45; }
.site-footer {
  width: min(100% - 32px, var(--container));
  margin: 0 auto 28px;
  padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.88rem;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.nav-toggle {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  min-height: 44px;
  min-width: 44px;
  font-size: 1.2rem;
  cursor: pointer;
}
.table-wrap, .panel { overflow-x: auto; }
.panel .table { min-width: 480px; }

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
  }
  .topbar .site-nav {
    display: none;
    width: 100%;
    max-height: min(70vh, 420px);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 10px 0 4px;
    border-top: 1px solid var(--line);
  }
  .topbar .site-nav.is-open {
    display: flex;
  }
  .site-nav .nav-link,
  .site-nav .btn,
  .site-nav .user-chip,
  .site-nav .nav-bell {
    width: 100%;
    box-sizing: border-box;
    justify-content: flex-start;
    border-radius: 12px;
  }
  .site-nav .user-chip {
    white-space: normal;
    line-height: 1.35;
    min-height: auto;
    padding: 10px 12px;
  }
  .site-nav .inline,
  .site-nav .inline .btn {
    width: 100%;
  }
}

/* Smooth page enter */
.page-enter {
  animation: pageIn .45s cubic-bezier(.22,1,.36,1) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.nav-link, .tab, .catalog-card, .terr {
  transition: background .22s ease, color .22s ease, border-color .22s ease, transform .22s cubic-bezier(.22,1,.36,1), fill .25s ease, filter .25s ease;
}

.nav-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--muted);
}
.nav-bell:hover, .nav-bell.is-active {
  background: var(--primary-soft);
  color: var(--primary-deep);
}
.nav-bell-icon {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  position: relative;
}
.nav-bell-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 8px;
  height: 3px;
  margin-left: -4px;
  border-radius: 0 0 4px 4px;
  background: currentColor;
}
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #b91c1c;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.notif-badge[hidden],
.notif-badge.is-empty {
  display: none !important;
}

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #042f2e;
  color: #ecfeff;
  box-shadow: 0 16px 40px rgba(4, 47, 46, 0.28);
  text-decoration: none;
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  transition: transform .35s cubic-bezier(.22,1,.36,1), opacity .3s ease;
}
.toast.is-in { transform: none; opacity: 1; }
.toast.is-out { transform: translateY(8px); opacity: 0; }
.toast strong { color: #fff; font-size: 0.95rem; }
.toast span { color: #99f6e4; font-size: 0.88rem; line-height: 1.35; }

.notif-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.notif-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  animation: pageIn .4s cubic-bezier(.22,1,.36,1) both;
}
.notif-item.is-unread {
  border-color: #99f6e4;
  background: linear-gradient(180deg, #f0fdfa, #fff);
}
.notif-item a {
  display: grid;
  gap: 4px;
  color: inherit;
  flex: 1;
  min-width: 0;
}
.notif-item strong { font-size: 0.98rem; }
.notif-item span { color: var(--muted); font-size: 0.9rem; }

.banner {
  animation: pageIn .35s ease both;
}
.panel {
  transition: box-shadow .25s ease, transform .25s ease;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .page-enter, .notif-item, .banner, .toast {
    animation: none !important;
    transition: none !important;
  }
  .btn:hover, .catalog-card:hover, .type-card:hover { transform: none; }
}
